Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Divineo Bunker Environment Variables
LVT_SECRET_KEY=your_secret_key_here
GEMINI_API_KEY=your_gemini_api_key_here
LVT_ALLOWED_ORIGINS=*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

Using * for LVT_ALLOWED_ORIGINS is overly permissive, even in an example file, as it encourages insecure configurations during development. It's better to provide a more realistic and secure example that developers can adapt, such as specifying local development origins.

LVT_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000

4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2025-03-05 - Hardcoded Secrets in Authentication Handshake
**Vulnerability:** Critical authentication secrets were hardcoded in multiple backend files (`main.py`, `DivineoBunker.py`), exposing the system to credential theft if the source code were compromised.
**Learning:** Hardcoding secrets often occurs during "rapid prototyping" phases and persists into production if not audited. Centralized environment variable management is essential for multi-component systems.
**Prevention:** Use `python-dotenv` and `os.getenv` for all sensitive keys. Implement mandatory pre-commit hooks or CI scans to detect plaintext secrets (e.g., `git-secrets`).
6 changes: 5 additions & 1 deletion backend/DivineoBunker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
import hashlib
import time
import json
import os
from dotenv import load_dotenv

load_dotenv()
Comment on lines +6 to +8
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling load_dotenv() within a library or class module can lead to unexpected side effects and makes it harder to control the application's configuration. Environment loading should be handled once at the application's entry point (e.g., in main.py, where it is already being called) to ensure a single source of truth for configuration.


class DivineoBunker:
def __init__(self):
# 🛡️ Configuración Maestra (abvetos.com)
self.secret_key = "LVT_SECRET_PROD_091228222"
self.secret_key = os.getenv("LVT_SECRET_KEY")
self.patent = "PCT/EP2025/067317"
self.algorithm_v = "V10_Divineo_Shopify_Final"

Expand Down
Binary file added backend/__pycache__/jules_engine.cpython-312.pyc
Binary file not shown.
Binary file added backend/__pycache__/main.cpython-312.pyc
Binary file not shown.
Binary file added backend/__pycache__/models.cpython-312.pyc
Binary file not shown.
19 changes: 16 additions & 3 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@
import hashlib
import time
import json
import os
from dotenv import load_dotenv
from fastapi import FastAPI, HTTPException

load_dotenv()
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from models import UserScan, SHOPIFY_INVENTORY
from jules_engine import get_jules_advice

app = FastAPI(title="Divineo Bunker Backend")

allowed_origins = os.getenv("LVT_ALLOWED_ORIGINS", "*").split(",")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

Defaulting to "*" for allow_origins is a security risk, as it allows any origin to make requests. A more secure approach is to default to an empty list, which denies all cross-origin requests unless LVT_ALLOWED_ORIGINS is explicitly configured. This follows the principle of 'fail-safe defaults'.

Suggested change
allowed_origins = os.getenv("LVT_ALLOWED_ORIGINS", "*").split(",")
allowed_origins_str = os.getenv("LVT_ALLOWED_ORIGINS")
allowed_origins = allowed_origins_str.split(",") if allowed_origins_str else []


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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The application relies on LVT_SECRET_KEY for a critical function (authentication). If this environment variable is not set, os.getenv() will return None, causing authentication to fail silently, which can be difficult to debug. The application should fail fast at startup if this critical configuration is missing.

Suggested change
SECRET_KEY = os.getenv("LVT_SECRET_KEY")
SECRET_KEY = os.getenv("LVT_SECRET_KEY")
if not SECRET_KEY:
raise RuntimeError("LVT_SECRET_KEY environment variable not set. The application cannot start without it.")

PATENT = "PCT/EP2025/067317"

def verify_auth(user_id: str, token: str) -> bool:
Expand Down Expand Up @@ -68,7 +74,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']}."
raise HTTPException(
status_code=503,
detail={
"status": "error",
"code": 503,
"message": "Jules AI Engine is currently recalibrating or unavailable. Please try again."
}
)

if is_divineo and item['stock'] > 0:
return {
Expand Down
Binary file not shown.
10 changes: 7 additions & 3 deletions backend/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ def mock_get_jules_advice(*args, **kwargs):

# 2. Prepare the request payload
payload = {
"height": 175.0,
"weight": 68.0,
"user_id": "test_user",
"token": "1741164800.mock_sig",
"waist": 70.0,
"event_type": "Gala"
}

# 3. Send the POST request to the endpoint
# We need to mock verify_auth to return True as we changed SECRET_KEY to env var
monkeypatch.setattr("backend.main.verify_auth", lambda u, t: True)

response = client.post("/api/recommend", json=payload)

# 4. Assertions
assert response.status_code == 503

data = response.json()
assert data == {
assert data["detail"] == {
"status": "error",
"code": 503,
"message": "Jules AI Engine is currently recalibrating or unavailable. Please try again."
Expand Down