T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/elevenlabs_api.py:32- Finding
Unauthenticated endpoints expose the server-held ElevenLabs API key and paid quota to unauthorized callers
- Content
View full analysis
Vulnerability Details
File Location:
scripts/elevenlabs_api.py, lines 32-46
Vulnerability Type: Missing authentication and authorization on a privileged API proxy
Risk Level: HighVulnerable Code
python @router.post("/api/voice/tts") async def text_to_speech(body: dict): text = body.get("text", "") voice_id = body.get("voice_id", "pNInz6obpgDQGcFmaJgB") # Adam default if not text: raise HTTPException(status_code=400, detail="text is required") async with httpx.AsyncClient(timeout=30) as client: r = await client.post(f"{BASE_URL}/text-to-speech/{voice_id}", headers=_headers(), json={"text": text, "model_id": "eleven_multilingual_v2", "voice_settings": {"stability": 0.5, "similarity_boost": 0.75}}) if r.status_code != 200: raise HTTPException(status_code=r.status_code, detail=r.text[:500]) return StreamingResponse(iter([r.content]), media_type="audio/mpeg", headers={"Content-Disposition": "attachment; filename=narration.mp3"})The same access-control weakness affects the voice-list, STT, sound-generation, lullaby-generation, WebSocket streaming, and story-chat routes.
Technical Analysis
The route accepts requests without authenticating or authorizing the caller and then authenticates the upstream request using the server-held
ELEVENLABS_API_KEY. This turns the application into an unrestricted proxy for paid ElevenLabs operations.The WebSocket route has the same issue and calls
await websocket.accept()without verifying the caller. If the containing FastAPI application is exposed beyond a strictly trusted local environment, remote users can invoke privileged upstream functionality without possessing the ElevenLabs credential.Although the code does not disclose the raw key in normal responses, it grants callers the effective privilege associated with that ke ...[truncated 1299 chars]
- Remediation
View remediation
Remediation Suggestions
- Require authentication on every HTTP endpoint before performing any upstream request.
- Apply authorization policies so users can access only the operations and quotas assigned to them.
- Authenticate WebSocket clients before calling
websocket.accept(), or immediately reject unauthorized handshakes using an appropriate close code. - Add per-user and per-IP rate limits, concurrent-request limits, and spending or character quotas.
- Bind the service to loopback by default if it is intended exclusively for local use.
- Place the service behind an authenticated reverse proxy when remote access is required.
- Record caller identity, operation type, and upstream usage in security audit logs without recording API keys or sensitive content.
- Fail securely when
ELEVENLABS_API_KEYis missing rather than sending an empty credential upstream.
