Skip to Content
Suffering builds character
아카이브18.spring Security스프링 시큐리티5.부록필터9.Logging

9.Logging

스프링 시큐리티에서는 개발 시 디버깅에 용이하도록 Security와 관련된 모든 이벤트들을 DEBUGTRACE 레벨의 로그들을 제공하고 있음

application.properties
logging.level.org.springframework.security=TRACE
logback.xml
<configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <!-- ... --> </appender> <!-- ... --> <logger name="org.springframework.security" level="trace" additivity="false"> <appender-ref ref="Console" /> </logger> </configuration>

개발 시 보안 처리와 관련된 정보들은 보통 HTTP 요청, 응답 객체에 포함되지 않고, 단순하게 400, 401, 403 등과 같은 HTTP 응답 상태 코드만으로 응답하기 때문에 디버깅이 어려울 수 있음

POST 요청으로 CSRF 방지 처리를 위한 코드 개발 과정에 발생한 로그 기록 예시

terminal
DEBUG 76975 --- o.s.security.web.FilterChainProxy : Securing POST /hello TRACE 76975 --- o.s.security.web.FilterChainProxy : Invoking DisableEncodeUrlFilter (1/15) TRACE 76975 --- o.s.security.web.FilterChainProxy : Invoking WebAsyncManagerIntegrationFilter (2/15) TRACE 76975 --- o.s.security.web.FilterChainProxy : Invoking SecurityContextHolderFilter (3/15) TRACE 76975 --- o.s.security.web.FilterChainProxy : Invoking HeaderWriterFilter (4/15) TRACE 76975 --- o.s.security.web.FilterChainProxy : Invoking CsrfFilter (5/15) DEBUG 76975 --- o.s.security.web.csrf.CsrfFilter : Invalid CSRF token found for http://localhost:8080/hello DEBUG 76975 --- o.s.s.w.access.AccessDeniedHandlerImpl : Responding with 403 status code TRACE 76975 --- o.s.s.w.header.writers.HstsHeaderWriter : Not injecting HSTS header since it did not match request to [Is Secure]

→ 로깅을 통해 유효하지 않은 CSRF token 누락되었다는 내역을 확인할 수 있음

Last updated on