[Fix] refresh 쿠키 SameSite를 환경변수로 오버라이드 가능하게 함 - #36
Conversation
로컬 프론트(localhost)가 배포된 서버를 호출해 테스트할 때, refresh_token 쿠키가 SameSite=Lax라 cross-site fetch/axios 요청에는 브라우저가 쿠키를 붙이지 않아 refresh API가 항상 401이었다 (로그인 리다이렉트는 top-level navigation이라 문제없이 되는 것과 대조적). Swagger UI는 서버와 같은 origin이라 문제가 드러나지 않았다. app.auth.refresh-cookie.same-site 프로퍼티(REFRESH_COOKIE_SAME_SITE 환경변수, 기본값 Lax)를 추가해, 로컬 프론트 테스트 기간에만 배포 시 None으로 오버라이드할 수 있게 한다. 기본값을 그대로 두면 기존 동작과 동일하다.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefresh 쿠키의 SameSite 값을 Terraform과 SSM을 거쳐 배포 환경에서 주입하고, ChangesRefresh 쿠키 SameSite 설정
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/main/java/com/shinhan/klljs/domain/auth/service/RefreshTokenService.java`:
- Line 50: RefreshTokenService의 cookieSameSite 설정이 허용된 값만 사용하도록 생성 시점에 검증하세요. 값이
Lax, Strict, None 중 하나인지 확인하고, 오타·빈 값 등 잘못된 설정이면 즉시 명확한 예외를 발생시키며, 검증된 값만
ResponseCookie.sameSite(...)에 전달되도록 수정하세요.
In
`@src/test/java/com/shinhan/klljs/domain/auth/service/RefreshTokenServiceTest.java`:
- Line 54: Update RefreshTokenServiceTest to construct RefreshTokenService with
the "None" SameSite setting and assert that buildCookie() produces a cookie
whose SameSite value is "None". Keep the assertion focused on the externally
observable cookie behavior and ensure it exercises the constructor configuration
path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 7e058a4d-b529-48dd-8d2c-757823be97db
📒 Files selected for processing (3)
src/main/java/com/shinhan/klljs/domain/auth/service/RefreshTokenService.javasrc/main/resources/application-prod.ymlsrc/test/java/com/shinhan/klljs/domain/auth/service/RefreshTokenServiceTest.java
- Terraform: refresh_cookie_same_site 변수(기본값 Lax) 추가, SSM 파라미터 /vision/prod/refresh-cookie-same-site로 저장 - cd.yml: 배포 시 이 SSM 파라미터를 조회해 REFRESH_COOKIE_SAME_SITE 환경변수로 컨테이너에 전달 (기존 SSM 파라미터들과 동일한 패턴) - RefreshTokenService: Lax/Strict/None 외의 값이 들어오면 기동 시점에 IllegalStateException으로 즉시 실패시킨다 - 오타가 조용히 401 재발로 이어지는 걸 막는다 - RefreshTokenServiceTest: None으로 생성했을 때 실제로 SameSite=None, Secure=true가 나오는지, 잘못된 값이 기동을 막는지 검증하는 테스트 추가
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@infra/variables.tf`:
- Around line 114-123: variable "refresh_cookie_same_site"에 validation 블록을 추가해
값이 "Lax", "Strict", "None" 중 하나인지 Terraform 단계에서 검증하세요. 기존 default와 설명은 유지하고,
애플리케이션의 기동 시 검증도 제거하지 마세요.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5f9d09c2-fbb2-44c1-a4ae-010e0a37a51e
📒 Files selected for processing (7)
.github/workflows/cd.ymlinfra/main.tfinfra/modules/ssm_params/main.tfinfra/modules/ssm_params/variables.tfinfra/variables.tfsrc/main/java/com/shinhan/klljs/domain/auth/service/RefreshTokenService.javasrc/test/java/com/shinhan/klljs/domain/auth/service/RefreshTokenServiceTest.java
CodeRabbit 리뷰 반영. 애플리케이션 기동 시 검증(RefreshTokenService)은 그대로 두고, terraform plan/apply 단계에서도 Lax/Strict/None 외의 값을 미리 걸러내 오타를 더 빨리 잡는다.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@infra/variables.tf`:
- Line 126: Update the validation error_message for refresh_cookie_same_site so
it accurately describes failure during Terraform plan/apply validation and the
resulting deployment behavior, removing the contradictory claim that apply can
succeed despite a typo. Keep the allowed-value guidance for Lax, Strict, and
None.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ef974941-c434-4faf-bb0d-6ee0279032a4
📒 Files selected for processing (1)
infra/variables.tf
이 validation 블록이 있으면 오타는 plan/apply 단계에서 바로 막힌다 - "apply는 성공해도"라는 이전 문구는 검증이 없던 상태를 설명한 것이라 지금 코드와 모순됐다.
🐛 버그 설명
로컬 프론트(
http://localhost:5173)가 배포된 서버(issue #31 대응으로app_frontend_url을 로컬로 임시 스왑한 인스턴스)를 호출해 소셜 로그인 테스트를 하면, 로그인 후 success로 리다이렉트는 정상 되는데POST /api/v1/auth/token/refresh를 호출하면 항상 401이 뜬다.Swagger UI(서버가 직접 서빙)에서 같은 흐름을 테스트하면 문제없이 된다.
원인
RefreshTokenService가 refresh 쿠키를SameSite=Lax로 발급한다.SameSite=Lax쿠키는 로그인 리다이렉트 같은 top-level navigation에는 붙지만,fetch/axios같은 cross-site subresource 요청에는 브라우저가 아예 첨부하지 않는다.refreshToken == null→AuthTokenController가 즉시 401예상 동작
로컬 프론트에서도 배포된 서버를 대상으로 refresh API까지 막힘없이 테스트할 수 있어야 한다.
📝 변경 사항
코드
RefreshTokenService: 쿠키의SameSite값을 하드코딩된"Lax"에서app.auth.refresh-cookie.same-site프로퍼티(기본값Lax)로 변경RefreshTokenService:Lax/Strict/None외의 값이 들어오면 기동 시점에IllegalStateException으로 즉시 실패 — 오타가 조용히 401 재발로 이어지는 걸 막는다application-prod.yml:REFRESH_COOKIE_SAME_SITE환경변수로 오버라이드 가능하게 배선. 기본값을 두면 지금 운영 동작과 완전히 동일하다RefreshTokenServiceTest:None으로 생성했을 때 실제로SameSite=None,Secure=true가 나오는지, 잘못된 값이 기동을 막는지 검증하는 테스트 추가 (기존Laxassertion도 그대로 통과)인프라 (배포 파이프라인까지 전체 배선)
infra/variables.tf:refresh_cookie_same_site변수 추가 (기본값Lax— tfvars 안 건드려도 apply 가능)infra/modules/ssm_params:/vision/prod/refresh-cookie-same-siteSSM 파라미터 추가 (비밀 아님,String타입).github/workflows/cd.yml: 배포 시 이 SSM 파라미터를 조회해REFRESH_COOKIE_SAME_SITE환경변수로 컨테이너에 전달 (기존 15개 파라미터와 동일한 패턴)실제로 로컬 테스트를 풀려면 (머지 후)
infra/terraform.tfvars에refresh_cookie_same_site = "None"추가terraform plan/apply로 SSM 파라미터 생성/변경 확인app_frontend_url원복과 함께 이 값도Lax로 되돌려야 함 (docs/before-prod-deploy-revert-issue-31.md체크리스트에 추가 권장)Closes #31
Test plan
./gradlew compileJava compileTestJava./gradlew test --tests RefreshTokenServiceTest(12개 전부 통과 —Lax/None/잘못된 값 케이스 포함)terraform validate(backend 없이 init, 문법/참조 검증 통과)terraform fmt -check(변경 파일만 대상, 포맷 이상 없음)bash -n문법 검사 + mock aws/docker/curl로 dry-run,docker run에REFRESH_COOKIE_SAME_SITE가 정상 전달되는지 확인Summary by CodeRabbit
SameSite값을 설정으로 조정할 수 있습니다(기본값:Lax).Lax/Strict/None) 외 입력 시 시작 시점에 오류가 발생하도록 검증을 강화했습니다.SameSite가 반영되는지와 잘못된 값 입력 시 예외 발생을 검증하는 테스트를 보완/추가했습니다.REFRESH_COOKIE_SAME_SITE를 컨테이너에 전달하고, SSM 파라미터에도 저장되도록 확장했습니다.