Skip to content

Conversation

@patulus
Copy link
Member

@patulus patulus commented Jul 30, 2025

What is this PR?🔍

Changes💻

  • 잘못된 패턴으로 인해 JWT 필터를 거치는 문제를 수정합니다.
  • 토큰 리프레시 API에 액세스 토큰(Authorization 헤더) 또는 리프레시 토큰(쿠키)가 없는 등 필수 헤더 값 또는 필수 쿠키가 없다면 비즈니스 예외를 던지도록 수정합니다.

Summary by CodeRabbit

  • 버그 수정

    • 필수 필드 누락 시 반환되는 HTTP 상태 코드가 204에서 400으로 변경되어, 잘못된 요청임을 명확히 알 수 있습니다.
    • JWT 인증 필터의 경로 매칭이 개선되어 인증 제외 경로 인식이 정확해졌습니다.
  • 신규 기능

    • 필수 요청 헤더 또는 쿠키가 누락된 경우, 사용자에게 명확한 오류 메시지와 함께 안내가 제공됩니다.
  • 기타

    • 예외 처리 로깅 메시지가 개선되어, 오류 상황 파악이 더욱 용이해졌습니다.

@patulus patulus requested review from Juhye0k and kon28289 July 30, 2025 11:10
@patulus patulus self-assigned this Jul 30, 2025
@patulus patulus added the bug Something isn't working label Jul 30, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 30, 2025

Walkthrough

이 변경 사항은 보안 구성에서 특정 엔드포인트의 permitAll 규칙을 제거하고, 예외 처리기를 확장하여 누락된 헤더 및 쿠키에 대한 처리를 추가하며, JWT 인증 필터의 경로 매칭 방식을 수정합니다. 또한, 예외 타입의 HTTP 상태 코드가 일부 변경되고, properties 파일의 서브프로젝트 커밋 참조가 업데이트되었습니다.

Changes

