如何修复 Gradle 项目中的 Log4J 漏洞

     2023-02-27     44

关键词:

【中文标题】如何修复 Gradle 项目中的 Log4J 漏洞【英文标题】:How to fix Log4J Vulnerability in Gradle Project 【发布时间】:2022-01-18 16:47:50 【问题描述】:

我可以在我的项目的 Gradle 依赖树中看到 org.apache.logging.log4j:log4j-core:2.14.0 库。

我们还没有从外部添加 log4j 版本。这个版本是来自其他 jars 或 spring-boot-starter 的传递依赖的一部分。

如何在 Gradle 中覆盖 log4j 版本?

【问题讨论】:

如果你没有,你就不会受到攻击。见spring.io/blog/2021/12/10/log4j2-vulnerability-and-spring-boot 【参考方案1】: 首选https://docs.gradle.org/current/userguide/resolution_rules.html 约束。 https://docs.gradle.org/current/userguide/rich_versions.html#rich-version-constraints https://blog.gradle.org/log4j-vulnerability
dependencies 
    constraints 
        implementation('org.apache.logging.log4j:log4j-api') 
            version 
                strictly('[2.17, 3[')
                prefer('2.17.0')
            
            because('CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities')
        

        implementation('org.apache.logging.log4j:log4j-core') 
            version 
                strictly('[2.17, 3[')
                prefer('2.17.0')
            
            because('CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities')
        

        implementation('org.apache.logging.log4j:log4j-slf4j-impl') 
            version 
                strictly('[2.17, 3[')
                prefer('2.17.0')
            
            because('CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities')
        

        implementation('org.apache.logging.log4j:log4j-web') 
            version 
                strictly('[2.17, 3[')
                prefer('2.17.0')
            
            because('CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities')
        
    

【讨论】:

【参考方案2】:

首先,找出您真正使用的 log4j 相关库,例如由

 .\gradlew dependencies --configuration=testRuntimeClasspath | find "log4j"

然后用当前版本(docs)覆盖它们,放在dependencies 块之后:

configurations.all 
    resolutionStrategy 
        force 'org.apache.logging.log4j:log4j-api:2.17.0'
        force 'org.apache.logging.log4j:log4j-core:2.17.0'
        force 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.0'
        force 'org.apache.logging.log4j:log4j-jul:2.17.0'
    

您可能需要向该块添加更多/更少的库,具体取决于开始时的检查结果。

由于你使用的是Spring Boot,你也可以使用Spring-Boot-specific feature来设置Log4J版本:

ext['log4j2.version'] = '2.17.0'

【讨论】:

