Gradle/Java: 如何安全升级log4j?
Gradle/Java: How to upgrade log4j safely?
鉴于最近的Log4J vulnerability
在 gradle 项目中升级传递依赖项的最安全方法是什么?我的项目没有明确使用 log4j(它使用 logback),但它有许多依赖项会带来易受攻击的版本(< 2.15.0)。首先,如果我的 SLF4J 使用 logback,是否有必要升级任何东西?如果我要升级,我如何强制 2.15 出现在类路径中而不是旧版本?
将以下内容添加到您的 gradle.build
文件中:
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'org.apache.logging.log4j') {
details.useVersion '2.17.1'
details.because 'zero-day exploits suck'
}
}
}
dependencies {
…
}
请注意,正如 documentation 指出的那样:
the following mechanisms allow you to write rules which are directly
injected into the resolution engine. Because of this, they can be seen
as brute force solutions, that may hide future problems (e.g. if new
dependencies are added). Therefore, the general advice is to only use
the following mechanisms if other means are not sufficient.
我意识到 OP 要求以“最安全”的方式升级依赖项——我选择将其解释为最有可能消除零日攻击。尽管如此,我确实认识到这种蛮力方法并不能保证库之间的兼容性,但这应该确保没有易受攻击的 log4j 版本最终出现在您的依赖树/构建中。
您当然应该 运行 gradle dependencies
在您进行更改后确保更改已生效并且您没有任何有问题的挥之不去的版本。
更新:删除了版本比较,推荐here。
更新:增加版本到2.17.1
您可以将依赖管理插件添加到您的 gradle.build:
plugins {
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
dependencyManagement {
imports {
mavenBom 'org.apache.logging.log4j:log4j-bom:2.17.0'
}
}
要确认更改,运行
./gradlew dependencies
你应该会看到类似
的内容
+--- org.apache.logging.log4j:log4j-to-slf4j:2.14.1 -> 2.17.0
| | | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.32
| | | | \--- org.apache.logging.log4j:log4j-api:2.17.0
鉴于最近的Log4J vulnerability 在 gradle 项目中升级传递依赖项的最安全方法是什么?我的项目没有明确使用 log4j(它使用 logback),但它有许多依赖项会带来易受攻击的版本(< 2.15.0)。首先,如果我的 SLF4J 使用 logback,是否有必要升级任何东西?如果我要升级,我如何强制 2.15 出现在类路径中而不是旧版本?
将以下内容添加到您的 gradle.build
文件中:
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'org.apache.logging.log4j') {
details.useVersion '2.17.1'
details.because 'zero-day exploits suck'
}
}
}
dependencies {
…
}
请注意,正如 documentation 指出的那样:
the following mechanisms allow you to write rules which are directly injected into the resolution engine. Because of this, they can be seen as brute force solutions, that may hide future problems (e.g. if new dependencies are added). Therefore, the general advice is to only use the following mechanisms if other means are not sufficient.
我意识到 OP 要求以“最安全”的方式升级依赖项——我选择将其解释为最有可能消除零日攻击。尽管如此,我确实认识到这种蛮力方法并不能保证库之间的兼容性,但这应该确保没有易受攻击的 log4j 版本最终出现在您的依赖树/构建中。
您当然应该 运行 gradle dependencies
在您进行更改后确保更改已生效并且您没有任何有问题的挥之不去的版本。
更新:删除了版本比较,推荐here。
更新:增加版本到2.17.1
您可以将依赖管理插件添加到您的 gradle.build:
plugins {
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
dependencyManagement {
imports {
mavenBom 'org.apache.logging.log4j:log4j-bom:2.17.0'
}
}
要确认更改,运行
./gradlew dependencies
你应该会看到类似
+--- org.apache.logging.log4j:log4j-to-slf4j:2.14.1 -> 2.17.0
| | | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.32
| | | | \--- org.apache.logging.log4j:log4j-api:2.17.0