Cohort / File(s) Change Summary
Security Configuration
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/config/security/SecurityConfig.java
특정 엔드포인트(/api/v1/members/sign-in, /api/v1/members/sign-up/**, /api/v1/members/refresh, /api/v1/email/**)에 대한 permitAll 규칙 삭제. 이제 /api/v1/admin/**만 ADMIN 권한 필요, 그 외는 모두 허용.
Exception Handling
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/GlobalExceptionHandler.java
MissingRequestHeaderException, MissingRequestCookieException에 대한 새로운 예외 처리기 추가. 일부 로그 메시지 포맷 개선 및 예외 메시지 로깅 방식 변경.
Exception Type Enum
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/ExceptionType.java
ESSENTIAL_FIELD_MISSING_ERROR의 HTTP 상태 코드를 204(NO_CONTENT)에서 400(BAD_REQUEST)로 변경.
JWT Filter Path Matching
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/jwt/filter/JwtAuthenticationFilter.java
excludePath 배열의 각 경로에 슬래시(/)를 추가하여 URI 매칭 정확도 개선.
Properties Submodule Reference
src/main/resources/properties
서브프로젝트 커밋 해시를 새로운 값으로 업데이트.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant GlobalExceptionHandler

    Client->>Server: HTTP 요청 (헤더/쿠키 누락)
    Server->>GlobalExceptionHandler: MissingRequestHeaderException 또는 MissingRequestCookieException 발생
    GlobalExceptionHandler-->>Client: 400 BAD_REQUEST 및 커스텀 메시지 반환
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/jwt

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (2)
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/GlobalExceptionHandler.java (2)

78-83: 누락된 헤더에 대한 구체적인 정보 제공을 고려해보세요.

새로운 MissingRequestHeaderException 핸들러가 추가되어 토큰 리프레시 API의 요구사항을 충족합니다. 다만 어떤 헤더가 누락되었는지에 대한 구체적인 정보를 포함하면 더 유용할 것입니다.

다음과 같이 구체적인 헤더명을 포함하는 것을 고려해보세요:

@ExceptionHandler(MissingRequestHeaderException.class)
public ResponseEntity<ResponseBody<Void>> handleMissingRequestHeaderException(MissingRequestHeaderException e) {
+   String customMessage = "필수 HTTP 헤더가 존재하지 않습니다: " + e.getHeaderName();
    return ResponseEntity
            .status(ExceptionType.ESSENTIAL_FIELD_MISSING_ERROR.getStatus())
-           .body(ResponseUtil.createFailureResponse(ExceptionType.ESSENTIAL_FIELD_MISSING_ERROR, "필수 HTTP 헤더가 존재하지 않습니다."));
+           .body(ResponseUtil.createFailureResponse(ExceptionType.ESSENTIAL_FIELD_MISSING_ERROR, customMessage));
}

85-90: 누락된 쿠키에 대한 구체적인 정보 제공을 고려해보세요.

새로운 MissingRequestCookieException 핸들러가 추가되어 토큰 리프레시 API의 요구사항을 충족합니다. 마찬가지로 어떤 쿠키가 누락되었는지에 대한 구체적인 정보를 포함하면 더 유용할 것입니다.

다음과 같이 구체적인 쿠키명을 포함하는 것을 고려해보세요:

@ExceptionHandler(MissingRequestCookieException.class)
public ResponseEntity<ResponseBody<Void>> handleMissingRequestCookieException(MissingRequestCookieException e) {
+   String customMessage = "필수 쿠키가 존재하지 않습니다: " + e.getCookieName();
    return ResponseEntity
            .status(ExceptionType.ESSENTIAL_FIELD_MISSING_ERROR.getStatus())
-           .body(ResponseUtil.createFailureResponse(ExceptionType.ESSENTIAL_FIELD_MISSING_ERROR, "필수 쿠키가 존재하지 않습니다."));
+           .body(ResponseUtil.createFailureResponse(ExceptionType.ESSENTIAL_FIELD_MISSING_ERROR, customMessage));
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7cb74f2 and e0577fd.

📒 Files selected for processing (5)
  • src/main/java/kr/ac/kumoh/d138/JobForeigner/global/config/security/SecurityConfig.java (0 hunks)
  • src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/ExceptionType.java (1 hunks)
  • src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/GlobalExceptionHandler.java (4 hunks)
  • src/main/java/kr/ac/kumoh/d138/JobForeigner/global/jwt/filter/JwtAuthenticationFilter.java (1 hunks)
  • src/main/resources/properties (1 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/kr/ac/kumoh/d138/JobForeigner/global/config/security/SecurityConfig.java
🧰 Additional context used
📓 Path-based instructions (1)
**/*.java

⚙️ CodeRabbit Configuration File

**/*.java: This project follows key rules from the NAVER Campus Hackday Java Coding Conventions (partial summary below; see full spec for details). * Indentation: use spaces (no tabs), tab width = 4 spaces. Files must end with Unix LF newline. * Line length: maximum 120 characters. * Imports: single-class imports only, allow wildcard for static imports, group imports with blank lines between sections. * Assignment operators (=, +=, -=, etc.): always have one space before and after; when breaking lines, the operator must start the next line (Binary expressions: operation sign on next line). * Lambda expressions: omit parentheses for a single parameter; surround -> with spaces (param -> expression); use braces and explicit return for multi-statement bodies; choose short, clear parameter names to keep intent visible. For the complete set of conventions and detailed examples, please refer to the full spec at https://naver.github.io/hackday-conventions-java/.

Files:

  • src/main/java/kr/ac/kumoh/d138/JobForeigner/global/jwt/filter/JwtAuthenticationFilter.java
  • src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/ExceptionType.java
  • src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/GlobalExceptionHandler.java
🧠 Learnings (2)
📓 Common learnings
Learnt from: patulus
PR: th-D138/Backend-JobForeigner#59
File: src/main/java/kr/ac/kumoh/d138/JobForeigner/global/jwt/authentication/JwtAuthentication.java:24-24
Timestamp: 2025-07-10T01:43:40.239Z
Learning: Spring Security의 hasRole() 및 hasAnyRole() 메서드는 자동으로 "ROLE_" 접두사를 추가하므로, SecurityConfig에서 MemberType.ADMIN.name()을 사용하고 JwtAuthentication에서 memberType.getKey()를 사용하는 것이 호환됨. SecurityConfig 수정이 불필요함.
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/jwt/filter/JwtAuthenticationFilter.java (1)

Learnt from: patulus
PR: #59
File: src/main/java/kr/ac/kumoh/d138/JobForeigner/global/jwt/authentication/JwtAuthentication.java:24-24
Timestamp: 2025-07-10T01:43:40.239Z
Learning: Spring Security의 hasRole() 및 hasAnyRole() 메서드는 자동으로 "ROLE_" 접두사를 추가하므로, SecurityConfig에서 MemberType.ADMIN.name()을 사용하고 JwtAuthentication에서 memberType.getKey()를 사용하는 것이 호환됨. SecurityConfig 수정이 불필요함.

🧬 Code Graph Analysis (1)
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/GlobalExceptionHandler.java (2)
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/response/ResponseUtil.java (1)
  • ResponseUtil (5-28)
src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/ExceptionHandlerFilter.java (2)
  • ExceptionHandlerFilter (15-32)
  • doFilterInternal (21-31)
🔇 Additional comments (4)
src/main/resources/properties (1)

1-1: 서브모듈 커밋 갱신 후 CI/CD 정상 동작 확인 요청

Subproject commit 해시가 변경되었습니다. 서브모듈을 사용하는 빌드·배포 파이프라인에서 git submodule update --init --recursive 단계가 누락되면 컴파일 오류가 발생할 수 있으니, CI 로그를 한 번 더 점검해 주세요.

src/main/java/kr/ac/kumoh/d138/JobForeigner/global/jwt/filter/JwtAuthenticationFilter.java (1)

33-33: 경로 매칭 수정이 적절합니다.

JWT 필터에서 제외해야 할 경로들에 슬래시(/) 접두사를 추가한 것은 올바른 수정입니다. HTTP 요청 URI는 일반적으로 슬래시로 시작하므로, 이 변경으로 토큰 리프레시 API(/api/v1/members/refresh)가 의도한 대로 JWT 필터를 우회할 수 있게 됩니다.

src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/ExceptionType.java (1)

15-15: HTTP 상태 코드 수정이 적절합니다.

ESSENTIAL_FIELD_MISSING_ERROR의 HTTP 상태 코드를 NO_CONTENT(204)에서 BAD_REQUEST(400)로 변경한 것은 올바른 수정입니다. 필수 필드 누락은 클라이언트 오류에 해당하므로 400 상태 코드가 의미상 더 적절합니다.

src/main/java/kr/ac/kumoh/d138/JobForeigner/global/exception/GlobalExceptionHandler.java (1)

43-43: 로깅 형식 변경이 일관성 있게 적용되었습니다.

예외 로깅 형식을 메시지만 기록하도록 변경한 것은 로그 가독성을 향상시킵니다. 특히 일반적인 예외 핸들러에서 전체 스택 트레이스를 기록하도록 한 것은 디버깅에 도움이 됩니다.

Also applies to: 65-65, 94-94

Copy link
Contributor

@kon28289 kon28289 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다

@patulus patulus merged commit c907a21 into dev Jul 30, 2025
3 checks passed
@patulus patulus deleted the fix/jwt branch July 30, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants