Skip to content

fix: secure CORS configuration by reading from environment - #45

Merged
aadityat23 merged 1 commit into
FinVerify:mainfrom
bheemrzz07-bit:fix-cors-misconfiguration
Jul 24, 2026
Merged

fix: secure CORS configuration by reading from environment#45
aadityat23 merged 1 commit into
FinVerify:mainfrom
bheemrzz07-bit:fix-cors-misconfiguration

Conversation

@bheemrzz07-bit

Copy link
Copy Markdown

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.

  • Replaced allow_origins=["*"] with an explicit, environment-driven allowlist.
  • Added a robust parsing step to fetch the CORS_ORIGINS environment variable, split it by commas, and strip any accidental whitespace.
  • This ensures that credentialed cross-origin requests are strictly limited to the explicit URLs defined in the .env file, effectively closing the security gap.
  • Maintained the custom "X-FinVerify-Key" in the allow_headers list so existing functionality does not break.

How I Tested It:

  • Verified the Python parsing logic (os.getenv("CORS_ORIGINS", "")) to ensure it safely falls back to an empty string if the variable is entirely missing, preventing server crashes.
  • Verified that the list comprehension correctly strips empty spaces and ignores trailing commas, ensuring a clean and strict Python list is passed to the CORSMiddleware.

Thank you for assigning me this first issue! Let me know if any further adjustments are needed.

@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

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.

@aadityat23 aadityat23 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@bheemrzz07-bit

Copy link
Copy Markdown
Author

Thanks for the review, @aadityat23! I appreciate the feedback.

To answer your two points:

1. .env.example Confirmation
I just checked the finverify-terminal/backend/.env.example file, and I can confirm it already contains the correct CORS_ORIGINS entry (with the localhost and Vercel domains), so no further updates were needed there.

2. Manual curl Test Demonstration
Here is the demonstration showing that a non-allowlisted Origin is successfully blocked and does not receive the Access-Control-Allow-Origin header:

Pre-flight Request from an invalid Origin (http://evil-hacker.com):

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 aadityat23 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@aadityat23
aadityat23 merged commit b92c009 into FinVerify:main Jul 24, 2026
1 of 2 checks passed
@aadityat23

Copy link
Copy Markdown
Member

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!

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