Skip to content

fix: implement CORS security to prevent unauthorized cross-origin requests #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 15, 2025

Conversation

yangm2
Copy link
Contributor

@yangm2 yangm2 commented Aug 7, 2025

Summary

  • Implement strict CORS policy with origin allowlist
  • Add Flask-CORS dependency for proper CORS handling
  • Reject unauthorized cross-origin requests at server level

Security Fix

This PR addresses the CORS misconfiguration reported in issue #94 by implementing proper server-side origin validation:

  • Added Flask-CORS dependency to handle CORS properly
  • Configured strict origin allowlist for tenantfirstaid.com domains
  • Added development localhost origins when ENV

@yangm2 yangm2 requested review from apkostka and leekahung August 7, 2025 19:53
@yangm2 yangm2 self-assigned this Aug 7, 2025
@yangm2 yangm2 added bug Something isn't working backend Bot implementation and other backend concerns labels Aug 7, 2025
@yangm2
Copy link
Contributor Author

yangm2 commented Aug 7, 2025

@claude fix failing check

Copy link
Contributor

claude bot commented Aug 7, 2025

Claude finished @yangm2's task —— View job


Fixed Failing Check ✅

Completed Tasks:

  • Read repository setup instructions (CLAUDE.md) - No repo-specific CLAUDE.md found
  • Examine the failing check details - Analyzed PR check workflow
  • Review the changed files in this PR - Reviewed CORS security implementation
  • Identify the root cause of the failure - Import order issue in app.py
  • Implement the fix - Corrected import order to comply with Python standards
  • Test the changes locally - Unable to run full tests without Bash permissions
  • Commit and push the fix - Pushed fix to branch

Summary:

Fixed the failing check by correcting the import order in backend/tenantfirstaid/app.py. The issue was that imports weren't following standard Python conventions:

Before:

from pathlib import Path
from flask import Flask, jsonify, session
from flask_cors import CORS
import os
import secrets

After:

import os
import secrets
from pathlib import Path

from flask import Flask, jsonify, session
from flask_cors import CORS

The fix follows Python import standards:

  1. Standard library imports first (os, secrets, pathlib)
  2. Third-party imports second (flask, flask_cors)
  3. Proper spacing between import groups

The CORS security implementation remains intact with all its security features:

  • Strict origin validation for production domains
  • Development localhost origins when ENV=dev
  • Proper credential support configuration

@yangm2 yangm2 marked this pull request as ready for review August 13, 2025 18:30
claude bot and others added 2 commits August 15, 2025 20:38
…uests

- Add Flask-CORS dependency to pyproject.toml
- Configure strict origin allowlist for tenantfirstaid.com domains
- Add development localhost origins when ENV=dev
- Enable credentials support for session handling
- Reject requests from unauthorized origins at server level

Fixes #94

Co-authored-by: yangm2 <[email protected]>
@yangm2 yangm2 force-pushed the claude/issue-94-20250807-1947 branch from a5d4c15 to 2380c28 Compare August 15, 2025 20:49
@yangm2 yangm2 merged commit 9d561b1 into main Aug 15, 2025
2 checks passed
@yangm2 yangm2 deleted the claude/issue-94-20250807-1947 branch August 15, 2025 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Bot implementation and other backend concerns bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants