Skip to content

🛡️ Sentinel: [CRITICAL/HIGH] Fix hardcoded secrets and improve error handling#17

Open
LVT-ENG wants to merge 1 commit intomainfrom
sentinel-fix-secrets-and-errors-16200982156984144478
Open

🛡️ Sentinel: [CRITICAL/HIGH] Fix hardcoded secrets and improve error handling#17
LVT-ENG wants to merge 1 commit intomainfrom
sentinel-fix-secrets-and-errors-16200982156984144478

Conversation

@LVT-ENG
Copy link
Copy Markdown
Member

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

🚨 Severity: CRITICAL/HIGH

💡 Vulnerability:

  1. Hardcoded Secrets: The application had a production-like secret key (LVT_SECRET_PROD_091228222) hardcoded in backend/main.py and backend/DivineoBunker.py for HMAC authentication.
  2. Insecure Error Handling: When the AI styling engine failed, the system would fallback to a plain string response, potentially leaking internal state or providing inconsistent data to the frontend.

🎯 Impact:
Hardcoded secrets can be easily discovered by unauthorized parties, leading to full bypass of the "Divineo Bunker" security protocol. Inconsistent error handling deviates from "fail-secure" principles, making the application less resilient and potentially exposing internal logic.

🔧 Fix:

  • Migrated the SECRET_KEY to an environment variable (LVT_SECRET_KEY) using python-dotenv.
  • Added a DEVELOPMENT_SECRET_KEY_REPLACE_ME default for safe local development.
  • Refactored recommend_garment to return a structured 503 Service Unavailable JSON response if the AI engine fails, ensuring the frontend handles the error gracefully.
  • Updated the backend test suite to match the current UserScan biometric model and added a mock for the security handshake to facilitate unit testing of failure paths.
  • Hardened .gitignore to prevent leakage of environment files and compiled Python bytecode.

Verification:
Successfully ran backend tests: export PYTHONPATH=$PYTHONPATH:$(pwd)/backend && python3 -m pytest backend/tests/. All tests passed, confirming both the security fix and the improved error handling logic.


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

…handling

- Removed hardcoded SECRET_KEY from backend/main.py and backend/DivineoBunker.py.
- Implemented environment variable loading using python-dotenv.
- Added .env.example template for secure configuration.
- Improved AI engine failure handling in main.py to return a fail-secure 503 JSON response.
- Updated backend tests to align with UserScan model and mocked authentication.
- Updated .gitignore to exclude Python cache and runtime data.
- Initialized Sentinel security journal in .jules/sentinel.md.

Co-authored-by: LVT-ENG <214667862+LVT-ENG@users.noreply.github.com>
@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.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 20, 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 20, 2026 6:02am

@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 significantly enhances the application's security posture and resilience. It addresses critical vulnerabilities by removing hardcoded production secrets and implementing a robust environment variable system for sensitive data. Additionally, it improves the user experience and system stability by providing structured and consistent error responses when external services, such as the AI styling engine, encounter issues. These changes collectively make the application more secure, maintainable, and reliable.

Highlights

  • Security Vulnerability Fix: Migrated the SECRET_KEY from being hardcoded in backend/main.py and backend/DivineoBunker.py to an environment variable (LVT_SECRET_KEY) using python-dotenv, with a DEVELOPMENT_SECRET_KEY_REPLACE_ME default for local development.
  • Improved Error Handling: Refactored the recommend_garment function to return a structured 503 Service Unavailable JSON response when the AI engine fails, ensuring graceful error handling on the frontend.
  • Test Suite Enhancements: Updated the backend test suite to align with the current UserScan biometric model and added a mock for the security handshake to facilitate unit testing of failure paths.
  • Repository Hardening: Hardened .gitignore to prevent the accidental leakage of environment files and compiled Python bytecode.
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 effectively addresses a critical security vulnerability by removing hardcoded secrets and improves error handling by implementing a fail-secure response. My review focuses on further improving maintainability and observability. I've suggested centralizing configuration to avoid duplication and adding logging to the new error handling path to aid in debugging. I also found a minor issue with an outdated comment in a test file.

Comment on lines 75 to +84
except Exception as e:
styling_advice = f"Divineo confirmado con {item['name']}."
# 🛡️ Security: Fail-secure and return structured error for the frontend/tests
return JSONResponse(
status_code=503,
content={
"status": "error",
"code": 503,
"message": "Jules AI Engine is currently recalibrating or unavailable. Please try again."
}
)
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.

high

This except block correctly provides a fail-secure response, but it completely hides the underlying error from the AI engine. Without logging the exception, debugging any issues with the get_jules_advice function will be impossible. The exception should be logged before returning the error response.

Suggested change
except Exception as e:
styling_advice = f"Divineo confirmado con {item['name']}."
# 🛡️ Security: Fail-secure and return structured error for the frontend/tests
return JSONResponse(
status_code=503,
content={
"status": "error",
"code": 503,
"message": "Jules AI Engine is currently recalibrating or unavailable. Please try again."
}
)
except Exception:
import logging
logging.exception("Jules AI Engine failed")
# 🛡️ Security: Fail-secure and return structured error for the frontend/tests
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 +24 to +27
load_dotenv()

# 🛡️ Configuración Maestra (abvetos.com)
SECRET_KEY = "LVT_SECRET_PROD_091228222"
SECRET_KEY = os.getenv("LVT_SECRET_KEY", "DEVELOPMENT_SECRET_KEY_REPLACE_ME")
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

While moving the secret to an environment variable is a great improvement, the configuration loading logic (calling load_dotenv() and getting the LVT_SECRET_KEY) is duplicated in backend/DivineoBunker.py. This violates the DRY (Don't Repeat Yourself) principle and could lead to maintenance issues if, for example, the environment variable name needs to change in the future. Consider centralizing your application's configuration into a single module (e.g., backend/config.py) that loads environment variables and defines configuration constants. Other modules could then import from this central config module.

"height": 175.0,
"weight": 68.0,
"user_id": "TEST_USER",
"token": "0.TEST_TOKEN", # This will fail verify_auth due to timestamp, but get_jules_advice is called later
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

The comment on this line is now incorrect and misleading. verify_auth is mocked on line 18 to always return True, so it will not fail as the comment suggests. This comment should be removed to avoid confusion for future developers maintaining this test.

Suggested change
"token": "0.TEST_TOKEN", # This will fail verify_auth due to timestamp, but get_jules_advice is called later
"token": "0.TEST_TOKEN",

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