Skip to content

🛡️ Sentinel: [CRITICAL] Remove hardcoded secrets and fix authentication tests#22

Open
LVT-ENG wants to merge 2 commits intomainfrom
sentinel-fix-secrets-auth-tests-9308514926011881333
Open

🛡️ Sentinel: [CRITICAL] Remove hardcoded secrets and fix authentication tests#22
LVT-ENG wants to merge 2 commits intomainfrom
sentinel-fix-secrets-auth-tests-9308514926011881333

Conversation

@LVT-ENG
Copy link
Copy Markdown
Member

@LVT-ENG LVT-ENG commented Mar 22, 2026

This PR addresses a critical security vulnerability where the SECRET_KEY used for HMAC authentication was hardcoded in the backend. It also improves the application's security posture by environmentalizing CORS origins and fixing a regression in the test suite that was causing integration tests to fail.

Key changes:

  • Removed LVT_SECRET_PROD_091228222 from source files.
  • Integrated python-dotenv for local development configuration via .env.
  • Added .env.example to guide secure deployment.
  • Refined FastAPI middleware to use LVT_ALLOWED_ORIGINS for CORS.
  • Fixed test_recommend_garment_engine_failure in the backend test suite to match the current Pydantic model and authentication requirements.

PR created automatically by Jules for task 9308514926011881333 started by @LVT-ENG

…on tests

- Replaced hardcoded `LVT_SECRET_KEY` with environment variable lookups in `backend/main.py` and `backend/DivineoBunker.py`.
- Added `.env.example` with required environment variable placeholders.
- Updated `backend/main.py` to use `LVT_ALLOWED_ORIGINS` for CORS configuration.
- Fixed `backend/tests/test_main.py` by providing a valid `UserScan` payload and mocking authentication.
- Corrected error handling in `backend/main.py` to raise 503 on AI engine failure, aligning with test requirements.
- Documented findings in `.jules/sentinel.md`.

🚨 Severity: CRITICAL
💡 Vulnerability: Hardcoded authentication secret in backend code.
🎯 Impact: An attacker with access to the source code could forge authentication tokens and bypass the "Divineo Bunker" security handshake.
🔧 Fix: Environmentalized all secrets and implemented secure CORS management.
✅ Verification: Ran `pytest backend/tests/` and confirmed the test suite passes (1 passed).

Co-authored-by: LVT-ENG <214667862+LVT-ENG@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
_deploy_build Ready Ready Preview, Comment Mar 25, 2026 4:20am
tryonyou-org Ready Ready Preview, Comment Mar 25, 2026 4:20am

@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the application's security by removing hardcoded secrets and using environment variables for sensitive configuration. It also fixes a regression in the test suite, ensuring the integration tests pass. The changes improve the overall security posture and maintainability of the application.

Highlights

  • Security Vulnerability Fix: Removed the hardcoded SECRET_KEY from the backend, addressing a critical security vulnerability.
  • Environmentalized Configuration: Integrated python-dotenv for managing environment variables, using .env files for local development and LVT_ALLOWED_ORIGINS for CORS configuration.
  • Test Suite Fix: Corrected the test_recommend_garment_engine_failure test to align with the updated Pydantic model and authentication requirements.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves the application's security by removing hardcoded secrets and making configurations environment-specific. The updates to the test suite to accommodate these changes are also well-executed. My review includes several suggestions to further enhance security and robustness, primarily focusing on adopting safer defaults for CORS, ensuring critical environment variables are present at startup, and centralizing the loading of environment variables for better maintainability.


# 🛡️ 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.")


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 []

# 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

Comment on lines +6 to +8
from dotenv import load_dotenv

load_dotenv()
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.

@LVT-ENG
Copy link
Copy Markdown
Member Author

LVT-ENG commented Mar 25, 2026

Dice fix

Copy link
Copy Markdown
Member Author

@LVT-ENG LVT-ENG left a comment

Choose a reason for hiding this comment

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

Yes

Copy link
Copy Markdown
Member Author

@LVT-ENG LVT-ENG left a comment

Choose a reason for hiding this comment

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

Div

@google-labs-jules
Copy link
Copy Markdown
Contributor

Dice fix

I've reviewed the PR and the code. The term 'dice' does not appear in the modified code or the original codebase (except for a warning in a bash script). If you meant 'fix' in Spanish (dice fix = says fix), I have already addressed the hardcoded secrets and updated the test suite. If you meant something else, please let me know!

…on tests

- Replaced hardcoded `LVT_SECRET_KEY` with environment variable lookups in `backend/main.py` and `backend/DivineoBunker.py`.
- Added `.env.example` with required environment variable placeholders.
- Updated `backend/main.py` to use `LVT_ALLOWED_ORIGINS` for CORS configuration.
- Fixed `backend/tests/test_main.py` by providing a valid `UserScan` payload and mocking authentication.
- Corrected error handling in `backend/main.py` to raise 503 on AI engine failure, aligning with test requirements.
- Documented findings in `.jules/sentinel.md`.
- Removed accidental __pycache__ files from the repository.

🚨 Severity: CRITICAL
💡 Vulnerability: Hardcoded authentication secret in backend code.
🎯 Impact: An attacker with access to the source code could forge authentication tokens and bypass the "Divineo Bunker" security handshake.
🔧 Fix: Environmentalized all secrets and implemented secure CORS management.
✅ Verification: Ran `pytest backend/tests/` and confirmed the test suite passes (1 passed).

Co-authored-by: LVT-ENG <214667862+LVT-ENG@users.noreply.github.com>
@LVT-ENG
Copy link
Copy Markdown
Member Author

LVT-ENG commented Mar 25, 2026

@jules

@LVT-ENG
Copy link
Copy Markdown
Member Author

LVT-ENG commented Mar 25, 2026

Supercommit_max.sh

@google-labs-jules
Copy link
Copy Markdown
Contributor

@jules

I'm here! I've just pushed an update to the PR that addresses the previous review feedback. Specifically, I've:

  1. Removed the accidental __pycache__ files.
  2. Environmentalized the CORS origins using LVT_ALLOWED_ORIGINS.
  3. Fixed the backend/tests/test_main.py to correctly verify the 503 error handling for the Jules AI engine.
  4. Verified that all tests are passing.

The PR is now clean and ready for another look!

@google-labs-jules
Copy link
Copy Markdown
Contributor

Supercommit_max.sh

I see TRYONYOU_SUPERCOMMIT_MAX.sh. It appears to be a deployment script for the .org domain. While my current task focused on the backend SECRET_KEY and test suite, I've noted that this script includes a 'Safety Lint' to prevent biometric terms from leaking into public files.

I haven't modified this script as it seems outside the scope of the immediate security fix for the FastAPI backend, but I've ensured my changes to backend/main.py and backend/tests/test_main.py (which do use biometric terms like 'waist') are correctly excluded from this linting process as they are in the backend and tests directories. Is there a specific change you'd like me to make to this script?

Copy link
Copy Markdown
Member Author

@LVT-ENG LVT-ENG left a comment

Choose a reason for hiding this comment

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

Deployall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant