Skip to content

[BUG] Cryptographic Timing Attack Vulnerability in Admin API Authentication #18

@rishabh0510rishabh

Description

@rishabh0510rishabh

title: "[BUG] Cryptographic Timing Attack Vulnerability in Admin API Authentication"
labels: level:critical, quality:exceptional, type:security, type:performance

Problem / Motivation

Analysis of the REST Admin API middleware reveals a critical security vulnerability in how Bearer tokens are validated.

In humane_proxy/api/admin.py, the _require_admin dependency extracts the HUMANE_PROXY_ADMIN_KEY from the environment and compares it against the incoming request credentials using a standard equality operator (!=):

# [humane_proxy/api/admin.py:48]
if credentials is None or credentials.credentials != admin_key:
    raise HTTPException(
        status_code=401,
        detail="Invalid or missing Bearer token.",
        headers={"WWW-Authenticate": "Bearer"},
    )
```python
---
Standard string comparison in Python evaluates character-by-character and short-circuits upon the first mismatch. This introduces a measurable timing discrepancy based on how many characters of the attacker's payload match the actual secret. An attacker can exploit this timing side-channel to brute-force the HUMANE_PROXY_ADMIN_KEY over the network, granting them full access to the /admin endpoints (including the ability to export or delete sensitive escalation logs).

To Reproduce
Start the HumaneProxy server with a configured HUMANE_PROXY_ADMIN_KEY.
Send repeated GET /admin/health or GET /admin/stats requests with varying Bearer tokens.
Measure the microsecond response time differences between a token where the first character matches the secret vs. a token where it does not.
Observe the timing leak caused by the short-circuiting != operator.
Expected Behaviour
Authentication token comparison must be executed in constant time, regardless of the input's validity or length, to prevent timing side-channel attacks.

Suggested Fix
Import the hmac module from the Python standard library and replace the standard equality operator with hmac.compare_digest. This function is specifically designed for cryptographic constant-time string comparison.

Update humane_proxy/api/admin.py:

Metadata

Metadata

Labels

bugSomething isn't workingenhancementNew feature or requestlevel:advancedRequires advanced implementation, bug fixing or refactoringtype:performanceFixes performance issuestype:securityFixes security issues

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions