Skip to content

feat(api): CORS 허용 origin을 환경변수로 설정 - #21

Merged
Lee-Soyeon merged 1 commit into
mainfrom
feat/cors-allowed-origins
Oct 20, 2026
Merged

Lee-Soyeon merged 1 commit into
mainfrom
feat/cors-allowed-origins

Conversation

@Lee-Soyeon

Copy link
Copy Markdown
Contributor

요약

API 서버가 쿠키를 실은 요청을 환경변수(CORS_ALLOWED_ORIGINS)에 적은 사이트에만 허용합니다.

#17 분할 PR B4 (main에서 바로 시작, 선행 PR 없음).

목적

프런트엔드는 credentials: "include"로 요청해서, allow_origins=["*"]는 브라우저가 거부합니다. #17은 이를 allow_origin_regex=".*"로 바꿨는데, allow_credentials=True와 함께 쓰면 모든 사이트가 쿠키를 실은 요청의 응답을 읽을 수 있어 위험합니다 (리뷰 지적). 허용 목록을 환경변수로 받도록 고칩니다.

변경 사항

  • 🔒 CorsSettings 추가: CORS_ALLOWED_ORIGINS(쉼표로 구분)에 적힌 origin만 허용합니다.
  • 🛠️ 기본값은 로컬 개발용 http://localhost:3000 하나입니다. 운영에서는 실제 프런트 도메인으로 설정해야 합니다.
  • 📝 backend/README.md 환경변수 표에 추가했습니다.
  • allow_origin_regex=".*"는 쓰지 않습니다.

테스트

  • make -C backend format / unit-test 통과 (23개), 기본값·쉼표 파싱 단위 테스트 추가
  • 참고: 이 브랜치에서 lint/type-check가 worker.py의 livekit.plugins.fishaudio/hedra import를 못 찾는다고 나오는 것은 제 로컬 가상환경이 feat(agent): TTS를 Fish Audio에서 ElevenLabs로 교체 #15 의존성이라서이며, 이 PR의 변경과 무관합니다 (main 그대로).
  • CORS_ALLOWED_ORIGINS에 적은 도메인의 프런트에서 쿠키 요청이 되는지
  • 적지 않은 도메인에서는 응답을 읽을 수 없는지

🤖 Generated with Claude Code

https://claude.ai/code/session_01DmBmpFCjUN5yzz3WPSEWva


Generated by Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmBmpFCjUN5yzz3WPSEWva
@Lee-Soyeon
Lee-Soyeon requested a review from ywkim October 16, 2026 00:09

Copy link
Copy Markdown
Contributor Author

@ywkim #17 분할의 B4(CORS)입니다. 재리뷰 부탁드립니다. main에서 바로 시작했고 선행 PR이 없습니다.

