Skip to content

Comments

security: restrict CORS to known local origins#88

Open
dgilperez wants to merge 2 commits intojamiepine:mainfrom
Balneario-de-Cofrentes:fix/restrict-cors-origins
Open

security: restrict CORS to known local origins#88
dgilperez wants to merge 2 commits intojamiepine:mainfrom
Balneario-de-Cofrentes:fix/restrict-cors-origins

Conversation

@dgilperez
Copy link

@dgilperez dgilperez commented Feb 17, 2026

Summary

  • Replace wildcard allow_origins=["*"] with an explicit allowlist of known local origins (Tauri webview, Vite dev server, localhost API)
  • Add VOICEBOX_CORS_ORIGINS env var for users who need additional origins in remote server mode
  • Zero breaking change for normal local usage

Motivation

The wildcard CORS policy allows any website the user visits to make cross-origin requests to the local voicebox backend (port 17493). A malicious page could silently trigger TTS generation, read voice profiles, or access generation history without user consent.

Allowed origins (default)

Origin Purpose
http://localhost:5173 Vite dev server
http://127.0.0.1:5173 Vite dev server (IP)
http://localhost:17493 Local API
http://127.0.0.1:17493 Local API (IP)
tauri://localhost Tauri webview (macOS)
https://tauri.localhost Tauri webview (Windows/Linux)

Remote server mode

Users running voicebox as a remote server can extend the allowlist:

VOICEBOX_CORS_ORIGINS="https://my-app.example.com,https://other.example.com" python -m backend.main --host 0.0.0.0

Test plan

  • 20 pytest tests covering allowed origins, blocked origins, preflight, env var parsing, and edge cases (all green)
  • Verify Tauri desktop app connects normally in local mode
  • Verify bun run dev (Vite) connects to backend
  • Verify arbitrary websites cannot make cross-origin requests to the backend

The wildcard `allow_origins=["*"]` allows any website the user visits to
make requests to the local voicebox backend, potentially triggering TTS
generation or reading voice profiles without consent.

Restrict to the known Tauri webview and Vite dev server origins by
default. Users running in remote server mode can set
VOICEBOX_CORS_ORIGINS to allow additional origins.
20 tests covering:
- All 6 default local origins are allowed
- Arbitrary external origins are blocked
- Preflight (OPTIONS) requests respect the allowlist
- VOICEBOX_CORS_ORIGINS env var extends the allowlist
- Edge cases: empty env, whitespace trimming, trailing commas

Tests use a minimal FastAPI app mirroring the real CORS config,
so they run without ML dependencies (torch, numpy, etc.).
Copilot AI added a commit to Patrick-DE/voicebox that referenced this pull request Feb 19, 2026
…ne#88, jamiepine#91, jamiepine#95, jamiepine#97)

Co-authored-by: Patrick-DE <14962702+Patrick-DE@users.noreply.github.com>
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.

1 participant