Skip to content

인터널 프론트를 위한 CORS 설정 추가 - #73

Open
ff1451 wants to merge 1 commit into
feat/t18-track-membersfrom
feat/t26-backend-cors
Open

인터널 프론트를 위한 CORS 설정 추가#73
ff1451 wants to merge 1 commit into
feat/t18-track-membersfrom
feat/t26-backend-cors

Conversation

@ff1451

@ff1451 ff1451 commented Aug 20, 2026

Copy link
Copy Markdown

배경

인터널 관리 화면(T-26, BCSD_INTERNAL_RECODE_V2)이 별도 오리진에서 credentials: 'include'로 브라우저에서 직접 API를 호출한다. 지금까지 SecurityConfig.cors(...)가 전혀 없어서, 테스트(MockMvc는 CORS 필터를 거치지 않음)는 통과했지만 실제 브라우저 요청은 전부 CORS로 막히는 상태였다. 프론트 셸을 붙이기 전에 먼저 고쳐야 하는 백엔드 쪽 문제라 별도 PR로 분리했다.

변경

  • app.cors.allowed-origins(CORS_ALLOWED_ORIGINS 환경변수, 기본 http://localhost:3000)로 허용 오리진을 설정한다.
  • credentials를 쓰므로 Allow-Origin: *를 쓸 수 없어 명시적 오리진 목록 + allowCredentials(true)로 구성했다.

참고 (로컬 개발 시)

  • refresh token 쿠키는 SameSite=Lax인데, internal.bcsdlab.comapi.internal.bcsdlab.com은 같은 eTLD+1(bcsdlab.com)이라 SameSite 기준 same-site라 운영 환경은 문제없다.
  • 로컬에서 http://localhost로 붙일 때는 REFRESH_TOKEN_COOKIE_SECURE=false를 켜야 한다(기본값 truehttp://localhost에서 Secure 쿠키가 브라우저에 의해 버려진다). 배포 환경변수는 그대로 두면 된다.

검증

  • ./gradlew test 전체 통과, 3회 연속.
  • 허용 오리진의 실제 요청과 preflight(OPTIONS) 각각 CORS 헤더가 붙는지, 비허용 오리진에는 헤더가 없는지 통합 테스트로 확인.

Refs #7 (인터널 프론트 T-26), 브랜치는 feat/t18-track-members(#72) 위에 스택 — T-14~T-18까지 포함된 상태입니다.

머지하지 않습니다. 부원 리뷰 후 직접 머지 예정입니다.

- 인터널 관리 화면(BCSD_INTERNAL_RECODE_V2, T-26)이 별도 오리진에서 credentials:
  'include'로 브라우저에서 직접 API를 호출한다. 지금까지 SecurityConfig에 .cors(...)가
  전혀 없어서 실제 브라우저 요청은 전부 CORS로 막힌다(테스트는 MockMvc라 CORS 필터를
  거치지 않아 이 문제가 드러나지 않았다).
- app.cors.allowed-origins(CORS_ALLOWED_ORIGINS 환경변수, 기본
  http://localhost:3000)로 허용 오리진을 설정한다. credentials를 쓰므로
  Allow-Origin에 "*"를 쓸 수 없어 명시적 오리진 목록 + allowCredentials(true)로 구성했다.
- refresh token 쿠키는 SameSite=Lax인데, internal.bcsdlab.com과
  api.internal.bcsdlab.com은 같은 eTLD+1(bcsdlab.com)이라 SameSite 기준으로는
  same-site이므로 운영 환경에서는 이미 문제가 없다. 로컬 개발에서 리프레시가 계속
  실패한다면 REFRESH_TOKEN_COOKIE_SECURE=false(기본값 true라 http://localhost에서
  Secure 쿠키가 버려진다)를 켜야 한다는 점은 프론트 셸 PR에 남긴다.

검증: ./gradlew test 전체 통과, 3회 연속. 허용 오리진 실제 요청·preflight·비허용
오리진 각각 CORS 헤더로 확인.
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a39f4f8-44d0-46dc-87c8-9fe77a7a6237

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@ff1451

ff1451 commented Aug 20, 2026

Copy link
Copy Markdown
Author

Refs #7 (BCSD_INTERNAL_RECODE_V2)

@ff1451

ff1451 commented Aug 20, 2026

Copy link
Copy Markdown
Author

🔴 이 PR은 불필요할 가능성이 높습니다 — 제 실수로 만든 문제였습니다.

인터널 프론트(BCSD_INTERNAL_RECODE_V2)의 next.config.ts에는 이미 rewrite 프록시가 있습니다:

const API_ORIGIN = process.env.API_ORIGIN ?? 'http://localhost:8080';
async rewrites() {
  return [{ source: '/v1/:path*', destination: `${API_ORIGIN}/v1/:path*` }];
}

브라우저는 same-origin으로 /v1/...을 호출하고 Next 서버가 백엔드로 프록시합니다. 크로스 오리진 요청이 아예 없으니 CORS도 걸리지 않습니다.

제가 CORS 문제를 겪은 건 이 프록시를 확인하지 않고 프론트에서 NEXT_PUBLIC_API_BASE_URLhttp://localhost:8080을 직접 호출했기 때문입니다. 프론트를 팀 방식(프록시)으로 되돌렸고(RECODE#17), 로컬에서 curl localhost:3000/v1/tracks → 200으로 CORS 없이 동작하는 것을 확인했습니다.

닫는 걸 권합니다. 브라우저 외 클라이언트가 API를 직접 호출할 계획이 있으면 그때 다시 올리는 게 맞다고 봅니다. 판단은 맡기겠습니다 — 스택 아래쪽(#68~#72)에 붙어 있으니 닫으실 거면 #74의 base를 #72로 바꿔야 합니다.

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.

1 participant