From 58d56ed767a0a628d2ff40196ea92c43eec6370f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 26 Oct 2026 12:11:51 +0100 Subject: [PATCH] Block non-http(s) editor and sidebar URLs to prevent stored XSS through iframes --- .../src/app/shared/utils/editor-utils.spec.ts | 34 +++++++++++++++++++ frontend/src/app/shared/utils/editor-utils.ts | 19 ++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/shared/utils/editor-utils.spec.ts b/frontend/src/app/shared/utils/editor-utils.spec.ts index 0788b4cc7..e182bdca4 100644 --- a/frontend/src/app/shared/utils/editor-utils.spec.ts +++ b/frontend/src/app/shared/utils/editor-utils.spec.ts @@ -61,6 +61,40 @@ describe('EditorUtils', () => { expect(result).toEqual('http://undefined?query=value'); }); + it('should keep relative editor url', () => { + const result = computeEditorUrl('/editors/${editor1}', settings); + + expect(result).toEqual('/editors/url/to/editor1'); + }); + + ['javascript:alert(1)', ' JavaScript:alert(1)', 'data:text/html,', 'vbscript:msgbox(1)'].forEach(url => { + it(`should return empty string if url has unsafe protocol ${url}`, () => { + const result = computeEditorUrl(url, settings); + + expect(result).toEqual(''); + }); + }); + + it('should return empty string if interpolated url has unsafe protocol', () => { + const unsafeSettings = new AppSettingsDto({ + patterns: [], + hideDateTimeModeButton: false, + hideScheduler: false, + editors: [ + new EditorDto({ + name: 'evil', + url: 'javascript:alert(1)', + }), + ], + version: 1, + _links: {}, + }); + + const result = computeEditorUrl('${evil}', unsafeSettings); + + expect(result).toEqual(''); + }); + [null, undefined, ''].forEach(url => { it(`should return empty string if url is ${url}`, () => { const result = computeEditorUrl(url, settings); diff --git a/frontend/src/app/shared/utils/editor-utils.ts b/frontend/src/app/shared/utils/editor-utils.ts index 3866222b7..8e92951b1 100644 --- a/frontend/src/app/shared/utils/editor-utils.ts +++ b/frontend/src/app/shared/utils/editor-utils.ts @@ -20,5 +20,22 @@ export function computeEditorUrl(url?: string | null, settings?: AppSettingsDto } } - return interpolate(url, editors) || ''; + const result = interpolate(url, editors) || ''; + + return isSafeEditorUrl(result) ? result : ''; +} + +function isSafeEditorUrl(url: string) { + if (!url) { + return false; + } + + // The url is trusted for the iframe, therefore protocols like 'javascript:' would run in our origin. + try { + const protocol = new URL(url, window.location.href).protocol; + + return protocol === 'http:' || protocol === 'https:'; + } catch { + return false; + } }