Download tasks/289592dc08fa1351/levels/level3/patch.diff from FuCY/php: direct link, hf CLI and curl.
- Browser
- Download file 6.17 kB
-
https://huggingface.co/datasets/FuCY/php/resolve/main/tasks/289592dc08fa1351/levels/level3/patch.diff
- Command line
-
hf download hf://datasets/FuCY/php/tasks/289592dc08fa1351/levels/level3/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/FuCY/php/resolve/main/tasks/289592dc08fa1351/levels/level3/patch.diff
6.17 kB
| 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 | |
| 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 | |
| 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 | |
| public function provideSanitise(): array | |
| 'input' => '<a href="javascript:alert(\'ok\')">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</a>', | |
| 'expected' => '<a>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</a>', | |
| ], | |
| + [ | |
| + 'input' => '<a href="' . XssSanitiserTest::CHAR_BACKSPACE . 'javascript:alert(\'ok\')">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</a>', | |
| + 'expected' => '<a>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</a>', | |
| + ], | |
| + [ | |
| + 'input' => '<a href="javascript:alert(\'ok\')' . XssSanitiserTest::CHAR_BACKSPACE . '">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</a>', | |
| + 'expected' => '<a>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</a>', | |
| + ], | |
| [ | |
| // Not exploitable XSS | |
| 'input' => '<<a href="javascript:evil"/>a href="javascript:evil"/>', | |
| public function provideSanitise(): array | |
| 'input' => '<IMG SRC="javascript:alert(\'XSS\');">', | |
| 'expected' => '<img>', | |
| ], | |
| + [ | |
| + 'input' => '<IMG SRC="' . XssSanitiserTest::CHAR_BACKSPACE . 'javascript:alert(\'XSS\');">', | |
| + 'expected' => '<img>', | |
| + ], | |
| [ | |
| 'input' => '<IMG SRC=javascript:alert(\'XSS\')>', | |
| 'expected' => '<img>', | |
| public function provideSanitise(): array | |
| 'input' => '<BGSOUND SRC="javascript:alert(\'XSS\');">', | |
| 'expected' => '<bgsound></bgsound>', | |
| ], | |
| + [ | |
| + 'input' => '<BGSOUND SRC="' . XssSanitiserTest::CHAR_BACKSPACE . 'javascript:alert(\'XSS\');">', | |
| + 'expected' => '<bgsound></bgsound>', | |
| + ], | |
| [ | |
| // Not exploitable XSS | |
| 'input' => '<BR SIZE="&{alert(\'XSS\')}">', | |
| 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 | |
| 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 | |
| { | |
| public function provideSanitise(): array | |
| '<a>Test</a>', | |
| 'Javascript in the href attribute of a link is completely removed' | |
| ], | |
| + [ | |
| + 'a[href|target|rel]', | |
| + '<a href="' . HTMLEditorSanitiserTest::CHAR_BACKSPACE . 'javascript:alert(0);">Test</a>', | |
| + '<a>Test</a>', | |
| + 'Javascript in the href attribute with leading backspace of a link is completely removed' | |
| + ], | |
| + [ | |
| + 'a[href|target|rel]', | |
| + '<a href="javascript:alert(0);' . HTMLEditorSanitiserTest::CHAR_BACKSPACE . '">Test</a>', | |
| + '<a>Test</a>', | |
| + 'Javascript in the href attribute with backspace in middle of a link is completely removed' | |
| + ], | |
| [ | |
| 'a[href|target|rel]', | |
| '<a href="' . implode("\n", str_split(' javascript:')) . '">Test</a>', | |
| public function provideSanitise(): array | |
| '<iframe></iframe>', | |
| 'Javascript with tab elements the src attribute of an iframe is completely removed' | |
| ], | |
| + [ | |
| + 'iframe[src]', | |
| + '<iframe src="' . HTMLEditorSanitiserTest::CHAR_BACKSPACE . 'javascript:alert(0);"></iframe>', | |
| + '<iframe></iframe>', | |
| + 'Javascript in the src attribute of an iframe with a backspace is completely removed' | |
| + ], | |
| [ | |
| 'object[data]', | |
| '<object data="OK"></object>', | |
| public function provideSanitise(): array | |
| '<object></object>', | |
| 'Object with dangerous javascript content in data attribute with quotes is completely removed' | |
| ], | |
| + [ | |
| + 'object[data]', | |
| + '<object data="' . HTMLEditorSanitiserTest::CHAR_BACKSPACE . 'javascript:alert()">', | |
| + '<object></object>', | |
| + 'Object with dangerous javascript content in data attribute with backspace is completely removed' | |
| + ], | |
| [ | |
| 'object[data]', | |
| '<object data="data:text/html;base64,PHNjcmlwdD5hbGVydChkb2N1bWVudC5sb2NhdGlvbik8L3NjcmlwdD4=">', | |