#2218·go2rtc

CORS preflight OPTIONS fails with 401 when authentication is enabled

Author: JeremyH76Created Apr 17, 2026Updated Oct 1, 2026
Labelsbug

Description

When both origin: '*' and username/password are configured in the api section, all cross-origin requests from browsers fail with a CORS error. I didn't succeed to connect to a stream in WebRTC.

Environment

I have the following config:

api:
  origin: '*'
  listen: ':1984'
  username: 'admin'
  password: 'pass'

Steps to reproduce

From a browser (different origin, like localhost:4200), make any fetch() POST request to /api/webrtc. Example: fetch("http://localhost:1984/api/webrtc?src=mycamera", { method: "POST", headers: { "Content-Type": "application/sdp", "Authorization": "Basic " + btoa("admin:pass") }, }); The browser sends a CORS preflight OPTIONS request first.

Observed behavior

OPTIONS http://localhost:1984/api/webrtc?src=mycamera → 401 Unauthorized POST http://localhost:1984/api/webrtc?src=mycamera → CORS error (blocked by browser)

Related issues

#850 — same problem, closed without fix