Skip to content

🛡️ Sentinel: [security improvement] Move staff verification to backend#33

Open
LVT-ENG wants to merge 1 commit intomainfrom
sentinel-staff-verification-8621098706126432433
Open

🛡️ Sentinel: [security improvement] Move staff verification to backend#33
LVT-ENG wants to merge 1 commit intomainfrom
sentinel-staff-verification-8621098706126432433

Conversation

@LVT-ENG
Copy link
Copy Markdown
Member

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

🚨 Severity: MEDIUM (Security Enhancement)

💡 Vulnerability:
The staff access password was hardcoded directly in the frontend JavaScript (js/main.js), making it trivial for anyone to discover by inspecting the source code.

🎯 Impact:
Unauthorized users could easily obtain the staff credential and potentially access restricted administrative areas or dashboards.

🔧 Fix:

  • Backend: Added a new POST /api/verify-staff endpoint in backend/main.py. It retrieves the expected password from the STAFF_PASSWORD environment variable and performs a secure comparison using hmac.compare_digest to mitigate timing attacks.
  • Models: Defined a StaffLogin Pydantic model in backend/models.py.
  • Frontend: Refactored verifyPrivatePass in js/main.js to send an asynchronous request to the new backend endpoint, removing the hardcoded secret.
  • Config: Added a vite.config.js to proxy /api requests to the FastAPI backend during development.
  • Documentation: Updated .env.example with the new STAFF_PASSWORD variable.

Verification:

  • Backend Tests: Created backend/tests/test_staff.py with 100% coverage for success and failure scenarios.
  • Frontend Verification: Used Playwright to visually confirm that the "ACCESO CONCEDIDO" and "ACCESO DENEGADO" notifications appear correctly based on backend responses.
  • Linting: Verified that the changes do not introduce new ESLint errors.

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

- Remove hardcoded password from js/main.js
- Implement /api/verify-staff endpoint in backend/main.py
- Use hmac.compare_digest to prevent timing attacks
- Add StaffLogin model to backend/models.py
- Update .env.example with STAFF_PASSWORD
- Add vite.config.js with proxy for local development
- Add backend/tests/test_staff.py for verification

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 25, 2026

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

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

@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 security of staff access by migrating the password verification logic from the frontend to the backend. This change eliminates the risk of exposing sensitive credentials in client-side code, making it much harder for unauthorized users to gain access to restricted areas. The new backend endpoint securely handles verification, improving the overall robustness of the application's access control.

Highlights

  • Security Enhancement: Moved the hardcoded staff access password from frontend JavaScript to a backend environment variable, significantly improving security by preventing credential exposure.
  • Backend API: Implemented a new POST /api/verify-staff endpoint in FastAPI for secure password verification, utilizing hmac.compare_digest to mitigate timing attacks.
  • Frontend Refactor: Updated js/main.js to asynchronously call the new backend endpoint for staff verification, removing the client-side hardcoded secret.
  • Development Configuration: Added vite.config.js to proxy /api requests to the backend during development, streamlining the local development workflow.
  • Testing: Introduced new backend tests (backend/tests/test_staff.py) for the staff verification endpoint, ensuring its reliability and correctness across various scenarios.
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 introduces a new staff verification system. It involves adding a STAFF_PASSWORD environment variable, defining a StaffLogin model, and implementing a POST /api/verify-staff endpoint in the backend for secure password comparison using hmac.compare_digest. The frontend js/main.js has been updated to use this new backend endpoint for authentication, replacing a hardcoded password check. Unit tests for the new endpoint and Vite proxy configuration are also included. A security vulnerability was identified where an empty STAFF_PASSWORD environment variable could lead to unauthorized access; it is recommended to ensure the password is not empty before comparison and add a corresponding test case.

Comment on lines +56 to +59
if hmac.compare_digest(login.password, STAFF_PASSWORD):
return {"status": "SUCCESS", "message": "Access granted"}
else:
raise HTTPException(status_code=401, detail="Access denied")
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

There's a potential security vulnerability here if the STAFF_PASSWORD environment variable is set to an empty string. In that case, if an attacker sends a request with an empty password, hmac.compare_digest('', '') would return True, granting them unauthorized access.

To mitigate this, you should ensure that an empty password is never considered valid by checking that STAFF_PASSWORD is not an empty string before performing the comparison.

For more robust testing, you could also add a test case where STAFF_PASSWORD is monkey-patched to an empty string to verify that access is denied for any provided password.

Suggested change
if hmac.compare_digest(login.password, STAFF_PASSWORD):
return {"status": "SUCCESS", "message": "Access granted"}
else:
raise HTTPException(status_code=401, detail="Access denied")
if STAFF_PASSWORD and hmac.compare_digest(login.password, STAFF_PASSWORD):
return {"status": "SUCCESS", "message": "Access granted"}
else:
raise HTTPException(status_code=401, detail="Access denied")

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