-
Notifications
You must be signed in to change notification settings - Fork 29
Hardcoded Flask Secret Key & CORS Origins (SECURITY) #47
Description
Security: Hardcoded Flask Secret Key and CORS Origins
Description
The Flask application has security credentials and environment-specific settings hardcoded into the code:
- SECRET_KEY- is hardcoded to
'12345'(trivially guessable) - CORS origins-are hardcoded to
http://127.0.0.1orhttps://osemosys.herokuapp.com/ - Deployment mode-is controlled by a hardcoded
HEROKU_DEPLOYflag (also used in the frontend)
This pattern makes it difficult to securely deploy the application across different environments.
Why This Matters
Critical security risk : A hardcoded SECRET_KEY compromises session security, CSRF tokens, and JWT signatures
Inflexible deployments : Cannot easily move from dev → staging → production without modifying code
Version control leak : Sensitive values are committed to git history
Violates 12-factor app principles : Configuration should come from the environment, not the codebase
Locations
File: API/app.py
Line 45 : SECRET_KEY
Lines 59–64 : CORS configuration
Current Code (Vulnerable)
Line 45 - HARDCODED SECRET:
app.config['SECRET_KEY'] = '12345'
Lines 59–64 - HARDCODED CORS:
if Config.HEROKU_DEPLOY == 1:
CORS(app, origins=['https://osemosys.herokuapp.com/'])
else:
CORS(app, origins=['http://127.0.0.1:3000', 'http://127.0.0.1:8080'])File 2 : API/Classes/Base/Config.py
Lines : 42–43
Hardcoded flags (should come from environment):
HEROKU_DEPLOY = 0
AWS_SYNC = 0File 3 : Base.Class.js
Lines : 6–7, 12–19 (Frontend mirrors backend hardcoding)
static HEROKU = 0;
static AWS_SYNC = 0;
if (this.HEROKU == 0) {
apiUrl = "http://127.0.0.1:5002/"; // Hardcoded
} else {
apiUrl = "https://osemosys.herokuapp.com/"; // Hardcoded
}Expected Behavior
- SECRET_KEY should be loaded from environment variable
- CORS origins should be configurable via environment (comma-separated list)
- Deployment mode should be determined by environment, not code flag
- Code should work identically in dev, staging, and production without modification
Acceptance Criteria
- Load
SECRET_KEYfrom environment variableFLASK_SECRET_KEY(fallback to secure random if missing) - Load
CORS_ORIGINSfrom environment variable (e.g.,"http://localhost:3000,https://prod.example.com") - Load
ENVIRONMENTfrom environment variable (dev/staging/prod) instead of hardcoded flag - Update Config.py to read from environment
- Update Base.Class.js to load API URL from a runtime config file or environment
- Document required environment variables in README
- Test that app works with different environment configurations