Skip to content

fix(security): use constant-time admin key checks#78

Open
Ayush-Raj-Chourasia wants to merge 1 commit into
Stanzin7:masterfrom
Ayush-Raj-Chourasia:fix/admin-key-constant-time
Open

fix(security): use constant-time admin key checks#78
Ayush-Raj-Chourasia wants to merge 1 commit into
Stanzin7:masterfrom
Ayush-Raj-Chourasia:fix/admin-key-constant-time

Conversation

@Ayush-Raj-Chourasia
Copy link
Copy Markdown

Summary

This PR hardens admin API key validation by using constant-time comparison.

Changes made

  • Replaced direct string equality with
  • Applied the same comparison approach to both admin and telemetry admin key checks
  • Added regression tests covering the admin and telemetry key paths

Security impact

This reduces the risk of timing-based key disclosure attacks against privileged endpoints.

Testing

  • PYTHONPATH=src python -m pytest -q tests/api/test_admin_endpoints.py -k 'constant_time_key_compare or telemetry_summary_with_telemetry_key_succeeds or delete_scan_with_correct_admin_key_succeeds'
  • Result: 4 passed

Copilot AI review requested due to automatic review settings April 2, 2026 22:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens privileged endpoint authentication by switching admin/telemetry API key validation to a constant-time comparison to reduce timing-attack exposure in extension_shield’s FastAPI layer.

Changes:

  • Replaced direct string equality checks with hmac.compare_digest for admin key validation.
  • Applied the same constant-time comparison logic to the telemetry admin key path.
  • Added regression tests to ensure both DELETE scan and telemetry summary endpoints go through compare_digest.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/extension_shield/api/main.py Uses hmac.compare_digest for admin and telemetry key verification in request guards.
tests/api/test_admin_endpoints.py Adds tests that patch hmac.compare_digest to assert constant-time compare is exercised for both relevant endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot added the area: backend Changes to the Python backend and scanning pipeline label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backend Changes to the Python backend and scanning pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants