Unsanitized user input in Access-Control-Allow-Origin
- Rule ID: python_lang_insecure_allow_origin
- Languages: python
- Source: insecure_allow_origin.yml
Description
Using unverified user-defined input to set the Access-Control-Allow-Origin header can result in unauthorized access to sensitive data. This vulnerability exposes your application to potential security risks by allowing attackers to specify origins that can access resources.
Remediations
- Do not use user input to define the
Access-Control-Allow-Origin
header without validation. This practice can inadvertently grant access to sensitive information.self.send_header('Access-Control-Allow-Origin', external_input) # unsafe
- Do validate user input if it must be used to set the
Access-Control-Allow-Origin
header. Ensure that only trusted origins are allowed by implementing a safelist of approved origins.allowed_origins = ['http://www.example.com', 'https://www.secure.example.com']
user_origin = input("Enter origin: ")
if user_origin in allowed_origins:
self.send_header('Access-Control-Allow-Origin', user_origin)
References
Associated CWE
OWASP Top 10
Configuration
To skip this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --skip-rule=python_lang_insecure_allow_origin
To run only this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --only-rule=python_lang_insecure_allow_origin