-
-
Notifications
You must be signed in to change notification settings - Fork 274
feat(api): add CORS headers for browser clients #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * CORS headers for public API endpoints. | ||
| * | ||
| * ClawHub is a public skill registry. Browser-based clients (like Cove WebUI) | ||
| * need CORS headers to fetch skills directly from the API. | ||
| */ | ||
|
|
||
| export const CORS_HEADERS = { | ||
| 'Access-Control-Allow-Origin': '*', | ||
| 'Access-Control-Allow-Methods': 'GET, POST, DELETE, OPTIONS', | ||
| 'Access-Control-Allow-Headers': 'Content-Type, Authorization', | ||
| 'Access-Control-Max-Age': '86400', // 24 hours | ||
| } as const | ||
|
Comment on lines
+8
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2]
Consider either echoing Prompt To Fix With AIThis is a comment left during a code review.
Path: convex/lib/cors.ts
Line: 8:13
Comment:
[P2] `Access-Control-Allow-Headers` may be too narrow for real browser clients
`CORS_HEADERS` hard-codes `'Access-Control-Allow-Headers': 'Content-Type, Authorization'` (`convex/lib/cors.ts:8-13`). In practice, browser requests can include other headers that trigger a preflight (e.g., `Accept`, `If-None-Match`, `Range`, `X-Requested-With`). If a client sends any additional header, the preflight will be rejected even though the server is otherwise willing to serve the request.
Consider either echoing `Access-Control-Request-Headers` or broadening this list to the headers your clients actually send.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| /** | ||
| * Handle CORS preflight (OPTIONS) requests. | ||
| */ | ||
| export function corsPreflightResponse(): Response { | ||
| return new Response(null, { | ||
| status: 204, | ||
| headers: CORS_HEADERS, | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] OPTIONS preflight only registered for
/api/prefixThis adds an OPTIONS handler only for
pathPrefix: '/api/'(convex/http.ts:199-204). However, this router also exposesLegacyApiRoutes.*(still under/apiin many setups) and potentially other non-/api/HTTP routes (e.g., auth routes). If any of those endpoints are called cross-origin and trigger a preflight, they’ll still fail with a missing/404 OPTIONS route even though the GET/POST responses now include CORS headers.If the intent is “all API endpoints,” consider also covering legacy routes (and/or the auth routes) with an OPTIONS handler that matches their prefixes.
Prompt To Fix With AI