Skip to content

fix: add CORS headers to early-return responses in chat completions route - #208

Closed
diegosouzapw with Copilot wants to merge 2 commits into
features-agente-mcp-a2afrom
copilot/sub-pr-207
Closed

diegosouzapw with Copilot wants to merge 2 commits into
features-agente-mcp-a2afrom
copilot/sub-pr-207

Conversation

Copilot AI commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

The 400 (prompt injection blocked) and 503 (guard unavailable) early-return responses in the chat completions route were missing CORS headers, causing browser clients to be blocked by CORS on those paths even though the server returned valid JSON.

Changes

  • src/app/api/v1/chat/completions/route.ts: Import CORS_HEADERS from the shared cors utility and spread into both early-return response headers
// Before
{ status: 503, headers: { "Content-Type": "application/json" } }

// After
{ status: 503, headers: { ...CORS_HEADERS, "Content-Type": "application/json" } }

Applies to both the 400 injection-blocked response and the 503 guard-unavailable response, consistent with every other API route in the codebase.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…oute

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on 'Features agente mcp a2a' PR fix: add CORS headers to early-return responses in chat completions route Mar 5, 2026
@diegosouzapw

Copy link
Copy Markdown
Owner

Fix integrated directly into features-agente-mcp-a2a branch. Thank you Copilot! 🎉

diegosouzapw added a commit that referenced this pull request Mar 5, 2026
…tion (#208, #209)

- Added CORS_HEADERS spread to 400/503 responses in chat/completions route
- Added createAutoComboSchema with Zod validation to /api/combos/auto
- Isolated JSON parsing errors with structured 400 response
- Prevented String(err) leakage on 500 errors
@diegosouzapw
diegosouzapw deleted the copilot/sub-pr-207 branch March 5, 2026 20:46
diegosouzapw added a commit that referenced this pull request Mar 7, 2026
…tion (#208, #209)

- Added CORS_HEADERS spread to 400/503 responses in chat/completions route
- Added createAutoComboSchema with Zod validation to /api/combos/auto
- Isolated JSON parsing errors with structured 400 response
- Prevented String(err) leakage on 500 errors
This was referenced May 10, 2026
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.

2 participants