리뷰 지적 반영: allow_origin_regex=".*"를 쓰지 않고, 허용 origin을 CORS_ALLOWED_ORIGINS(쉼표 구분, 기본 http://localhost:3000)로 받습니다. README 환경변수 표와 단위 테스트를 추가했습니다.


Generated by Claude Code

@ywkim ywkim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Lee-Soyeon 리뷰 지적을 빠르게 반영해주셔서 감사합니다! 승인합니다.

allow_origin_regex=".*"가 사라지고 허용 origin이 CORS_ALLOWED_ORIGINS로 한정됐습니다. 기존 Settings 컨벤션과도 일치합니다.

확인한 항목

  • CI: backend-ci가 head 2d351de에서 success (unit-test 단계 포함). 로컬에는 pydantic_settings가 없어 테스트를 직접 돌리지 못해 CI 결과로 대체했습니다.
  • Starlette middleware/cors.py를 직접 읽었습니다. 목록 origin은 정확히 일치할 때만 허용하고, "*"이 목록에 있으면서 allow_credentials=True이면 요청 Origin을 그대로 반사합니다.
  • 운영 배포 설정: 미확인. 저장소에 main.py 배포 설정이 없어 운영의 CORS_ALLOWED_ORIGINS 설정 여부는 확인하지 못했습니다. 설정 전에 배포되면 운영 프런트 요청이 CORS로 막힙니다.

비차단 (머지 후 후속 가능)

  • settings.py: CORS_ALLOWED_ORIGINS=*를 막지 않습니다. 위 Starlette 동작 때문에 쿠키 요청에서 모든 origin이 허용돼 이 PR이 막으려던 위험이 재현됩니다. * 거부 검증과 테스트 1건을 권합니다.
  • settings.py: origin을 정규화하지 않습니다. https://a.com/처럼 끝 슬래시가 붙으면 Origin 헤더와 영원히 불일치해, 오류 없이 CORS만 실패합니다.
  • README.md: frontend/.env.development가 API를 127.0.0.1:8000으로 가리키므로, 프런트를 http://127.0.0.1:3000으로 열면 기본값으로는 막힙니다. 한 줄 안내를 권합니다.

Generated by Claude Code

@Lee-Soyeon
Lee-Soyeon merged commit 76eb83f into main Oct 20, 2026
1 check passed
@Lee-Soyeon
Lee-Soyeon deleted the feat/cors-allowed-origins branch October 20, 2026 00:09
Lee-Soyeon pushed a commit that referenced this pull request Oct 21, 2026
Hedra 아바타 삭제는 별도 PR로 분리한다. main(#21, #28)을 병합하고
Fish Audio -> ElevenLabs TTS 교체만 남긴다 (hedra extra와 코드 유지).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HtQpw2nbQZLwzSJGbw5E3C
Lee-Soyeon added a commit that referenced this pull request Oct 21, 2026
## 요약

AI 아이돌 통화의 음성을 Fish Audio에서 **ElevenLabs TTS**로 바꿉니다. Hedra 아바타 삭제와
LiveKit Agents 1.8 업그레이드는 리뷰 요청에 따라 이 PR에서 **뺐습니다** (각각 별도 PR).
`livekit-agents`는 1.2.18 그대로입니다.

## 변경 사항

### 음성 (TTS)
- Fish Audio → **ElevenLabs** (`eleven_flash_v2_5`).
`FANCALL_ELEVENLABS_MODEL`로 모델 변경 가능.
- API 키는 `ELEVEN_API_KEY` (`ElevenLabsSettings` 추가).
- extra를 `fishaudio` → `elevenlabs`로 교체 (`hedra` extra는 유지).
`poetry.lock`은 main 대비 fish 플러그인 의존성 제거와 `livekit-plugins-elevenlabs`
추가만 바뀝니다.
- 기본 페르소나(은우)의 Fish voice ID 제거. voice ID가 없으면 ElevenLabs 기본 목소리 사용.

### 호출하는 쪽에 영향
- `create_worker_options()`: `fish_settings` → `elevenlabs_settings`.
호스트 앱이 직접 호출하면 함께 수정 필요. `hedra_settings`는 그대로입니다.
- `voice_id`는 ElevenLabs voice ID여야 함 (README, `schemas.ts` 주석에 안내).

### 이 PR에 없는 것
- Hedra 삭제: 별도 PR
- LiveKit Agents 1.8 업그레이드: 별도 PR (`feat/livekit-agents-1.8`)

main(#21, #28)을 병합해 충돌을 풀었습니다.

## 테스트
- [x] `make -C backend lint` 10/10, `type-check` 오류 0, `unit-test` 23/23
통과
- [x] (이전 커밋 기준) 로컬 LiveKit dev 서버에서 ElevenLabs 음성으로 응답 확인
- [ ] 브라우저 실제 통화 화면 확인
- [ ] 은우용 ElevenLabs voice ID 지정 확인

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01HtQpw2nbQZLwzSJGbw5E3C

---------

Co-authored-by: Claude <noreply@anthropic.com>
Lee-Soyeon added a commit that referenced this pull request Oct 23, 2026
ElevenLabs 교체는 main(#15) 쪽을 따르고, #22 고유 변경(wait_for_answer)만 main의 worker.py 위에 다시 얹었다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants