Bug: Timing-unsafe admin key comparison in bridge API
Severity: MEDIUM (CWE-208: Observable Timing Discrepancy)
Description
bridge/bridge_api.py uses a direct string comparison for admin key authentication:
def _require_admin(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
key = request.headers.get("X-Admin-Key", "")
if not BRIDGE_ADMIN_KEY:
return jsonify({"error": "admin key not configured on server"}), 500
if key != BRIDGE_ADMIN_KEY: # ← TIMING-UNSAFE!
return jsonify({"error": "unauthorized"}), 403
Impact
- Timing attack: The
!= comparison returns early at the first differing character, enabling an attacker to determine the key character-by-character by measuring response times
- Key recovery: With enough requests, the entire admin key can be reconstructed
- 500 error info leak: Returning 500 when key not configured reveals server configuration to attackers
Suggested Fix
import hmac
if not hmac.compare_digest(key, BRIDGE_ADMIN_KEY):
return jsonify({"error": "unauthorized"}), 403
Wallet: RTC9d7caca3039130d3b26d41f7343d8f4ef4592360
Bug: Timing-unsafe admin key comparison in bridge API
Severity: MEDIUM (CWE-208: Observable Timing Discrepancy)
Description
bridge/bridge_api.pyuses a direct string comparison for admin key authentication:Impact
!=comparison returns early at the first differing character, enabling an attacker to determine the key character-by-character by measuring response timesSuggested Fix
Wallet:
RTC9d7caca3039130d3b26d41f7343d8f4ef4592360