mirror of
https://github.com/immich-app/immich
synced 2026-08-29 13:15:45 +00:00
fix: maintentance return URL sanitization (#30948)
This commit is contained in:
parent
c98c20e963
commit
cbf5d83a69
2 changed files with 28 additions and 1 deletions
27
web/src/lib/utils/maintenance.spec.ts
Normal file
27
web/src/lib/utils/maintenance.spec.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { maintenanceReturnUrl } from '$lib/utils/maintenance';
|
||||
|
||||
describe('maintenance', () => {
|
||||
describe(maintenanceReturnUrl.name, () => {
|
||||
beforeEach(() => {
|
||||
// @ts-expect-error - override location for testing
|
||||
// eslint-disable-next-line unicorn/no-global-object-property-assignment
|
||||
globalThis.location = new URL('https://my.immich.server');
|
||||
vi.spyOn(document, 'baseURI', 'get').mockReturnValue('https://my.immich.server/');
|
||||
});
|
||||
|
||||
it('should resolve a same-origin continue url', () => {
|
||||
expect(maintenanceReturnUrl(new URLSearchParams({ continue: '/photos' }))).property(
|
||||
'href',
|
||||
'https://my.immich.server/photos',
|
||||
);
|
||||
});
|
||||
|
||||
it('should fall back to the root route when continue is missing', () => {
|
||||
expect(maintenanceReturnUrl(new URLSearchParams())).property('href', 'https://my.immich.server/');
|
||||
});
|
||||
|
||||
it('should reject a cross-origin continue url', () => {
|
||||
expect(maintenanceReturnUrl(new URLSearchParams({ continue: 'https://malicious.site/evil' }))).toBe('/');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -8,7 +8,7 @@ export function maintenanceCreateUrl(url: URL) {
|
|||
}
|
||||
|
||||
export function maintenanceReturnUrl(searchParams: URLSearchParams) {
|
||||
return searchParams.get('continue') ?? '/';
|
||||
return Route.continue(searchParams.get('continue'), '/');
|
||||
}
|
||||
|
||||
export function maintenanceShouldRedirect(maintenanceMode: boolean, currentUrl: URL | Location) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue