Skip to content

stag jwt 에러 무시 코드 수정#583

Merged
ByunDohwi merged 8 commits intodevelopfrom
577-stag-jwt-에러-무시-코드-수정
Dec 15, 2025

Hidden character warning

The head ref may contain hidden characters: "577-stag-jwt-\uc5d0\ub7ec-\ubb34\uc2dc-\ucf54\ub4dc-\uc218\uc815"
Merged

stag jwt 에러 무시 코드 수정#583
ByunDohwi merged 8 commits intodevelopfrom
577-stag-jwt-에러-무시-코드-수정

Conversation

@ByunDohwi
Copy link
Member

@ByunDohwi ByunDohwi commented Dec 15, 2025

Summary by CodeRabbit

  • Bug Fixes

    • 인증 토큰 누락 시 명확한 401 오류 반환
    • 토큰 검사 로직 강화로 인증 우회 방지 및 접근 제어 강화
  • Chores

    • 보안 엔드포인트 경로 중앙화로 일관성 향상
    • 불필요한 CORS 설정 제거 및 보안 설정 간소화
    • JWT 검증 흐름 정리 및 예외 처리 단순화

✏️ Tip: You can customize this high-level summary in your review settings.

@ByunDohwi ByunDohwi self-assigned this Dec 15, 2025
@ByunDohwi ByunDohwi linked an issue Dec 15, 2025 that may be closed by this pull request
@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Walkthrough

보안 엔드포인트를 상수화하고 JWT 필터에 경로 기반 스킵 로직을 추가하며, 토큰 미존재 시 새로운 예외를 던지도록 인증 흐름을 단순화했습니다. CORS 관련 빈과 설정은 제거되었습니다.

Changes

Cohort / File(s) 변경 요약
보안 경로 중앙집중화
src/main/kotlin/dsm/pick2024/global/security/path/SecurityPaths.kt
여러 엔드포인트 패턴을 그룹화한 SecurityPaths 객체 추가 (PERMIT_ALL_ENDPOINTS, SCH_*, STU_*, GET_AUTHENTICATED 등)
보안 설정 리팩토링
src/main/kotlin/dsm/pick2024/global/config/security/SecurityConfig.kt
하드코딩된 엔드포인트들을 SecurityPaths 상수로 대체; CORS 관련 유틸/빈 제거; anyRequest().authenticated()anyRequest().denyAll()로 변경
JWT 필터 제어 흐름 변경
src/main/kotlin/dsm/pick2024/global/security/jwt/JwtTokenFilter.kt
shouldNotFilter() 추가로 PERMIT_ALL_ENDPOINTS 경로는 필터에서 스킵; AntPathMatcher로 경로 매칭; 토큰 미존재 시 AuthTokenMissingException 발생; 인증 설정 흐름 단순화
예외 및 에러 코드 업데이트
src/main/kotlin/dsm/pick2024/global/security/jwt/exception/AuthTokenMissingException.kt,
src/main/kotlin/dsm/pick2024/global/error/exception/ErrorCode.kt
신규 AuthTokenMissingException 추가(예외 객체, ErrorCode.AUTH_TOKEN_MISSING 사용); ErrorCodeAUTH_TOKEN_MISSING 추가 및 DEBEZIUM_CONNECTOR_ERROR 제거

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client
    participant Filter as JwtTokenFilter
    participant Paths as SecurityPaths
    participant Auth as JwtUtils/AuthProvider
    participant SecCtx as SecurityContext

    Client->>Filter: HTTP 요청 (경로 포함)
    Filter->>Paths: 요청 경로가 PERMIT_ALL인지 확인 (shouldNotFilter)
    alt permit-all 경로
        Filter-->>Client: 필터 스킵 -> 다음 핸들러로 전달
    else 보호 필요 경로
        Filter->>Auth: 요청에서 토큰 추출
        alt 토큰 없음
            Auth-->>Filter: 토큰 없음 -> AuthTokenMissingException 발생
            Filter--xClient: 401 에러 처리 (예외)
        else 토큰 존재
            Auth->>Auth: 토큰 검증 및 Authentication 생성
            Auth->>SecCtx: SecurityContext에 Authentication 설정
            Filter-->>Client: 필터 통과 -> 다음 핸들러로 전달
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • 주의할 파일/영역:
    • JwtTokenFilter.shouldNotFilter() 경로 매칭 로직 및 패턴 일치성 검증
    • 토큰 부재 시 예외 전파가 기존 예외 처리 체계(글로벌 예외 핸들러 등)와 호환되는지 확인
    • SecurityConfiganyRequest().denyAll() 변경으로 인해 누락된 허용 경로나 권한 매핑 여부 점검
    • SecurityPaths에 정의된 모든 패턴의 정확성(와일드카드, HTTP 메서드별 매핑 등)

Poem

🐰 길 모아 놓고 깡총깡총, 토큰 없으면 경고를 울려요
필터는 똑똑히 건너뛰고, 길은 상수로 단정했죠
예외는 명확히 외치고, 보안은 한결 가벼워요 🥕🔐

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning PR 제목은 JWT 에러 처리 관련 코드 수정을 의도하고 있으나, 실제 변경사항은 JWT 토큰 필터 메커니즘 재설계, 보안 경로 중앙집중식 관리, CORS 설정 제거 등 다양한 구조적 개선을 포함하고 있어 제목이 변경사항의 범위를 충분히 반영하지 못함. 제목을 'JWT 토큰 검증 및 보안 설정 리팩토링' 또는 '보안 경로 중앙집중화 및 JWT 필터 강화'로 변경하여 더 포괄적인 변경사항을 반영하도록 수정 권장.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 577-stag-jwt-에러-무시-코드-수정

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3d43133 and d423641.

📒 Files selected for processing (2)
  • src/main/kotlin/dsm/pick2024/global/security/jwt/JwtTokenFilter.kt (2 hunks)
  • src/main/kotlin/dsm/pick2024/global/security/path/SecurityPaths.kt (1 hunks)
🔇 Additional comments (4)
src/main/kotlin/dsm/pick2024/global/security/jwt/JwtTokenFilter.kt (2)

18-24: LGTM! 경로 기반 필터 스킵 로직이 올바르게 구현되었습니다.

shouldNotFilter 메서드가 AntPathMatcher를 사용하여 PERMIT_ALL_ENDPOINTS와 요청 경로를 정확히 비교하고 있습니다. 이전 리뷰에서 지적된 네이밍 이슈(PERMITALLPATHSPERMIT_ALL_ENDPOINTS)도 해결되었습니다.


31-35: 인증 플로우 단순화가 잘 되었습니다.

토큰이 없을 때 AuthTokenMissingException을 명시적으로 던지도록 변경하여 로직이 명확해졌습니다. shouldNotFilter에서 permit-all 경로를 이미 처리하므로, doFilterInternal이 실행되는 시점에는 토큰이 반드시 필요한 것이 맞습니다.

예외 처리도 적절히 구성되어 있습니다. AuthTokenMissingExceptionjwtTokenProvider.authentication(token)에서 발생 가능한 모든 예외(만료된 토큰, 유효하지 않은 토큰)는 PickException의 서브클래스로 변환되며, GlobalExceptionHandler@ExceptionHandler(PickException::class) 메서드에서 일관되게 처리됩니다.

src/main/kotlin/dsm/pick2024/global/security/path/SecurityPaths.kt (2)

3-133: LGTM! 보안 경로 중앙화가 잘 구현되었습니다.

역할(SCH/STU)과 HTTP 메서드별로 엔드포인트를 명확하게 그룹핑하여 가독성과 유지보수성이 향상되었습니다. 이전 리뷰에서 지적된 중복 엔드포인트(/status/grade, /notice/modify)도 모두 제거되었습니다.


58-58: 와일드카드 패턴 검토 완료 - 의도적인 설계입니다.

Line 58의 "/notice/*"는 단일 와일드카드를 의도적으로 사용하고 있습니다.

코드 분석:

  • "/notice/*": 단일 수준의 notice 조회 (/notice/123)
  • "/notice/delete/**": 중첩 경로를 위한 이중 와일드카드 (/notice/delete/sub/path)
  • 다른 notice 엔드포인트들은 구체적 경로 (/notice/create, /notice/modify, /notice/delete)

