Skip to content

Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)

Python

fix(security): constant-time comparison for ANTHROPIC_AUTH_TOKEN (#262)

@aaronjmarsb8f850813c9b
diff --git a/api/dependencies.py b/api/dependencies.py
index c3e57434..fbc37b08 100644
--- a/api/dependencies.py
+++ b/api/dependencies.py
@@ -1,5 +1,7 @@
"""Dependency injection for FastAPI."""
+import secrets
+
from fastapi import Depends, HTTPException, Request
from loguru import logger
from starlette.applications import Starlette
@@ -116,7 +118,11 @@ def require_api_key(
if token and ":" in token:
token = token.split(":", 1)[0]
- if token != anthropic_auth_token:
+ # Constant-time comparison to avoid leaking the configured token via
+ # response-time differences on a per-byte mismatch (CWE-208).
+ if not secrets.compare_digest(
+ token.encode("utf-8"), anthropic_auth_token.encode("utf-8")
+ ):
raise HTTPException(status_code=401, detail="Invalid API key")