본문 바로가기
Web Development/Spring Boot

[Spring Boot / Gradle] Log4J 2 이슈에 따른 2.17.1 업데이트 대응 및 spring-boot-starter-logging 제거 (IntelliJ)

by 감자맹고우 2021. 12. 15.
728x90
반응형
최근 Apache Log4j 2 취약점이 발견되어 이슈가 되고 있습니다.

며칠 전만 해도 2.15.0버전으로 업데이트를 해야한다고 했는데, 
2.15.0도 해당 취약점에 대해 특정 구성에서 불완전한 것으로 나타났다고 합니다.

<!--
그래서 2.16.0 버전으로 업데이트하면 가장 간단하게 해결이 된다고 하며, 
검색해보면 Java 8의 경우 업데이트 외에도 다른 방법이 제공이 되고 있습니다.
-->

<!--
2.16.0 버전에서 JNDI Lookup pattern 문제가 발생하였습니다.
그렇습니다. 우리는 이제 2.17.0 버전으로 업그레이드 해야 합니다.
-->

2.17.0 버전에서 신규 취약점 CVE-2021-44832이 발견되었습니다.
다시 2.17.1 버전으로 업그레이드 해야 하며, 한동안 취약점은 계속 발생할 수 있어 지속적으로 관심을 가져야 할 것 같습니다.

[ 참고 ] Log4J2 신규 취약점 관련 링크 https://logging.apache.org/log4j/2.x/security.html

 

 

Spring Boot로 실습 프로젝트를 생성하는 도중

spring-boot-starter에 'logging > log4j:log4j-to-slf 4j:2.13.2' 가 생성되는 것을 보았고, 이 파일도 해당되는지는 모르겠지만, 찝찝하니 이 참에 버전 업을 해보기로 하였습니다.

 

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' exclude module: 'spring-boot-starter-logging'
	implementation 'org.springframework.boot:spring-boot-starter-validation' exclude module: 'spring-boot-starter-logging'
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa' exclude module: 'spring-boot-starter-logging'
	implementation 'org.springframework.boot:spring-boot-starter-web' exclude module: 'spring-boot-starter-logging'
	implementation 'org.springframework.boot:spring-boot-devtools'
	implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.6'
	compileOnly 'org.projectlombok:lombok'
	runtimeOnly 'com.h2database:h2:1.3.175'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test' exclude module: 'spring-boot-starter-logging'
	testImplementation "org.junit.vintage:junit-vintage-engine" exclude group: "org.hamcrest", module: "hamcrest-core"
	implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
	implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
	implementation group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.17.1'
	implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.17.1'
	implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32'
	implementation group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.32'
}

 

반응형

 

1. build.gradle 파일의 dependencies에 2.17.1(2.16.0, 2.17.0)버전의 log4j를 추가하였습니다.

 

implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.17.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.17.1'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32'
implementation group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.32'

 

그러나, 추가를 해서는 기존 버전의 log4j가 제거되지 않았습니다.

 

그렇기 때문에, 추가적으로 기존 버전을 제거해주어야 했습니다.

 

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' exclude module: 'spring-boot-starter-logging'
implementation 'org.springframework.boot:spring-boot-starter-validation' exclude module: 'spring-boot-starter-logging'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' exclude module: 'spring-boot-starter-logging'
implementation 'org.springframework.boot:spring-boot-starter-web' exclude module: 'spring-boot-starter-logging'

 

 

2. 이와 같이 exclude module을 통해서 logging 모듈을 제외하도록 설정하였는데, 처음에는 web에만 적용했다가 thymeleaf에도 logging이 있는 것을 확인하여, 전체에 동일한 설정을 추가하였습니다.

 

gradle 탭

 

이를 통해서 기존 log4j 버전은 사라지고, 2.17.1(2.16.0, 2.17.0)버전의 log4j만 남는 것을 확인할 수 있었습니다.

 

반응형

 

---------------------------------------- 2021.12.20 추가 ------------------------------------------

 

 

JUnit 테스트 중, ' log4j-slf4j-impl cannot be present with log4j-to-slf4j ' 오류가 발생하였습니다.

 

정상 동작하지 않는 것을 보고 확인해 본 결과 dependencies의 spring-boot-starter-test에서 기존 logging을 제거해주지 않은 것을 발견하였습니다.

 

testImplementation 'org.springframework.boot:spring-boot-starter-test' exclude module: 'spring-boot-starter-logging'

 

다음과 같이 수정해주었고, log4j 기능이 동작하는 것을 확인하였습니다.

 

 

---------------------------------------- 2021.12.23 변경 ------------------------------------------

 

Log4j 2.16.0 버전 신규 취약점 발견으로 인한 2.17.0 버전으로 내용 수정

 

---------------------------------------- 2022.1.4 변경 ------------------------------------------

 

Log4J 2.17.0 버전 신규 취약점 발견으로 인한 2.17.1 버전으로 내용 수정

 

 

 

- 버전 정보 -

IntelliJ IDEA 2021.3

Spring Boot 2.4.1

 

🤞 도움이 되셨기를 바랍니다. 한 번의 클릭과 댓글은 어딘가의 누군가에게 진실로 큰 힘이 됩니다. 🐱‍🏍

 

728x90
반응형

댓글