fix(webui): preserve reverse proxy authentication

Prevent login loops when the WebUI is protected by HTTP authentication
at a reverse proxy. Apply the fix to settings, uploads, and live streams
while retaining compatibility with existing WebUI clients.

Fixes #523
This commit is contained in:
DrSmoothl committed 2026-10-14 08:13:50 +08:00
1 parent d6dd748beb
commit 5150d83403
13 files changed
+244 -56

No files matched your search

+9 -1
View File
@@ -41,7 +41,15 @@ export const webuiSecurityHeaders: MiddlewareHandler = async (c, next) => {
);
};
export function extractBearerToken(request: Request): string {
export function extractWebuiSessionToken(request: Request): string {
const sessionToken = request.headers.get('x-snowluma-token');
// Authorization belongs to the proxy when it uses HTTP authentication.
// Only clients without the dedicated header use the legacy Bearer transport.
if (sessionToken !== null) {
return sessionToken;
}
const authorization = request.headers.get('authorization');
return authorization?.startsWith('Bearer ') ? authorization.slice(7) : '';
}
+4 -5
View File
@@ -108,7 +108,7 @@ import { registerStorageRoutes } from './storage-routes';
import { LogStorageSettingsManager } from './storage-settings';
import {
clearAvatarSessionCookie,
extractBearerToken,
extractWebuiSessionToken,
readAvatarSessionToken,
registerLoginRequestSecurity,
setAvatarSessionCookie,
@@ -801,7 +801,7 @@ export async function initWebUI(
return next();
}
const token = extractBearerToken(c.req.raw);
const token = extractWebuiSessionToken(c.req.raw);
if (!token) {
return c.json({ status: 'failed', message: 'Unauthorized' }, 401);
@@ -1672,9 +1672,8 @@ export async function initWebUI(
});
// Invoke a Stream API action (or any action) and relay every frame to the
// browser over an SSE body. The frontend reads this with fetch()+a stream
// reader (Bearer auth in the header), so — unlike /api/debug/stream — it does
// NOT need a query-token allowlist entry. Frames are never dropped.
// browser over an SSE body. The frontend uses fetch()+a stream reader so
// the session token stays in a header on this POST. Frames are never dropped.
app.post('/api/debug/invoke-stream', async (c) => {
let body: unknown;