Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ public function preFilter($html, $config, $context)

public static function filter($html)
{
// Strip null bytes before regex matching to prevent bypass via on\x00load patterns
// Strip null bytes before regex matching to prevent bypass via on\x00load patterns.
$html = str_replace("\0", '', $html);
$pattern = '/\s+on\w+\s*=\s*(?:"[^"]*"|\'[^\']*\'|[^\s>]+)/i';
$pattern = '/(?:=\s*(?:"[^"]*"|\'[^\']*\'|[^\s>]+))(*SKIP)(*F)|(?:\s+|\/+|(?<=["\']))on\w+\s*=\s*(?:"[^"]*"|\'[^\']*\'|[^\s>]+)/i';

return preg_replace($pattern, '', $html);
return preg_replace_callback(
'/<(?:[^>"\']+|"[^"]*"|\'[^\']*\')*>/s',
function ($matches) use ($pattern) {
return preg_replace($pattern, '', $matches[0]);
},
$html
);
}
}
Loading