fix(api): restrict CORS origin on Gemini estimation endpoint#211
Conversation
Replace the wildcard Access-Control-Allow-Origin header with the Firebase Hosting domain so external sites cannot call the endpoint and drain the Gemini API quota. Falls back to the production URL if ALLOWED_ORIGIN is not set. Document the env var in .env.example.
|
@kumudranjan6127-debug is attempting to deploy a commit to the hrx01-dev's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds an ChangesCORS origin restriction
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.env.example:
- Around line 23-26: The ALLOWED_ORIGIN example and runtime fallback currently
include a trailing slash, which causes the serialized origin to mismatch browser
Origin headers. Update the documented default and any fallback value used by the
CORS check in the Gemini estimation endpoint so it uses the bare origin string
without the trailing slash, and keep the logic in the endpoint’s origin
comparison aligned with that value.
In `@api/estimate.ts`:
- Line 125: The CORS origin being set in estimate.ts uses a value with a
trailing slash, which can prevent exact Origin matching in browsers. Update the
Access-Control-Allow-Origin handling in the estimate response path to use the
origin without the trailing slash, or normalize ALLOWED_ORIGIN before passing it
to res.setHeader so it always matches the browser Origin exactly. Also update
the default/example value referenced by ALLOWED_ORIGIN to the slashless form so
the configuration stays consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0c24147b-3ef2-4f71-9636-aa959871ef78
📒 Files selected for processing (2)
.env.exampleapi/estimate.ts
…emini-cors-origin
…in has no slash Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
What changed
Replaced the wildcard
Access-Control-Allow-Origin: *header in theGemini estimation endpoint with the project's Firebase Hosting domain,
so no external site can call the endpoint and drain the API quota.
Falls back to
https://servio-0.web.app/ifALLOWED_ORIGINis notset. Documented in
.env.example.Action required after merge
Add
ALLOWED_ORIGIN=https://servio-0.web.app/inVercel → Project → Settings → Environment Variables.
Files changed
api/estimate.ts— 1 line changed.env.example—ALLOWED_ORIGINdocumentedcloses CORS wildcard on /api/estimate — api/estimate.ts:126 #207
Summary by CodeRabbit
Bug Fixes
Documentation
ALLOWED_ORIGINvariable (with guidance) for controlling which domain can access the endpoint.