Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-FLASK-AUDIT-004 --project .About This Rule
Understanding the vulnerability and how it is detected
This rule detects Flask applications that initialize Flask-CORS with a wildcard origin (origins="*"). The Access-Control-Allow-Origin: * header instructs browsers to allow any web page -- on any domain, including attacker-controlled sites -- to make cross-origin requests to the application and read the responses.
The critical risk arises when wildcard CORS is combined with credentials (cookies, HTTP auth, or client-side certificates). While browsers prevent credentials from being sent with a pure wildcard response, the misconfiguration often evolves: developers add supports_credentials=True and then change origins="*" to origins="null" or reflect the Origin header, inadvertently creating a credentialed CORS bypass. Auditing wildcard CORS early prevents this class of vulnerability from appearing in the first place.
The detection uses FlaskCORS.method("CORS").where("origins", "*") -- a QueryType-based precise match. FlaskCORS declares fqns=["flask_cors"], so only objects imported from the flask_cors package are matched. The .where("origins", "*") filter means only calls where the origins keyword argument is exactly the string "*" are flagged. Calls with a specific domain list, a regex, or a variable are not flagged. This precision delivers zero false positives on correctly configured applications.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Cross-Origin Data Theft from Authenticated Users
With wildcard CORS, any malicious web page can make JavaScript fetch() calls to the application's API and read the JSON responses. If the user visiting the malicious page is already authenticated (via cookie or session), the request carries their credentials and the attacker's page can silently exfiltrate account data, private API responses, or internal state.
Cross-Site Request Forgery Amplification
Wildcard CORS allows attackers to use JavaScript XMLHttpRequest with full access to response bodies, not just fire-and-forget form submissions. This upgrades CSRF from blind state-changing attacks to data-reading attacks where the attacker can actually see what the server returns.
Credential-Based Bypass When supports_credentials Is Added Later
Applications often start with origins="*" and later add supports_credentials=True as authentication is added. At that point, browsers block the combination. Developers then change to reflecting the Origin header or using origins="null", both of which are exploitable. Fixing the wildcard origin early prevents this progression.
Internal API Exposure
Wildcard CORS on internal APIs (admin panels, management endpoints, metrics) allows any external website visited by a privileged user to make requests to those endpoints. Even if authentication is required, the attacker's page executes in the authenticated user's browser context.
How to Fix
Recommended remediation steps
- 1Replace origins="*" with an explicit list of trusted origins -- for example, ["https://app.example.com", "https://admin.example.com"].
- 2If you need to allow multiple environments (dev, staging, prod), maintain an allow-list per environment and inject it via configuration rather than hardcoding "*".
- 3Never combine origins="*" with supports_credentials=True -- browsers block this and developers tend to work around it in insecure ways.
- 4Restrict CORS to the minimum required HTTP methods (methods=["GET", "POST"]) rather than allowing all methods.
- 5Audit CORS configuration changes in code review as a security-sensitive change, similar to changes to authentication middleware.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule uses a QueryType-based precise match: FlaskCORS.method("CORS").where("origins", "*"). FlaskCORS declares fqns=["flask_cors"], restricting matches to objects imported from the flask_cors package. The .method("CORS") step targets the CORS() constructor call. The .where("origins", "*") step filters to calls where the origins keyword argument is exactly the string "*". Calls with a list of specific origins, a compiled regex, or a variable are not flagged. The rule operates at the call-site level without cross-file dataflow analysis.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
Flask Debug Mode Enabled
Detects Flask applications started with debug=True, which enables the interactive Werkzeug debugger and must never run in production.
Flask Bound to All Interfaces
Detects Flask applications binding the development server to 0.0.0.0, exposing it to every network interface instead of localhost only.
Flask Cookie Without Secure Flags
Detects set_cookie() calls with secure=False or httponly=False, which expose session and authentication cookies to theft via network eavesdropping or JavaScript access.
Frequently Asked Questions
Common questions about Flask CORS Wildcard Origin
New feature
Get these findings posted directly on your GitHub pull requests
The Flask CORS Wildcard Origin rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.