Repository navigation
fix(api): CORS for SSE stream and non-safelisted methods - #22
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR improves CORS handling across the API server by explicitly declaring allowed HTTP methods in the CORS middleware configuration and propagating computed CORS headers into Server-Sent Events responses. The changes ensure consistent CORS behavior for both regular HTTP endpoints and SSE streams. ChangesCORS Configuration and SSE Header Propagation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Resumo
Corrige dois bugs de CORS que impedem clientes browser cross-origin de usar a API, mesmo com a origem corretamente listada em
CORS_ORIGINS. 2 commits, 2 arquivos.Closes #21.
Bug fixes
apps/api/src/http/server.ts: o@fastify/cors@11.2.0passou a usarmethods: 'GET,HEAD,POST'por default; sem declararmethods, DELETE/PATCH/PUT eram bloqueados no preflight em todas as rotas (webhooks, sessoes, api-keys via DELETE; tenant/settings e groups via PATCH). Agora o cors declara explicitamente GET/HEAD/POST/PUT/PATCH/DELETE.apps/api/src/http/sse.ts: oreply.hijack()do stream descartava os headers de CORS, entaoGET /sessions/:id/eventssaia semAccess-Control-Allow-Origine qualquer consumidor SSE no browser cross-origin era bloqueado. Agora os headers de CORS computados pelo plugin (access-control-allow-origin,-allow-credentials,vary) sao repassados nowriteHead, herdando a politica configurada.Plano de teste
pnpm lint,pnpm typecheckepnpm buildterminam zerados.curl -X OPTIONS -H "Origin: <origem em CORS_ORIGINS>" -H "Access-Control-Request-Method: DELETE" /webhooks/:idretornaAccess-Control-Allow-MethodsincluindoDELETE.curl -H "Origin: <origem em CORS_ORIGINS>" /sessions/:id/eventsretornaAccess-Control-Allow-Origin.CORS_ORIGINScontinua bloqueada (sem header ACAO no preflight e no stream).Summary by CodeRabbit