Skip to content

fix: answer CORS OPTIONS without an API key - #148

Merged
caigee-cmd merged 3 commits into
mainfrom
fix/cors-options-preflight
Sep 14, 2026
Merged

fix: answer CORS OPTIONS without an API key#148
caigee-cmd merged 3 commits into
mainfrom
fix/cors-options-preflight

Conversation

@caigee-cmd

@caigee-cmd caigee-cmd commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Serve CORS preflight OPTIONS with 204 before API-key auth so browser extensions can call /v1 (#145).
  • Reflect Origin and allow Authorization, Content-Type, x-api-key, X-CLI2API-Session, and X-Qoder-Account.
  • Keep GET/POST authenticated; unauthorized chat still returns 401 with CORS headers so the client can read the error.

Test plan

  • go test ./internal/api/ -count=1 -run 'TestCORS|TestManagementRoutesRequireAPIKey|TestNamedAPIKeyCannotManage'
  • Confirm an extension OPTIONS /v1/chat/completions no longer gets 401
  • Confirm POST /v1/chat/completions without a key is still 401

Closes #145

Browser extensions send a preflight OPTIONS request without Authorization.
Serve 204 with CORS headers before auth so /v1 remains usable cross-origin,
while GET/POST still require a key.
@caigee-cmd

Copy link
Copy Markdown
Owner Author

1

@caigee-cmd
caigee-cmd merged commit 0c71b11 into main Sep 14, 2026
6 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.

跨域情况下,OPTION类型的请求会被401阻止

1 participant