Skip to content

fix: make WebRTC ICE servers configurable via VITE_ICE_SERVERS - #733

Closed
birme wants to merge 2 commits into
mainfrom
frontend/fix-626-configurable-ice-servers
Closed

birme wants to merge 2 commits into
mainfrom
frontend/fix-626-configurable-ice-servers

Conversation

@birme

@birme birme commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • ICE servers were hardcoded to Google STUN in use-rtc-connection.ts, leaking user IPs to Google and preventing customisation (Security: Hardcoded Google STUN servers expose user IPs and prevent customisation #626).
  • Added a resolveIceServers() helper that reads VITE_ICE_SERVERS (a JSON array of RTCIceServer objects).
  • Parsing is defensive: JSON.parse is wrapped in try/catch and a non-empty-array check; on any error it logs a warning and uses the fallback, so a malformed value never throws on the connection path.
  • The fallback preserves existing behaviour exactly (same two Google STUN URLs).
  • Documented the new env var in README.md and .env.local.sample.

Test plan

  • Tests pass (npm test)
  • TypeScript compiles (npm run typecheck)
  • Lint clean (npm run lint)
  • Unset var falls back to Google STUN; valid JSON var is used; malformed var falls back without throwing

Closes #626

🤖 Generated with Claude Code

Hardcoded Google STUN servers exposed user IPs and prevented
customisation. Resolve the ICE server list from the VITE_ICE_SERVERS env
var (a JSON array of RTCIceServer objects), parsing defensively and
falling back to the previous Google STUN list when unset or invalid.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@birme

birme commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Automated self-review verdict: NEEDS_CHANGES (code-reviewer, separate invocation from the implementer).

Blocking: resolveIceServers() validates only Array.isArray(parsed) && parsed.length > 0, then casts parsed as RTCIceServer[] with no per-element shape check. A valid-JSON-but-wrong-shape value (e.g. VITE_ICE_SERVERS=["stun:stun.l.google.com:19302"], [{}], or [1,2,3]) passes the array check, escapes the try/catch, and then throws TypeError uncaught at new RTCPeerConnection({ iceServers: resolveIceServers() }) during the useState initializer — crashing the production-line render. This defeats the PR's stated defensive-parse contract.

Fix: validate each element is a non-null object with a string/array urls field; fall back to the default (with a warning) if any element fails, so the cast is justified and all malformed input stays within the catch.

Non-blocking: logger.red warning is suppressed at the production logger level; VITE_ICE_SERVERS isn't declared on ImportMetaEnv in src/vite-env.d.ts (so it types as any). A small unit test on the exported helper would cover the parse/fallback branches.

Harden resolveIceServers() so valid JSON of the wrong shape (string
elements, [{}], [1,2,3]) can no longer escape the try/catch and throw
uncaught at RTCPeerConnection construction. Each element is now validated
to be a non-null object with a urls field that is a non-empty string or
array of strings; any failure falls back to the default Google STUN list.

Also declare VITE_ICE_SERVERS on ImportMetaEnv, export the helper and
DEFAULT_ICE_SERVERS, and add Vitest coverage for unset, valid, malformed
and wrong-shape inputs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@birme

birme commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate. An earlier, more complete PR for #626 already exists: #714 (branch security-audit/626-configurable-ice-servers).

#714 has a dedicated, well-tested ice-servers.ts module (scheme validation, urls-array handling, TURN-credential checks under review) with green CI, plus a documented analysis of the remaining architectural blocker — VITE_ICE_SERVERS must be wired through this repo's runtime-config path (window.__ENV__ → env.js/entrypoint.sh/runtime-config.ts/Dockerfile) to actually take effect in the deployed image, not only import.meta.env at build time.

This PR (#733) was opened by an automated run that missed the pre-existing #714; it does not add anything #714 lacks and shares the same unresolved runtime-config gap. Consolidating on #714 so the review history and analysis stay in one place.

@birme birme closed this Oct 14, 2026
@birme
birme deleted the frontend/fix-626-configurable-ice-servers branch October 14, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Hardcoded Google STUN servers expose user IPs and prevent customisation

2 participants