#7704: fix(voice-call): add authentication to WebSocket media stream endpoint
channel: voice-call
stale
Cluster:
Voice Call Security Enhancements
## Fix Summary
This PR adds authentication to the voice-call WebSocket media stream endpoint, addressing a critical security vulnerability where the endpoint accepted connections without any authentication.
**Changes:**
- Add `streamToken` config option for URL-based token validation
- Add `expectedAccountSid` config option for Twilio accountSid validation
- Reject WebSocket upgrades without valid token when `streamToken` is configured
- Reject streams with mismatched accountSid when `expectedAccountSid` is configured
## Issue Linkage
Fixes #7001
## Security Snapshot
| Metric | Value |
|--------|-------|
| **Score** | 9.1 / 10.0 |
| **Severity** | Critical |
| **Vector** | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N |
## Implementation Details
### Files Changed
- `extensions/voice-call/src/config.ts` (+11/-0)
- `extensions/voice-call/src/media-stream.ts` (+25/-2)
- `extensions/voice-call/src/webhook.ts` (+18/-1)
### Technical Analysis
This PR adds authentication to the voice-call WebSocket media stream endpoint, addressing a critical security vulnerability where the endpoint accepted connections without any authentication.
## Validation Evidence
- Command: `pnpm build`
- Status: passed
## Risk and Compatibility
non-breaking; compatibility impact was not explicitly documented in the original PR body.
## AI-Assisted Disclosure
- AI-assisted: yes
- Model: Claude Code
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds opt-in authentication/validation around the voice-call media streaming WebSocket endpoint by:
- Extending `VoiceCallStreamingConfigSchema` with `streamToken` (query param token gate) and `expectedAccountSid` (Twilio start message validation).
- Enforcing the token check during HTTP `upgrade` handling in `extensions/voice-call/src/webhook.ts`, rejecting unauthenticated upgrades.
- Validating the Twilio `start.accountSid` inside the stream handler and closing the socket on mismatch.
Overall this tightens a previously unauthenticated WS entrypoint. The main concern is that `expectedAccountSid` is stored as mutable handler state, which can cause cross-connection validation races if multiple streams are upgraded concurrently under different expected SIDs.
<h3>Confidence Score: 3/5</h3>
- Generally safe to merge, but there is a concurrency/state bug risk in the new accountSid validation wiring.
- The auth gate on WS upgrades is straightforward and localized, but `MediaStreamHandler.handleUpgrade()` mutates a shared `expectedAccountSid` field that is later used during `start` processing; this can validate against the wrong value under concurrent streams or differing server configuration. `.gitignore` also includes unrelated broad additions that add noise.
- extensions/voice-call/src/media-stream.ts (shared mutable expectedAccountSid); .gitignore (unrelated ignore-pattern churn)
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#21050: security(voice-call): path-based stream token for Twilio WebSocket ...
by richvincent · 2026-02-19
88.1%
#12471: fix(voice-call): pass stream auth token via TwiML Parameter for Twi...
by Yida-Dev · 2026-02-09
80.5%
#17007: fixed stacy voice
by tashen247 · 2026-02-15
77.1%
#21197: Security/Voice Call: enforce exact webhook path matching
by bmendonca3 · 2026-02-19
76.8%
#21101: Security/Voice Call: gate skipSignatureVerification to local-dev or...
by bmendonca3 · 2026-02-19
76.7%
#18852: fix: Voice-call state persistence is fire-and-forget, causing silen...
by coygeek · 2026-02-17
75.7%
#21288: Security/Voice: reject malformed Host headers in webhook+WS server
by bmendonca3 · 2026-02-19
75.7%
#8922: feat(voice-call): Add ElevenLabs WebSocket streaming TTS
by mikiships · 2026-02-04
75.7%
#6702: fix(voice-call): mark calls as ended when media stream disconnects
by johngnip · 2026-02-01
75.5%
#10238: Security: Fix TwiML injection via unescaped locale/language/voice p...
by StreetJammer · 2026-02-06
75.2%