Skip to content

[USER] 개발/배포 환경별 쿠키 보안 설정 분리#51

Merged
s0ooo0k merged 1 commit intoPETTY-HUB:mainfrom
taehyun32:feat/auth
Jun 1, 2025
Merged

[USER] 개발/배포 환경별 쿠키 보안 설정 분리#51
s0ooo0k merged 1 commit intoPETTY-HUB:mainfrom
taehyun32:feat/auth

Conversation

@taehyun32
Copy link
Member

@taehyun32 taehyun32 commented Jun 1, 2025

📜 PR 내용 요약

  • 개발 및 배포 환경에 따라 쿠키의 보안 설정 (Secure, SameSite)을 다르게 적용할 수 있도록 관련 코드를 수정했습니다.
  • 이를 위해 쿠키 설정을 담당하는 CookieUtils 클래스를 스프링 컴포넌트로 관리하도록 변경하고, 환경별 설정을 주입받아 사용하도록 개선했습니다.
  • 관련 필터 및 핸들러에서 CookieUtils를 주입받아 사용하도록 수정했습니다.

⚒️ 작업 및 변경 내용(상세하게)

  • CookieUtils 클래스 수정:
    • 정적 유틸리티 클래스에서 스프링 컴포넌트 (@Component) 로 변경했습니다.
    • application.yml 또는 환경별 설정 파일(application-prod.yml)에서 security.cookie.securesecurity.cookie.same-site 속성 값을 주입받도록 필드를 추가 했습니다.
    • setTokenCookies 메서드를 인스턴스 메서드로 변경하고, 주입받은 cookieSecure 값을 사용하여 쿠키의 setSecure 속성을 설정하도록 수정했습니다.
  • LoginFilter, OAuth2SuccessHandler, UsersApiController, SecurityConfig 수정:
    • 각 클래스의 생성자 또는 필드에 CookieUtils 빈을 주입받도록 추가했습니다.
    • 기존에 CookieUtils.setTokenCookies와 같이 정적으로 호출하던 부분을 주입받은 cookieUtils 인스턴스를 통해 호출하도록 변경했습니다.
  • application-prod.yml 추가/수정:
    • 배포 환경 (prod)에서 쿠키의 Secure 속성을 true로 설정하기 위해 security.cookie.secure: true 속성을 추가했습니다.
    • security.cookie.same-site: Lax 속성도 함께 추가했습니다.

📚 기타 참고 사항

  • 이 변경을 통해 HTTPS 환경에서 필요한 Secure 쿠키 속성을 배포 환경에서만 적용하고, HTTP 환경인 개발 환경에서는 적용하지 않도록 분리하여 유연성을 확보했습니다.
  • 쿠키 보안 설정이 외부에 노출된 설정 파일(application-prod.yml)을 통해 관리되므로 환경에 따른 설정 변경이 용이해졌습니다.

@coderabbitai
Copy link

coderabbitai bot commented Jun 1, 2025

Caution

Review failed

The pull request is closed.

Summary by CodeRabbit

  • 신규 기능

    • 쿠키 설정을 애플리케이션 환경설정에서 관리할 수 있도록 개선되었습니다. 이제 쿠키의 Secure 및 SameSite 속성이 환경설정에 따라 자동 적용됩니다.
  • 버그 수정

    • 쿠키 관련 동작이 환경설정에 맞춰 일관되게 적용되어, 보안 및 동작 신뢰성이 향상되었습니다.
  • 문서화

    • production 환경설정 파일에 쿠키 관련 설정 항목이 추가되었습니다.

Walkthrough

이 변경 사항은 CookieUtils를 정적 유틸리티 클래스에서 Spring 컴포넌트로 전환하여, 관련 클래스(SecurityConfig, LoginFilter, UsersApiController, OAuth2SuccessHandler)에 의존성 주입 방식으로 전달하도록 수정합니다. 또한 프로덕션 환경에서 쿠키의 securesame-site 속성을 설정하는 구성을 추가합니다.

Changes

파일/경로 변경 요약
.../users/util/CookieUtils.java 정적 유틸리티에서 Spring 컴포넌트로 변경, 인스턴스 메서드화, cookieSecure, sameSite 속성 주입 추가
.../config/SecurityConfig.java
.../users/controller/UsersApiController.java
.../users/jwt/LoginFilter.java
.../users/oauth2/OAuth2SuccessHandler.java
각 클래스에 CookieUtils 의존성 주입 및 생성자/필드/메서드 수정, 정적 호출을 인스턴스 호출로 변경
src/main/resources/application-prod.yml security.cookie.secure: true, security.cookie.same-site: Lax 프로덕션 환경 설정 추가

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller(UsersApiController)
    participant CookieUtils
    participant Response

    Client->>Controller: refreshToken 요청
    Controller->>CookieUtils: setTokenCookies(response, token, refreshToken)
    CookieUtils->>Response: 쿠키 속성 설정 (secure, same-site 등)
    Controller-->>Client: 응답 반환
Loading
sequenceDiagram
    participant Client
    participant LoginFilter
    participant CookieUtils
    participant Response

    Client->>LoginFilter: 로그인 요청
    LoginFilter->>CookieUtils: setTokenCookies(response, token, refreshToken)
    CookieUtils->>Response: 쿠키 속성 설정
    LoginFilter-->>Client: 인증 성공 응답
Loading

Possibly related PRs

Poem

🍪
쿠키 토끼가 깡총깡총,
정적에서 인스턴스로 점프!
보안 속성 꽉 채워,
HTTPS 위에서만 춤춰요.
Lax한 마음, 안전한 밤,
오늘도 쿠키는 토끼와 함께!
🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6941d18 and 917d54e.

📒 Files selected for processing (6)
  • src/main/java/io/github/petty/config/SecurityConfig.java (3 hunks)
  • src/main/java/io/github/petty/users/controller/UsersApiController.java (2 hunks)
  • src/main/java/io/github/petty/users/jwt/LoginFilter.java (2 hunks)
  • src/main/java/io/github/petty/users/oauth2/OAuth2SuccessHandler.java (2 hunks)
  • src/main/java/io/github/petty/users/util/CookieUtils.java (1 hunks)
  • src/main/resources/application-prod.yml (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@taehyun32
Copy link
Member Author

@CodeRabbit review

@coderabbitai
Copy link

coderabbitai bot commented Jun 1, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@s0ooo0k s0ooo0k merged commit 9137415 into PETTY-HUB:main Jun 1, 2025
2 checks passed
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.

2 participants