Skip to content

API 요청/응답 로깅 개선#245

Open
ckdals4600 wants to merge 3 commits into
mainfrom
feature/edit-RequestLoggingFilter
Open

API 요청/응답 로깅 개선#245
ckdals4600 wants to merge 3 commits into
mainfrom
feature/edit-RequestLoggingFilter

Conversation

@ckdals4600

@ckdals4600 ckdals4600 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

PR 설명

배경

  • 기존 RequestLoggingFilter가 모든 요청의 헤더·바디를 INFO 로 통째 로깅하여
    authorization/cookie의 JWT 토큰, 로그인 요청의 비밀번호가 평문으로 남고 있었음.
  • 헬스체크·정적리소스·스캐너 탐색 요청까지 매번 기록되어 운영 로그가 노이즈로 가득 찼음.

변경 사항

민감 정보 로깅 제거

  • INFO 로그에서 헤더/바디 전체 덤프 제거 → method / uri / status / 소요시간 / ip / user-agent만 한 줄로 기록
  • 요청 헤더는 DEBUG 에서만 출력하며 민감 헤더(Authorization, Cookie, Set-Cookie 등)는 값 전체 마스킹
  • 응답 헤더(Set-Cookie)는 로깅하지 않아 토큰이 헤더로 새지 않음

요청/응답 본문 로깅 (마스킹 적용)

  • 응답 본문: INFO 기록, 민감 필드(email 등)·JWT 패턴 마스킹 + 2000자 상한
  • 요청 본문: DEBUG 기록(클라이언트 통제 불가 입력이라 보수적), 동일 마스킹 적용
  • email/password/토큰류 필드 값 마스킹, 필드명과 무관하게 eyJ... JWT 패턴은 통째로 마스킹
  • ContentCachingResponseWrapper 사용 시 copyBodyToResponse() 호출로 빈 응답 방지
  • 파일 업로드(multipart)·바이너리는 메모리 버퍼링 방지를 위해 래핑·로깅에서 제외

로그 노이즈 제거

  • RequestLoggingFilter에서 노이즈 경로(/actuator, /favicon.ico, /swagger, /v3/api-docs) 요청 로깅 제외
  • GlobalExceptionHandler에서 NoResourceFoundException(스캐너 404) ERROR → DEBUG 강등
  • JwtTokenProvider에서 익명 요청에 대한 Token not found 로그 삭제

@ckdals4600 ckdals4600 requested review from Goder-0 and minibr June 18, 2026 13:11
@ckdals4600 ckdals4600 self-assigned this Jun 18, 2026
@ckdals4600 ckdals4600 changed the title Feature/edit request logging filter API 요청/응답 로깅 개선 (민감정보 마스킹 · 노이즈 제거) Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

📊 코드 커버리지 리포트

Overall Project 93.29% -1.69% 🍏
Files changed 80.67% 🍏

File Coverage
JwtTokenProvider.java 92.22% 🍏
RequestLoggingFilter.java 81.8% -18.2% 🍏
GlobalExceptionHandler.java 36.36% -5.68%

@ckdals4600 ckdals4600 changed the title API 요청/응답 로깅 개선 (민감정보 마스킹 · 노이즈 제거) API 요청/응답 로깅 개선 Jun 18, 2026
Comment on lines +92 to +93
log.info("[API RESPONSE] {} {} -> {} body={}", request.getMethod(), uri, response.getStatus(),
responseBody(response));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

INFO 로 항상 남기면 토큰/이메일만 가려도 사용자 데이터가 그대로 운영 로그에 쌓입니다. 이 서비스 응답에는 채팅 본문, AI 답변, 링크 메모, 요약 내용 같은 사용자 콘텐츠가 포함되는데, 현재 마스킹은 email/password/token 계열만 처리해서 본문 유출 문제가 그대로 남습니다. 이번 PR의 목적이 “민감정보 제거 + 운영 로그 노이즈 축소”라면 응답 본문은 DEBUG 로 내리거나, 정말 필요한 일부 endpoint만 allowlist 로 남기는 쪽이 좋을 것 같습니다.

@ckdals4600 ckdals4600 Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

응답 본문을 DEBUG로 내리려던 것을 실수로 요청 본문에 적용했었네요.
짚어주신 덕분에 응답 본문 로그 레벨을 DEBUG로 수정 반영했습니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

응답 본문을 DEBUG로 내린 건 확인했는데, 요청 본문이 아직 INFO로 남아 있어서 원래 코멘트가 완전히 해소되진 않았습니다. 현재도 채팅 질문, 링크 메모, 요약 요청 payload 같은 사용자 콘텐츠가 운영 로그에 적재될 수 있어보입니다.

@ckdals4600 ckdals4600 Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

요청 본문 로그를 응답 본문과 동일하게 DEBUG로 내렸습니다. 이제 헤더·요청/응답 본문이 모두 DEBUG에서만 남고, INFO에는 메타 정보(메서드·경로·상태·응답시간·IP)만 남깁니다. 사용자 입력 콘텐츠가 운영 기본 로그에 적재되지 않습니다. 짚어주셔서 감사합니다.

@ckdals4600 ckdals4600 force-pushed the feature/edit-RequestLoggingFilter branch 2 times, most recently from 4c061c2 to fc597ae Compare June 21, 2026 07:47
@ckdals4600

Copy link
Copy Markdown
Contributor Author

@Goder-0
JwtTokenProvider 수정 사항 추가 됐습니다. 확인 부탁드립니다.

}

long tookMs = (System.nanoTime() - startNs) / 1_000_000;
String query = request.getQueryString() != null ? "?" + request.getQueryString() : "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

query string 도 그대로 로그에 남기면 민감값 유출 경로가 하나 더 생깁니다. header/body 마스킹과 별개로 \?token=, ?code= 같은 값이 적재될 수 있으니, access log 에서는 query string 을 제거하거나 민감 키 마스킹이 필요해 보입니다. 제가 생각하기엔 token, code 등만 제외하면 될 것 같긴합니다.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

query string도 maskQueryString()으로 마스킹 처리했습니다. 확인해보니 민감 값이 query로 오는 경로는 OAuth 콜백의 code/state뿐이라(나머지는 헤더/쿠키 처리) 그 둘을 마스킹 대상으로 두었습니다.

@ckdals4600 ckdals4600 force-pushed the feature/edit-RequestLoggingFilter branch from fc597ae to 7b7fb0d Compare June 24, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

응답 본문 로깅 추가 (DEBUG 레벨) 운영 로그에서 스캐너·정적리소스 요청 제외 요청 로깅 방식 수정

2 participants