diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 987bfcb333..1c6329286e 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -330,6 +330,21 @@ const cookieDomain = isolateDevAuth ? '' : 'localhost' // with it so that one worktree's login does not stand for another's session. const sessionHintCookie = isolateDevAuth ? `${authCookie}_hint` : 'wm_session' +// `changeOrigin` rewrites Host to the backend's, so pass on the host the browser addressed: +// over plain http to a LAN or Tailscale address there is no Sec-Fetch-Site, and the backend's +// cross-site check (request_site.rs) then matches Origin against the hosts it can see. +function forwardHost(proxy) { + proxy.on('proxyReq', (proxyReq, req) => { + if (req.headers.host && !req.headers['x-forwarded-host']) + proxyReq.setHeader('x-forwarded-host', req.headers.host) + }) +} + +function configureApiProxy(proxy) { + forwardHost(proxy) + isolateAuthCookie(proxy) +} + function isolateAuthCookie(proxy) { if (!isolateDevAuth) return proxy.on('proxyReq', (proxyReq, req) => { @@ -454,7 +469,7 @@ const config = { target: remoteUrl, changeOrigin: true, cookieDomainRewrite: cookieDomain, - configure: isolateAuthCookie + configure: configureApiProxy }, '^/api/w/[^/]+/s3_proxy/.*': { target: remoteUrl, @@ -474,7 +489,7 @@ const config = { target: remoteUrl, changeOrigin: true, cookieDomainRewrite: cookieDomain, - configure: isolateAuthCookie + configure: configureApiProxy }, '^/ws/.*': { target: process.env.REMOTE_LSP ?? process.env.REMOTE_EXTRA ?? 'https://app.windmill.dev',