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:
13 files changed
+244
-56
No files matched your search
@@ -1,21 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { extractBearerToken } from '../src/webui/request-security';
|
||||
import { extractWebuiSessionToken } from '../src/webui/request-security';
|
||||
|
||||
describe('WebUI stream authentication', () => {
|
||||
it('accepts a dedicated session header alongside proxy credentials for every stream', () => {
|
||||
for (const path of [
|
||||
'/api/logs/stream',
|
||||
'/api/debug/stream',
|
||||
'/api/state/stream',
|
||||
'/api/debug/invoke-stream',
|
||||
]) {
|
||||
const request = new Request(`http://localhost${path}`, {
|
||||
headers: {
|
||||
authorization: 'Basic cHJveHk6cGFzc3dvcmQ=',
|
||||
'X-SnowLuma-Token': 'stream-token',
|
||||
},
|
||||
});
|
||||
expect(extractWebuiSessionToken(request)).toBe('stream-token');
|
||||
}
|
||||
});
|
||||
|
||||
it('accepts bearer credentials for every live stream', () => {
|
||||
for (const path of ['/api/logs/stream', '/api/debug/stream', '/api/state/stream']) {
|
||||
const request = new Request(`http://localhost${path}`, {
|
||||
headers: { authorization: 'Bearer stream-token' },
|
||||
});
|
||||
expect(extractBearerToken(request)).toBe('stream-token');
|
||||
expect(extractWebuiSessionToken(request)).toBe('stream-token');
|
||||
}
|
||||
});
|
||||
|
||||
it('does not accept tokens from stream query parameters', () => {
|
||||
for (const path of ['/api/logs/stream', '/api/debug/stream', '/api/state/stream']) {
|
||||
expect(extractBearerToken(new Request(`http://localhost${path}?token=leaked`))).toBe(
|
||||
'',
|
||||
);
|
||||
expect(
|
||||
extractWebuiSessionToken(new Request(`http://localhost${path}?token=leaked`)),
|
||||
).toBe('');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user