From 12ee78262ef9a105b548f3c024bc7bbc587af263 Mon Sep 17 00:00:00 2001 From: Jacopo Beschi Date: Wed, 18 Dec 2024 17:52:52 +0100 Subject: [PATCH 1/2] Fix XSS via `javascript:` url in a link Prevously, was possible to trigger XSS setting as link an URL like `javascript:alert('XSS')`. Fix it via a custom HTML input validation pattern to block both `javascript:` and `data:` URLs. --- src/test/system/text_formatting_test.js | 12 ++++++++++++ src/trix/config/toolbar.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/system/text_formatting_test.js b/src/test/system/text_formatting_test.js index 0b099c5f0..ce7e775e6 100644 --- a/src/test/system/text_formatting_test.js +++ b/src/test/system/text_formatting_test.js @@ -58,6 +58,18 @@ testGroup("Text formatting", { template: "editor_empty" }, () => { expectDocument("ahttp://example.com\n") }) + test("inserting a javascript: link is forbidden", async () => { + await typeCharacters("XSS") + await moveCursor("left") + await expandSelection("left") + await clickToolbarButton({ attribute: "href" }) + assert.ok(isToolbarDialogActive({ attribute: "href" })) + await typeInToolbarDialog("javascript:alert('XSS')", { attribute: "href" }) + assert.textAttributes([ 0, 1 ], {}) + assert.textAttributes([ 1, 2 ], { frozen: true }) + assert.textAttributes([ 2, 3 ], {}) + }) + test("editing a link", async () => { insertString("a") const text = Text.textForStringWithAttributes("bc", { href: "http://example.com" }) diff --git a/src/trix/config/toolbar.js b/src/trix/config/toolbar.js index d45c68bee..2d97de337 100644 --- a/src/trix/config/toolbar.js +++ b/src/trix/config/toolbar.js @@ -35,7 +35,7 @@ export default {