From 1946cfa11de61d3dc69417fd226396bd476ae04f Mon Sep 17 00:00:00 2001 From: Edoardo Spadoni Date: Fri, 27 Nov 2026 16:10:03 +0100 Subject: [PATCH] fix(streaming): send an origin to the video gateway The pages of the packaged app are loaded from file://, so the WHEP requests to the video gateway carry no Origin header while Chromium marks them as cross-site. MediaMTX refuses them with 403 before checking the token, and the door phone video is never shown. In dev mode the pages come from the Vite server, which sends an origin. Send the requests to the video gateway with the origin of the gateway when they have none: the access is still granted by the token only. --- src/main/lib/videoGatewayOrigin.ts | 31 ++++++++++++++++++++++++++++++ src/main/main.ts | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 src/main/lib/videoGatewayOrigin.ts diff --git a/src/main/lib/videoGatewayOrigin.ts b/src/main/lib/videoGatewayOrigin.ts new file mode 100644 index 00000000..83b63e92 --- /dev/null +++ b/src/main/lib/videoGatewayOrigin.ts @@ -0,0 +1,31 @@ +import { session } from 'electron' + +// WHEP endpoint of the NethVoice video gateway (MediaMTX) +const VIDEO_GATEWAY_URLS = [ + 'https://*/streaming-gw/*', + 'http://*/streaming-gw/*', +] + +/** + * The pages of NethLink are loaded from file://, so their requests carry no + * Origin header while Chromium marks them as cross-site. The video gateway + * refuses a cross-site request without a valid origin before checking its + * token, and the door phone video is never shown. Send the requests to the + * gateway with the origin of the gateway itself: the access is still granted + * by the token of the request only. + */ +export function attachVideoGatewayOrigin() { + session.defaultSession.webRequest.onBeforeSendHeaders( + { urls: VIDEO_GATEWAY_URLS }, + (details, callback) => { + const requestHeaders = { ...details.requestHeaders } + const hasOrigin = Object.keys(requestHeaders).some( + (name) => name.toLowerCase() === 'origin', + ) + if (!hasOrigin) { + requestHeaders['Origin'] = new URL(details.url).origin + } + callback({ requestHeaders }) + }, + ) +} diff --git a/src/main/main.ts b/src/main/main.ts index 220d7148..ba547cb3 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -64,6 +64,7 @@ import Backend from 'i18next-fs-backend/cjs' import { uniq } from 'lodash' import { Registry } from 'rage-edit' import { useNethVoiceAPI } from '@shared/useNethVoiceAPI' +import { attachVideoGatewayOrigin } from './lib/videoGatewayOrigin' // get app parameter const params = process.argv @@ -297,6 +298,7 @@ function attachOnReadyProcess() { new SplashScreenController() new TrayController() new ScreenSharePickerController() + attachVideoGatewayOrigin() // I display the splashscreen when the splashscreen component is correctly loaded. SplashScreenController.instance.window.addOnBuildListener(() => {