-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [CRITICAL/HIGH] Fix hardcoded secrets and improve CORS policy #19
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ## 2025-05-15 - [Securing HMAC Secrets and CORS] | ||
| **Vulnerability:** Hardcoded HMAC secret key and overly permissive CORS policy. | ||
| **Learning:** Hardcoding production-level secrets in multiple files (`main.py` and `DivineoBunker.py`) creates a high risk of exposure. Permissive CORS (`"*"`) is acceptable for rapid prototyping but should be configurable for deployment to prevent unauthorized cross-origin access. | ||
| **Prevention:** Use environment variables (via `os.getenv` and `python-dotenv`) for all sensitive credentials. Implement configurable CORS origins through environment variables, defaulting to specific origins in production. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,24 +2,31 @@ | |||||||||||||||||||||||||||||||||||||||||
| import hashlib | ||||||||||||||||||||||||||||||||||||||||||
| import time | ||||||||||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||
| from dotenv import load_dotenv | ||||||||||||||||||||||||||||||||||||||||||
| from fastapi import FastAPI, HTTPException | ||||||||||||||||||||||||||||||||||||||||||
| from fastapi.responses import JSONResponse | ||||||||||||||||||||||||||||||||||||||||||
| from fastapi.middleware.cors import CORSMiddleware | ||||||||||||||||||||||||||||||||||||||||||
| from models import UserScan, SHOPIFY_INVENTORY | ||||||||||||||||||||||||||||||||||||||||||
| from jules_engine import get_jules_advice | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| load_dotenv() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| app = FastAPI(title="Divineo Bunker Backend") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # π Security: In production, configure LVT_ALLOWED_ORIGINS in .env | ||||||||||||||||||||||||||||||||||||||||||
| ALLOWED_ORIGINS = os.getenv("LVT_ALLOWED_ORIGINS", "*").split(",") | ||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using an environment variable for CORS origins is a great security improvement. However, defaulting to
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| app.add_middleware( | ||||||||||||||||||||||||||||||||||||||||||
| CORSMiddleware, | ||||||||||||||||||||||||||||||||||||||||||
| allow_origins=["*"], | ||||||||||||||||||||||||||||||||||||||||||
| allow_origins=ALLOWED_ORIGINS, | ||||||||||||||||||||||||||||||||||||||||||
| allow_credentials=True, | ||||||||||||||||||||||||||||||||||||||||||
| allow_methods=["*"], | ||||||||||||||||||||||||||||||||||||||||||
| allow_headers=["*"], | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # π‘οΈ ConfiguraciΓ³n Maestra (abvetos.com) | ||||||||||||||||||||||||||||||||||||||||||
| SECRET_KEY = "LVT_SECRET_PROD_091228222" | ||||||||||||||||||||||||||||||||||||||||||
| SECRET_KEY = os.getenv("LVT_SECRET_KEY", "LVT_DEV_SECRET_DO_NOT_USE_IN_PROD") | ||||||||||||||||||||||||||||||||||||||||||
| PATENT = "PCT/EP2025/067317" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def verify_auth(user_id: str, token: str) -> bool: | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -68,7 +75,14 @@ async def recommend_garment(scan: UserScan, garment_id: str = "BALMAIN_SS26_SLIM | |||||||||||||||||||||||||||||||||||||||||
| # Usamos Jules para el toque de estilo | ||||||||||||||||||||||||||||||||||||||||||
| styling_advice = get_jules_advice(scan, item) | ||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||
| styling_advice = f"Divineo confirmado con {item['name']}." | ||||||||||||||||||||||||||||||||||||||||||
| return JSONResponse( | ||||||||||||||||||||||||||||||||||||||||||
| status_code=503, | ||||||||||||||||||||||||||||||||||||||||||
| content={ | ||||||||||||||||||||||||||||||||||||||||||
| "status": "error", | ||||||||||||||||||||||||||||||||||||||||||
| "code": 503, | ||||||||||||||||||||||||||||||||||||||||||
| "message": "Jules AI Engine is currently recalibrating or unavailable. Please try again." | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
77
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if is_divineo and item['stock'] > 0: | ||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change correctly removes the hardcoded secret. However, this file
DivineoBunker.pyappears to contain a significant amount of duplicated logic and data that also exists inmain.pyandmodels.py. For instance:self.secret_keyis also defined inmain.py._verify_authmethod is nearly identical toverify_authinmain.py.self.shopify_inventoryduplicatesSHOPIFY_INVENTORYfrommodels.py._calculate_fitis a copy ofcalculate_fitfrommain.py.This duplication increases maintenance overhead and risk of inconsistencies. Consider refactoring to remove this duplicated code, possibly by removing this class if it's unused or consolidating the logic into a single place.