不幸的是,这并没有强制在依赖项内部进行升级。我仍然可以通过gradlew dependencies 看到有旧版本 这个方法也特别适用于传递依赖。 对于 build.gradle.kts / KotlinDSL 应该如何看待?至少对我来说不是:-( 我以不同的方式修复了它,它现在可以在我自己的答案中使用 ***.com/a/70367520/863403【参考方案3】:

我在 MacOS 上并使用子项目:

首先我运行:./gradlew projects,它将列出我的子项目:

输出:

:projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'test-backend'
+--- Project ':test-suite'
+--- Project ':test-suite-services'
\--- Project ':test-utils'

使用输出我们可以一一检查依赖关系:

./gradlew test-suite:dependencies | grep "log4j"
./gradlew test-suite-services:dependencies | grep "log4j"
./gradlew test-utils:dependencies | grep "log4j"

【讨论】:

如何修复 Buildship 中的“缺少 Gradle 项目配置文件”问题?

】如何修复Buildship中的“缺少Gradle项目配置文件”问题?【英文标题】:Howtofix"MissingGradleprojectconfigurationfile"issueinBuildship?【发布时间】:2017-07-1214:58:07【问题描述】:作为Eclipse用户,我一直很喜欢GradleIDE。但是,此插件... 查看详情

如何修复项目“MyApp”不是基于 gradle 的项目

】如何修复项目“MyApp”不是基于gradle的项目【英文标题】:HowcanIfixProject“MyApp”Isnotagradlebasedproject【发布时间】:2022-01-2114:20:49【问题描述】:我正在对已导入AndroidStudio的现有Flutter项目做一些工作。在将项目连接到Firebase时... 查看详情

Gradle/Java:如何安全升级 log4j?

】Gradle/Java:如何安全升级log4j?【英文标题】:Gradle/Java:Howtoupgradelog4jsafely?【发布时间】:2022-01-1521:44:31【问题描述】:鉴于最近的Log4Jvulnerability在gradle项目中升级传递依赖项的最安全方法是什么?我的项目没有明确使用log4j(... 查看详情

在 gradle 传递依赖项中检测 Apache Log4j 漏洞的存在

...v/vuln/detail/CVE-2021-44228中存在一个漏洞,其重要性得分为10如何检查gr 查看详情

Log4j 1:如何在不将版本更新到 2.15.0 的情况下缓解 log4j 中的漏洞

】Log4j1:如何在不将版本更新到2.15.0的情况下缓解log4j中的漏洞【英文标题】:Log4j1:HowtomitigatethevulnerabilityinLog4jwithoutupdatingversionto2.15.0【发布时间】:2022-01-1618:31:23【问题描述】:我正在使用log4j1.2.16。我将它与mavenseleniumtestngjav... 查看详情

如何修复停止工作的gradle - 同步时出错?

】如何修复停止工作的gradle-同步时出错?【英文标题】:Howtofixgradlewhichstoppedworking-errorwhilesyncing?【发布时间】:2021-12-2502:58:20【问题描述】:我在我的Android项目中遇到了gradle问题。我觉得我自己无法解决这个问题很愚蠢。我昨... 查看详情

Gradle 依赖(org.apache.commons)是不是也受到当前 log4j 漏洞的影响?

】Gradle依赖(org.apache.commons)是不是也受到当前log4j漏洞的影响?【英文标题】:Gradledependency(org.apache.commons)isalsoeffectedbycurrentlog4jvulnerabilityornot?Gradle依赖(org.apache.commons)是否也受到当前log4j漏洞的影响?【发布时间】:2022-01-1... 查看详情

如何在我运行颤振项目时修复“错误完成:Gradle 任务 assembleDebug 失败,退出代码 -1”错误

】如何在我运行颤振项目时修复“错误完成:Gradle任务assembleDebug失败,退出代码-1”错误【英文标题】:Howtofix"Finishedwitherror:GradletaskassembleDebugfailedwithexitcode-1"errorwhenirunflutterproject【发布时间】:2020-07-2906:22:39【问题描述... 查看详情

空手道框架的 log4j 漏洞是不是有任何修复/更新?

】空手道框架的log4j漏洞是不是有任何修复/更新?【英文标题】:Isthereanyfix/updateforlog4jvulnerabilityforKarateframework?空手道框架的log4j漏洞是否有任何修复/更新?【发布时间】:2022-01-2221:43:19【问题描述】:在空手道最新版本1.1.0中... 查看详情

出现此错误时如何修复gradle?

】出现此错误时如何修复gradle?【英文标题】:Howtofixgradlewhenthiserrorappear?【发布时间】:2019-07-1114:43:47【问题描述】:我开始了一个新项目并放了火基云:applyplugin:\'com.android.application\'applyplugin:\'android-apt\'androidcompileSdkVersion28bui... 查看详情

openeuler欧拉开源社区log4j高危安全漏洞修复完成

导读欧拉开源社区已经修复Log4j高危安全漏洞(CVE-2021-44228)并发布安全公告。你可以通过更新openEuler20.03LTSSP1/SP2Log4j的安全补丁修复该漏洞。近日消息,据openEuler发布,目前,欧拉开源社区已经修复Log4j高危安全漏洞(CVE-... 查看详情

如何修复无法在 Android Studio 中加载 gradle 属性

】如何修复无法在AndroidStudio中加载gradle属性【英文标题】:HowtofixcouldnotloadgradlepropertiesinAndroidStudio【发布时间】:2022-01-1013:59:13【问题描述】:当我在androidstudio中创建一个新项目时,我收到Gradle错误:Couldnotloadwrapperpropertiesfrom\... 查看详情

python漏洞被曝可能殃及35万个开源项目,又一“log4j风暴”来了?

...问题。粗略估计,这个15年前就已经被发现但并未被修复的漏洞,将会让35万个开源项目和使用它们的应用程 查看详情

springboot项目的log4j漏洞解决—jeecgboot(代码片段)

...回复:jeecgboot采用的是logback实现,按道理不影响如何担心也可以升级下版本号,步骤如下最简修复方式改起来非常简单,不用惊讶,只需要加个下面的配置就可以了一、修改文件jeecg-boot\\pom.xml<properties><... 查看详情

如何读取属性文件并使用项目 Gradle 脚本中的值?

】如何读取属性文件并使用项目Gradle脚本中的值?【英文标题】:HowtoreadapropertiesfilesandusethevaluesinprojectGradlescript?【发布时间】:2016-09-0306:01:52【问题描述】:我正在编写一个Gradle脚本,我需要在其中读取local.properties文件并使用... 查看详情

如何修复这些漏洞? (npm audit fix 无法修复这些漏洞)

】如何修复这些漏洞?(npmauditfix无法修复这些漏洞)【英文标题】:Howtofixthesevulnerabilities?(npmauditfixfailstofixthesevulnerabilities)【发布时间】:2020-02-1520:35:23【问题描述】:我的项目有6个高度严重的漏洞,我不知道如何修复它们。... 查看详情

修不完的bug:log4j第三次发布漏洞补丁,开源社区已修复1/7受影响java包

...xff08;最高10分,分数越高漏洞越严重)。2.16.0曾经修复了2.15.0中存在的两个漏洞,Log4j在Lookup评估中不能完全防止无限递归。也就是说,2.16.0版本的Log4j可能会受到DoS(拒绝服务)攻击。网友表示:这难... 查看详情

如何使用 Gradle 访问 Java 项目中的资源?

】如何使用Gradle访问Java项目中的资源?【英文标题】:HowtoaccessaresourceinJavaprojectusingGradle?【发布时间】:2016-01-2312:16:05【问题描述】:我有一个使用Gradle文件构建的javafx项目,我在Intellij中编写所有内容。在其中,我使用javafx.sc... 查看详情