feat(api): authorized origins#221
Conversation
|
Warning Review limit reached
More reviews will be available in 42 minutes and 37 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR enforces stricter origin authorization for the BFF with HTTPS-only validation and leading-dot wildcard subdomain matching, documented in environment examples and tested across six configuration scenarios. A separate fix improves test isolation by properly cleaning environment variables in the Coingecko test suite. ChangesStrict Origin Authorization with Subdomain Matching
Test Environment Isolation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@apps/api/src/app/plugins/bffAuth.ts`:
- Around line 12-15: The parsing currently trims and filters AUTHORIZED_ORIGINS
into an array (the domains variable result) but doesn't fail when the env is
present yet yields no valid entries, which silently disables origin protection;
change the startup logic that produces the parsed origins array
(authorizedOrigins) to detect when process.env.AUTHORIZED_ORIGINS is set but
parsed array length === 0 and then fail-closed (throw an Error or exit) with a
clear message about malformed AUTHORIZED_ORIGINS instead of returning an empty
array, and also update the middleware conditional that currently skips auth when
authorizedOrigins is empty to assume a malformed configuration rather than
allowing requests (i.e., require successful parse or stop startup).
🪄 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
Run ID: e6df991b-a933-4cf6-970d-32d229ba3230
📒 Files selected for processing (4)
.env.exampleapps/api/src/app/plugins/bffAuth.spec.tsapps/api/src/app/plugins/bffAuth.tslibs/repositories/src/datasources/coingecko.test.ts
Summary
Harden authorized origins.
Addresses feedback from https://github.com/cowprotocol/infrastructure/pull/5701
Note: in order to preserve current behaviour of accepting subdomains, BFF configs need to be updated from:
"cow.fi, cowswap.vercel.app, cowswap-dev.vercel.app, explorer-dev.vercel.app, swap-dev-5u6.pages.dev, explorer-dev-dxz.pages.dev"
to
".cow.fi, .cowswap.vercel.app, .cowswap-dev.vercel.app, .explorer-dev.vercel.app, .swap-dev-5u6.pages.dev, .explorer-dev-dxz.pages.dev"
Testing
Unit tests
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests