fix(cors): replace wildcard origin with environment-based whitelist and secure localhost fallback#315
Open
V1ctor-o wants to merge 2 commits into
Open
Conversation
…back for testing - Remove wildcard-like behavior that allowed any origin via dashboardUrl fallback - Prioritize FRONTEND_URL as primary allowed origin - Support DASHBOARD_URL as secondary origin if configured differently - Explicitly allow localhost only for non-production environments (NODE_ENV !== 'production') - Add clear error messages indicating which origins are allowed - Maintain backward compatibility by continuing to allow no-origin requests (same-origin) - Follow existing code style with inline helper functions Fixes: CORS policy enforcement for financial contract configuration security
…back for testing Changes: - Remove redundant cors() middleware from index.ts that allowed all origins by default - Implement explicit CORS origin whitelist in app.ts (FRONTEND_URL and DASHBOARD_URL) - Add production environment validation requiring explicit FRONTEND_URL configuration - Allow localhost only for non-production environments (NODE_ENV !== 'production') - Provide clear error messages indicating allowed origins and testing exceptions - Maintain backward compatibility for same-origin requests (no origin header) - Clean up unused imports and validation code in index.ts Security improvements: - Eliminates wildcard CORS policy that exposed financial contract configurations - Enforces strict origin validation for production deployments - Enables safe localhost access for staging and testing environments - Provides audit trail via descriptive error messages Follows existing code style and maintains all existing functionality.
|
@V1ctor-o Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR removes the insecure wildcard CORS configuration and replaces it with a strict, environment-driven whitelist system to improve backend security for financial contract operations.
Changes Made
Security Fixes
origin: "*") from the backendFRONTEND_URLandDASHBOARD_URLEnvironment-Aware Behavior
FRONTEND_URLandDASHBOARD_URLlocalhost,127.0.0.1)Code Improvements
src/index.tssrc/app.tsSecurity Improvements
Files Changed
src/app.ts— updated CORS configuration and origin validationsrc/index.ts— removed insecure/default CORS middlewareTesting Performed
Notes
This change strengthens the backend security posture by enforcing strict origin control and eliminating unsafe default CORS behavior.
Closes #295