Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(workers): fail closed on an empty API key and compare keys timing-safely as bytes
nirholas02699aee5e25
diff --git a/workers/avatar-pipeline-controller/worker_security.py b/workers/avatar-pipeline-controller/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/avatar-pipeline-controller/worker_security.py+++ b/workers/avatar-pipeline-controller/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/avatar-reconstruction/worker_security.py b/workers/avatar-reconstruction/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/avatar-reconstruction/worker_security.py+++ b/workers/avatar-reconstruction/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/garment-forge/worker_security.py b/workers/garment-forge/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/garment-forge/worker_security.py+++ b/workers/garment-forge/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/longcat/worker_security.py b/workers/longcat/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/longcat/worker_security.py+++ b/workers/longcat/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/model-asl-recognition/README.md b/workers/model-asl-recognition/README.mdindex c67ecd0dd..48ede9414 100644--- a/workers/model-asl-recognition/README.md+++ b/workers/model-asl-recognition/README.md@@ -63,9 +63,12 @@ video ever leaves the user's machine, only pose coordinates.cd workers/model-asl-recognitionpip install -r requirements.txtgsutil cp gs://three-ws-model-weights/aslfr-1st-place/cfg_2-fold-1/model.tflite .-MODEL_PATH=./model.tflite API_KEY= uvicorn main:app --port 8087+MODEL_PATH=./model.tflite API_KEY=dev-local-key uvicorn main:app --port 8087```+The worker fails closed: with `API_KEY` unset every route but `/health` answers+401, so pick any local value and send it as `Authorization: Bearer dev-local-key`.+That is the platform's mirror of the same 40,946,288-byte file the image pullsfrom the release zip (sha256`4dda856e82c4f909c3ae7eb7f070e5fc88afb143daab639683209b631e3cbfaa`); the zipdiff --git a/workers/model-asl-recognition/main.py b/workers/model-asl-recognition/main.pyindex f7a3f6f82..3fffc99e8 100644--- a/workers/model-asl-recognition/main.py+++ b/workers/model-asl-recognition/main.py@@ -17,6 +17,7 @@ API (bearer auth via API_KEY, same secret family as the reconstruction lanes):from __future__ import annotationsimport asyncio+import hmacimport osimport timefrom contextlib import asynccontextmanager@@ -50,10 +51,12 @@ app = FastAPI(lifespan=lifespan)def _check_auth(request: Request) -> None:- if not API_KEY:- return+ # Fails closed like every other worker: an unset API_KEY must not turn the+ # public Cloud Run URL into an open inference endpoint. Constant-time+ # compare so the key cannot be recovered byte by byte from response timing.header = request.headers.get("authorization", "")- if header != f"Bearer {API_KEY}":+ expected = f"Bearer {API_KEY}"+ if not API_KEY or not hmac.compare_digest(header.encode("utf-8"), expected.encode("utf-8")):raise HTTPException(status_code=401, detail="unauthorized")diff --git a/workers/model-hunyuan3d/worker_security.py b/workers/model-hunyuan3d/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/model-hunyuan3d/worker_security.py+++ b/workers/model-hunyuan3d/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/model-text2motion/worker_security.py b/workers/model-text2motion/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/model-text2motion/worker_security.py+++ b/workers/model-text2motion/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/model-trellis/worker_security.py b/workers/model-trellis/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/model-trellis/worker_security.py+++ b/workers/model-trellis/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/model-triposg/worker_security.py b/workers/model-triposg/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/model-triposg/worker_security.py+++ b/workers/model-triposg/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/model-triposr/worker_security.py b/workers/model-triposr/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/model-triposr/worker_security.py+++ b/workers/model-triposr/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/model-video2motion/worker_security.py b/workers/model-video2motion/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/model-video2motion/worker_security.py+++ b/workers/model-video2motion/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/model-video2scene/worker_security.py b/workers/model-video2scene/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/model-video2scene/worker_security.py+++ b/workers/model-video2scene/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/rembg/worker_security.py b/workers/rembg/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/rembg/worker_security.py+++ b/workers/rembg/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/remesh/worker_security.py b/workers/remesh/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/remesh/worker_security.py+++ b/workers/remesh/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/rig/worker_security.py b/workers/rig/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/rig/worker_security.py+++ b/workers/rig/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/segment/worker_security.py b/workers/segment/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/segment/worker_security.py+++ b/workers/segment/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/stylize/worker_security.py b/workers/stylize/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/stylize/worker_security.py+++ b/workers/stylize/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")diff --git a/workers/texture/worker_security.py b/workers/texture/worker_security.pyindex b1c4dd4cd..a0360fe96 100644--- a/workers/texture/worker_security.py+++ b/workers/texture/worker_security.py@@ -39,11 +39,18 @@ def require_api_key(authorization: Optional[str], api_key: str) -> None:Raises ``PermissionError`` on any failure so callers can translate it intothe framework's 401 (FastAPI workers map this to HTTPException(401))."""+ # Fail closed on an empty configured key: with api_key == "" a bare+ # "Bearer " header would otherwise strip to "" and compare equal.+ if not api_key:+ raise PermissionError("worker api key not configured")if not authorization or not authorization.startswith("Bearer "):raise PermissionError("missing bearer token")token = authorization[len("Bearer "):].strip()- # hmac.compare_digest is timing-safe and accepts str (ASCII) operands.- if not hmac.compare_digest(token, api_key):+ if not token:+ raise PermissionError("missing bearer token")+ # Compare bytes: hmac.compare_digest is timing-safe, and on str operands it+ # raises TypeError for non-ASCII input, which would surface as a 500.+ if not hmac.compare_digest(token.encode("utf-8"), api_key.encode("utf-8")):raise PermissionError("invalid api key")