feat(security): P1 보안 강화 — WebSocket CORS, 파일 업로드 검증, Rate Limiting - #333
Draft
alpin87 wants to merge 4 commits into
Draft
feat(security): P1 보안 강화 — WebSocket CORS, 파일 업로드 검증, Rate Limiting#333alpin87 wants to merge 4 commits into
alpin87 wants to merge 4 commits into
Conversation
STOMP 엔드포인트(/ws/chat, /ws/blinddate)의 setAllowedOriginPatterns("*")를 SecurityConfig가 사용하는 authentication.origins 화이트리스트로 교체하여 CSWSH(교차 출처 WebSocket 하이재킹)를 방지하고 REST/WebSocket CORS 정책을 일원화한다.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ts (P1-1) - 매직바이트(파일 시그니처)로 실제 이미지 타입(JPEG/PNG/GIF/WEBP)을 판별하는 FileValidator/ImageSignatureDetector 추가. 클라이언트 확장자/Content-Type을 신뢰하지 않는다. - 저장 파일명과 Content-Type을 판별 결과로 결정하여 확장자 위장(.png로 위장한 HTML/SVG) 및 stored XSS 차단. - 빈 파일/크기 상한(10MB) 검증, getOriginalFilename() NPE 및 dead code 제거. - multipart 한도를 max-file-size 10MB / max-request-size 35MB로 설정(기본 1MB가 검증을 무력화하던 문제 해결). - MaxUploadSizeExceededException을 413으로 매핑하는 핸들러 추가. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…(P1-3) - 남용 위험이 높은 엔드포인트(로그인/소셜 5회·분, 이메일 발송 5회·분, 검색 30회·분)에 IP 기준 Rate Limiting 적용. - Redis Lua 스크립트로 INCR+PEXPIRE를 원자적으로 처리(고정 시간창). TTL 유실로 인한 영구 키 문제 방지. - RateLimitFilter를 JwtFilter 앞에 등록하고, FilterRegistrationBean.setEnabled(false)로 서블릿 컨테이너 자동 등록을 막아 이중 카운트 방지. - List<RateLimitRule> 주입 함정을 RateLimitRules 홀더로 회피. - raw X-Forwarded-For 파싱 대신 server.forward-headers-strategy=framework로 위임하여 IP 스푸핑 방지(prod). Redis 장애 시 가용성 우선 fail-open. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
SecurityConfig가 RateLimitFilter를 의존하게 되면서, Filter 타입 빈을 자동 포함하는 @WebMvcTest 슬라이스가 RateLimitFilter의 StringRedisTemplate 의존성을 해소하지 못해 컨텍스트 로딩에 실패했다. 기존 JwtFilter 목 처리와 동일하게 15개 슬라이스 테스트에 RateLimitFilter @MockitoBean을 추가한다. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
KISA AI 보안 가이드라인 / OWASP Top 10 기준 Priority 1 보안 취약점 중 3건을 조치합니다. (AI 텍스트 필터링 P1-2/P1-5는 별도 AI 서비스 영역이라 제외)
변경 내용
🔒 P1-4 — WebSocket CORS (
fix(security))/ws/chat,/ws/blinddate)의setAllowedOriginPatterns("*")→authentication.origins화이트리스트 재사용🔥 P1-1 — 파일 업로드 보안 (
feat(security))FileValidator,ImageSignatureDetector,ImageContentTypegetOriginalFilename()NPE 및 dead code 제거max-file-size: 10MB/max-request-size: 35MB(기본 1MB가 검증을 무력화하던 문제 해결)MaxUploadSizeExceededException→ 413 매핑🚦 P1-3 — Rate Limiting (
feat(security))5회/분, 이메일 발송5회/분, 검색30회/분RateLimitFilter를JwtFilter앞에 등록 +FilterRegistrationBean.setEnabled(false)로 서블릿 자동 등록 차단(이중 카운트 방지)List<RateLimitRule>주입 함정을RateLimitRules홀더로 회피forward-headers-strategy: framework위임(IP 스푸핑 방지), Redis 장애 시 fail-open검증
./gradlew compileJava통과"*"→ 화이트리스트로 좁혔습니다. Origin 헤더를 보내지 않는 네이티브 클라는 통과되어 보통 안전하나, 앱이 WebSocket에 Origin을 실어 보낼 경우 핸드셰이크가 막힐 수 있어/ws/chat·/ws/blinddate실제 앱 스테이징 연결 테스트 필요X-Forwarded-For를 덮어쓰는지(스푸핑 방지 전제) 확인ImageSignatureDetector,FileValidator,RateLimitFilter🤖 Generated with Claude Code