Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Tests/InputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2048,4 +2048,17 @@ public function testCleanObject()

$this->assertEquals($expected, $filter->clean($object));
}

/**
* A tab inside the scheme must not slip a data:text/html URI past the attribute filter,
* as browsers strip tab/newline characters when parsing a URL.
*/
public function testCleanStripsTabbedHtmlDataUri()
{
$filter = new InputFilter(['a'], ['href']);

$input = "<a href=\"data:text/\thtml;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==\">Data link</a>";

$this->assertSame('<a>Data link</a>', $filter->clean($input, 'html'));
}
}
4 changes: 2 additions & 2 deletions src/InputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
*/
if (
(!preg_match('/^[a-z][a-z0-9]*$/i', $tagName))
|| (!$tagName)

Check failure on line 391 in src/InputFilter.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Negated boolean expression is always false.
|| ((\in_array(strtolower($tagName), $this->blockedTags)) && $this->xssAuto)
) {
$postTag = substr($postTag, ($tagLength + 2));
Expand Down Expand Up @@ -586,8 +586,8 @@
// Strips unicode, hex, etc
$attrSubSet[1] = str_replace('&#', '', $attrSubSet[1]);

// Strip normal newline within attr value
$attrSubSet[1] = preg_replace('/[\n\r]/', '', $attrSubSet[1]);
// Strip tab and newline within attr value (browsers drop these when parsing a URL)
$attrSubSet[1] = preg_replace('/[\t\n\r]/', '', $attrSubSet[1]);

// Strip double quotes
$attrSubSet[1] = str_replace('"', '', $attrSubSet[1]);
Expand Down
Loading