이는 일관된 설계이므로 변경할 필요가 없습니다.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
src/main/kotlin/dsm/pick2024/global/config/security/SecurityConfig.kt (1)

40-41: 하드코딩된 경로를 SecurityPaths로 이동하세요.

"/attendance/time/grade/**" 경로가 SecurityPaths.SCH_GET_ENDPOINTS에 포함되지 않고 하드코딩되어 있습니다. 중앙 집중식 경로 관리의 일관성을 위해 해당 경로를 SecurityPaths.SCH_GET_ENDPOINTS에 추가하는 것이 좋습니다.

SecurityPaths.kt에 경로 추가:

     val SCH_GET_ENDPOINTS = arrayOf(
         "/admin/**",
         "/after/**",
+        "/attendance/time/grade/**",
         "/application/reason/all",

그 후 SecurityConfig.kt에서:

             .antMatchers(
                 HttpMethod.GET,
-                *SecurityPaths.SCH_GET_ENDPOINTS,
-                "/attendance/time/grade/**"
+                *SecurityPaths.SCH_GET_ENDPOINTS
             ).hasRole(Role.SCH.name)
src/main/kotlin/dsm/pick2024/global/security/path/SecurityPaths.kt (1)

77-83: 중복 패턴 정리 권장.

"/after/**"는 이미 "/after/delete"를 포함하고, "/notice/delete/**""/notice/delete"를 포함합니다. 중복 항목을 제거하여 코드 가독성을 높이세요.

     val SCH_DELETE_ENDPOINTS = arrayOf(
         "/after/**",
         "/notice/delete/**",
-        "/schedule/delete/*",
-        "/after/delete",
-        "/notice/delete"
+        "/schedule/delete/*"
     )
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 85ef6e1 and 3d43133.

📒 Files selected for processing (5)
  • src/main/kotlin/dsm/pick2024/global/config/security/SecurityConfig.kt (2 hunks)
  • src/main/kotlin/dsm/pick2024/global/error/exception/ErrorCode.kt (2 hunks)
  • src/main/kotlin/dsm/pick2024/global/security/jwt/JwtTokenFilter.kt (2 hunks)
  • src/main/kotlin/dsm/pick2024/global/security/jwt/exception/AuthTokenMissingException.kt (1 hunks)
  • src/main/kotlin/dsm/pick2024/global/security/path/SecurityPaths.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Check Code Quality
🔇 Additional comments (4)
src/main/kotlin/dsm/pick2024/global/config/security/SecurityConfig.kt (1)

72-72: 보안 강화 변경 확인.

anyRequest().denyAll()로 변경하여 명시적으로 정의되지 않은 모든 엔드포인트에 대한 접근을 거부합니다. 새로운 엔드포인트 추가 시 반드시 SecurityPaths에 등록해야 합니다.

src/main/kotlin/dsm/pick2024/global/error/exception/ErrorCode.kt (1)

22-22: LGTM!

AUTH_TOKEN_MISSING 에러 코드가 적절한 401 상태 코드와 함께 추가되었습니다. JwtTokenFilter에서 토큰 부재 시 사용됩니다.

src/main/kotlin/dsm/pick2024/global/security/jwt/exception/AuthTokenMissingException.kt (1)

6-8: LGTM!

싱글톤 object 패턴을 사용한 예외 구현이 적절합니다. 스택 트레이스가 재사용되지만, 인증 관련 예외에서는 디버깅 정보 노출을 최소화하는 것이 일반적인 관행입니다.

src/main/kotlin/dsm/pick2024/global/security/jwt/JwtTokenFilter.kt (1)

31-35: 토큰 검증 로직 간소화 확인.

shouldNotFilter에서 permit-all 경로를 필터링하므로, 이 메서드에 도달하면 토큰이 필수입니다. 토큰 유효성 검증(만료, 형식 등)은 jwtTokenProvider.authentication()에서 처리되는지 확인하세요.

@ByunDohwi ByunDohwi merged commit dc9f394 into develop Dec 15, 2025
2 checks passed
@ByunDohwi ByunDohwi deleted the 577-stag-jwt-에러-무시-코드-수정 branch December 15, 2025 00:16
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.

stag jwt 에러 무시 코드 수정

2 participants