fix: secure CORS configuration by reading from environment - #45
Conversation
|
Someone is attempting to deploy a commit to the aadi's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Thanks for the contribution @bheemrzz07-bit ! The implementation looks good, and the backend tests passed. Before I can merge this, could you please complete the remaining acceptance criteria?
-
Add either a manual curl test (or a regression test) demonstrating that a non-allowlisted Origin does not receive the Access-Control-Allow-Origin header.
-
Confirm whether .env.example already contains the correct CORS_ORIGINS entry. If not, please update it as described in the issue.
Once those are addressed, I'll be happy to review and merge it. Great work so far, and thanks again for your first contribution to FinVerify!
|
Thanks for the review, @aadityat23! I appreciate the feedback. To answer your two points: 1. .env.example Confirmation 2. Manual curl Test Demonstration Pre-flight Request from an invalid Origin ( curl -I -X OPTIONS http://localhost:8000/health \
-H "Origin: [http://evil-hacker.com](http://evil-hacker.com)" \
-H "Access-Control-Request-Method: GET" |
aadityat23
left a comment
There was a problem hiding this comment.
Thanks for the quick updates and for addressing the review comments. I verified the changes, and the security improvement looks good. The backend tests are passing, and the Vercel authorization check appears unrelated to the implementation itself. I'll go ahead and merge this. Thanks again for your contribution!
|
Merged! Thanks for the contribution and for being responsive during the review @bheemrzz07-bit . Looking forward to seeing more contributions to FinVerify in the future! |
Fixes the open issue regarding the wildcard CORS misconfiguration.
Summary of Changes:
As requested, I have removed the unsafe wildcard CORS configuration that was paired with
allow_credentials=True.allow_origins=["*"]with an explicit, environment-driven allowlist.CORS_ORIGINSenvironment variable, split it by commas, and strip any accidental whitespace..envfile, effectively closing the security gap."X-FinVerify-Key"in theallow_headerslist so existing functionality does not break.How I Tested It:
os.getenv("CORS_ORIGINS", "")) to ensure it safely falls back to an empty string if the variable is entirely missing, preventing server crashes.CORSMiddleware.Thank you for assigning me this first issue! Let me know if any further adjustments are needed.