diff --git a/src/Core/XssSanitiser.php b/src/Core/XssSanitiser.php index 5ffdb224b95..adfcfabb289 100644 --- a/src/Core/XssSanitiser.php +++ b/src/Core/XssSanitiser.php @@ -201,7 +201,9 @@ private function getStripAttributeContentsRegex(): string $this->splitWithWhitespaceRegex('vbscript:'), ]; // Regex is "starts with any of these, with optional whitespace at the start, case insensitive" - return '#^\s*(' . implode('|', $regexes) . ')#iu'; + // \x08 is the backspace character, though it only causes vulnerabilities if it's at the start + // or end of a string + return '#^(\s|\x08)*(' . implode('|', $regexes) . ')(\s|\x08)*#iu'; } private function splitWithWhitespaceRegex(string $string): string diff --git a/tests/php/Core/XssSanitiserTest.php b/tests/php/Core/XssSanitiserTest.php index 0d1ef959447..103e6eed496 100644 --- a/tests/php/Core/XssSanitiserTest.php +++ b/tests/php/Core/XssSanitiserTest.php @@ -9,6 +9,9 @@ class XssSanitiserTest extends SapphireTest { + // This is the backspace character. It needs to be escaped in double-quotes. + private const CHAR_BACKSPACE = "\x08"; + protected $usesDatabase = false; public function provideSanitise(): array @@ -73,6 +76,14 @@ public function provideSanitise(): array 'input' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.', 'expected' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.', ], + [ + 'input' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.', + 'expected' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.', + ], + [ + 'input' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.', + 'expected' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.', + ], [ // Not exploitable XSS 'input' => '<a href="javascript:evil"/>', @@ -132,6 +143,10 @@ public function provideSanitise(): array 'input' => '', 'expected' => '', ], + [ + 'input' => '', + 'expected' => '', + ], [ 'input' => '', 'expected' => '', @@ -206,6 +221,10 @@ public function provideSanitise(): array 'input' => '', 'expected' => '', ], + [ + 'input' => '', + 'expected' => '', + ], [ // Not exploitable XSS 'input' => '
', diff --git a/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php b/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php index ee3d9980212..ebeaef92dc7 100644 --- a/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php +++ b/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php @@ -10,6 +10,8 @@ class HTMLEditorSanitiserTest extends FunctionalTest { + // This is the backspace character. It needs to be escaped in double-quotes. + private const CHAR_BACKSPACE = "\x08"; public function provideSanitise(): array { @@ -80,6 +82,18 @@ public function provideSanitise(): array '
Test', 'Javascript in the href attribute of a link is completely removed' ], + [ + 'a[href|target|rel]', + 'Test', + 'Test', + 'Javascript in the href attribute with leading backspace of a link is completely removed' + ], + [ + 'a[href|target|rel]', + 'Test', + 'Test', + 'Javascript in the href attribute with backspace in middle of a link is completely removed' + ], [ 'a[href|target|rel]', 'Test', @@ -110,6 +124,12 @@ public function provideSanitise(): array '', 'Javascript with tab elements the src attribute of an iframe is completely removed' ], + [ + 'iframe[src]', + '', + '', + 'Javascript in the src attribute of an iframe with a backspace is completely removed' + ], [ 'object[data]', '', @@ -128,6 +148,12 @@ public function provideSanitise(): array '', 'Object with dangerous javascript content in data attribute with quotes is completely removed' ], + [ + 'object[data]', + '', + '', + 'Object with dangerous javascript content in data attribute with backspace is completely removed' + ], [ 'object[data]', '',