Skip to content
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

Fix/108 fix cors issues #109

Merged
merged 2 commits into from
Dec 15, 2024
Merged

Fix/108 fix cors issues #109

merged 2 commits into from
Dec 15, 2024

Conversation

longwind48
Copy link
Collaborator

Standardize CORS Configuration Across Backend Functions

Changes Made

  • Created centralized CORS configuration in utils/cors_config.py
  • Implemented strict origin validation for security
  • Updated all Firebase Functions to use standardized CORS handling:
    • chat_message
    • schemes
    • schemes_search
    • feedback
    • update_scheme

Key Features

  • Explicitly allowed origins:
    • http://localhost:3000 (development)
    • https://schemessg-v3-dev.web.app (staging)
  • Proper handling of CORS preflight (OPTIONS) requests
  • Consistent CORS headers across all endpoints
  • Origin validation for improved security

Technical Details

  • Added get_cors_headers() utility function that validates request origins
  • Added handle_cors_preflight() for standardized OPTIONS request handling
  • Removed duplicated CORS configurations from individual function files
  • Maintained all existing business logic while improving CORS implementation

Testing

  • Local development works (http://localhost:3000)
  • Staging environment works (https://schemessg-v3-dev.web.app)
  • Unauthorized origins are properly rejected
  • OPTIONS requests are handled correctly
  • All endpoints maintain their original functionality

Security

  • Removes wildcard (*) CORS configuration
  • Implements explicit origin validation
  • Maintains secure headers for all responses

Related Issues

Closes #[issue_number] - Standardize CORS handling across backend

@longwind48 longwind48 self-assigned this Dec 15, 2024
@longwind48 longwind48 linked an issue Dec 15, 2024 that may be closed by this pull request
@longwind48 longwind48 merged commit 8ff083b into stg Dec 15, 2024
@longwind48 longwind48 deleted the fix/108-fix-cors-issues branch December 15, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix CORS issues coming from backend
1 participant