Skip to content

Commit

Permalink
Patch log4j JAR to remove JndiLookup class (#81631)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Dec 10, 2021
1 parent cdc5ae4 commit 5b38441
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
}
}
all {
resolutionStrategy.dependencySubstitution {
substitute module("org.apache.logging.log4j:log4j-core") using project(":libs:elasticsearch-log4j") because "patched to remove JndiLookup clas"}
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion libs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

subprojects {
configure(subprojects - project('elasticsearch-log4j')) {
/*
* All subprojects are java projects using Elasticsearch's standard build
* tools.
Expand Down
28 changes: 28 additions & 0 deletions libs/log4j/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id 'base'
id 'elasticsearch.repositories'
}

configurations {
log4j {
transitive = false
}
}

dependencies {
log4j "org.apache.logging.log4j:log4j-core:${versions.log4j}"
}

// Strip out JndiLookup class to avoid any possibility of exploitation of CVE-2021-44228
// See: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44228
// See: https://issues.apache.org/jira/browse/LOG4J2-3201
def patchLog4j = tasks.register('patchLog4j', Zip) {
archiveExtension = 'jar'
from({ zipTree(configurations.log4j.singleFile) }) {
exclude '**/JndiLookup.class'
}
}

artifacts {
'default'(patchLog4j)
}

1 comment on commit 5b38441

@davydotcom
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm, why didnt you just bump to the latest Log4j version , it works fine and prevents this from showing up on a security scan

Please sign in to comment.