From e21d3a40ad32769a837db54df4a440f567523367 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 3 Oct 2023 08:37:34 +0200 Subject: [PATCH] parser: use safer mechanism for allowing URLs Having a default-remove boolean flag is making it easier to get this right and decouple the if-branches that check if something is OK (which may get more complex in the future) from the actual handling of the result by always removing the href attribute if not explicitly told otherwise. Signed-off-by: Thomas Lamprecht --- src/Parser.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Parser.js b/src/Parser.js index 60eff5d..04c8188 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -31,6 +31,7 @@ Ext.define('Proxmox.Markdown', { ) { node.attributes.removeNamedItem(name); } else if ((name === 'href' || name === 'src') && !_isHTTPLike(value)) { + let safeURL = false; try { let url = new URL(value, window.location.origin); if ( @@ -38,6 +39,9 @@ Ext.define('Proxmox.Markdown', { canonicalTagName === 'a' || (canonicalTagName === 'img' && url.protocol.toLowerCase() === 'data:') ) { + safeURL = true; + } + if (safeURL) { node.attributes[i].value = url.href; } else { node.attributes.removeNamedItem(name);