Skip to content

🛡️ Sentinel: [HIGH] Secure staff verification and remove hardcoded password#36

Open
LVT-ENG wants to merge 1 commit intomainfrom
fix/secure-staff-verification-4052392736350921056
Open

🛡️ Sentinel: [HIGH] Secure staff verification and remove hardcoded password#36
LVT-ENG wants to merge 1 commit intomainfrom
fix/secure-staff-verification-4052392736350921056

Conversation

@LVT-ENG
Copy link
Copy Markdown
Member

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

🚨 Severity: HIGH
💡 Vulnerability: A staff password was hardcoded in the client-side JavaScript (js/main.js), making it trivial for anyone to discover.
🎯 Impact: Unauthorized access to staff-only functionality or dashboards.
🔧 Fix: Refactored the verification flow to use a secure backend endpoint. The password is now stored in an environment variable and compared using a timing-safe hmac.compare_digest call.
✅ Verification:

  • Added backend tests in backend/tests/test_staff.py (all passed).
  • Verified frontend interaction via Playwright, confirming successful communication with the backend through the Vite proxy.
  • Manual verification of notification states (Access Granted/Denied).

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

…ssword

- Move staff password verification to the backend.
- Implement `/api/verify-staff` endpoint in `backend/main.py`.
- Use `hmac.compare_digest` to prevent timing attacks.
- Retrieve staff password from `STAFF_PASSWORD` environment variable.
- Update `js/main.js` to call the backend verification endpoint.
- Add `StaffLogin` Pydantic model to `backend/models.py`.
- Add `vite.config.js` with API proxy for local development.
- Add integration tests for staff verification in `backend/tests/test_staff.py`.
- Remove hardcoded password 'SAC_MUSEUM_2026' from the client-side code.

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 26, 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 26, 2026 6:02am
tryonyou-org Ready Ready Preview, Comment Mar 26, 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 security posture of the application by addressing a critical vulnerability where a staff password was hardcoded on the client-side. The changes refactor the staff verification process to a secure backend endpoint, utilizing environment variables for sensitive data and timing-safe comparisons, thereby preventing unauthorized access and improving overall system integrity.

Highlights

  • Security Vulnerability Fix: Removed a hardcoded staff password from client-side JavaScript (js/main.js), addressing a critical security vulnerability.
  • Secure Backend Verification: Implemented a new /api/verify-staff endpoint in backend/main.py for secure staff authentication.
  • Timing-Safe Password Comparison: Utilized hmac.compare_digest for password comparison in the backend to prevent timing attacks.
  • Environment Variable for Password: Configured the staff password to be loaded from an environment variable (STAFF_PASSWORD) in backend/main.py.
  • Backend Test Coverage: Added new unit tests in backend/tests/test_staff.py to ensure the staff verification endpoint functions correctly.
  • Frontend Integration and Proxy: Updated js/main.js to communicate with the new backend verification endpoint and configured a Vite proxy in vite.config.js for API routing.
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 implements a new staff login verification system. It moves the staff password from a hardcoded frontend value to a backend environment variable, introduces a secure /api/verify-staff endpoint using hmac.compare_digest, and updates the frontend to use this new API. Corresponding backend tests have been added, and a Vite proxy configuration was included. The review suggests refactoring the test setup logic into a pytest fixture to reduce duplication and adding a missing assertion to the test_verify_staff_empty_password test for robustness.

Comment on lines +1 to +34
import pytest
from fastapi.testclient import TestClient
from backend.main import app
import os

client = TestClient(app)

def test_verify_staff_success(monkeypatch):
# Set a known staff password for testing
monkeypatch.setenv("STAFF_PASSWORD", "TEST_STAFF_PASS")
# Reload the app's STAFF_PASSWORD from env
import backend.main
monkeypatch.setattr(backend.main, "STAFF_PASSWORD", "TEST_STAFF_PASS")

response = client.post("/api/verify-staff", json={"password": "TEST_STAFF_PASS"})
assert response.status_code == 200
assert response.json()["status"] == "SUCCESS"

def test_verify_staff_failure(monkeypatch):
monkeypatch.setenv("STAFF_PASSWORD", "TEST_STAFF_PASS")
import backend.main
monkeypatch.setattr(backend.main, "STAFF_PASSWORD", "TEST_STAFF_PASS")

response = client.post("/api/verify-staff", json={"password": "WRONG_PASSWORD"})
assert response.status_code == 401
assert response.json()["detail"] == "Acceso denegado"

def test_verify_staff_empty_password(monkeypatch):
monkeypatch.setenv("STAFF_PASSWORD", "TEST_STAFF_PASS")
import backend.main
monkeypatch.setattr(backend.main, "STAFF_PASSWORD", "TEST_STAFF_PASS")

response = client.post("/api/verify-staff", json={"password": ""})
assert response.status_code == 401
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 test setup logic is repeated across all test functions. This can be refactored into a single pytest fixture with autouse=True to reduce code duplication and improve maintainability.

Additionally, test_verify_staff_empty_password is missing an assertion to verify the response body. I've added it to make the test more robust and consistent with the other failure case.

import pytest
from fastapi.testclient import TestClient
from backend.main import app
import os

client = TestClient(app)

@pytest.fixture(autouse=True)
def mock_staff_password(monkeypatch):
    """Mocks the staff password for the duration of the tests."""
    test_password = "TEST_STAFF_PASS"
    monkeypatch.setenv("STAFF_PASSWORD", test_password)
    # Since the env var is read at module load, we also need to patch the variable in the imported module.
    import backend.main
    monkeypatch.setattr(backend.main, "STAFF_PASSWORD", test_password)

def test_verify_staff_success():
    response = client.post("/api/verify-staff", json={"password": "TEST_STAFF_PASS"})
    assert response.status_code == 200
    assert response.json()["status"] == "SUCCESS"

def test_verify_staff_failure():
    response = client.post("/api/verify-staff", json={"password": "WRONG_PASSWORD"})
    assert response.status_code == 401
    assert response.json()["detail"] == "Acceso denegado"

def test_verify_staff_empty_password():
    response = client.post("/api/verify-staff", json={"password": ""})
    assert response.status_code == 401
    assert response.json()["detail"] == "Acceso denegado"

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