Skip to content

Escape inline event attributes instead of remove them #4

@edlmo

Description

@edlmo

Hi,
I found myself on this situation where I have a valid non executable HTML with inline events, which were removed by the filter. At first sight this should be the expected behavior, but in my case I'm using the filter on user input data that documents HTML code, so these events are expected if the affected tags are inside of <pre> or <code> ones.

I believe this line https://github.com/MasterRO94/laravel-xss-filter/blob/master/src/Cleaner.php#L74 can be safely replace with

$string = preg_replace_callback($this->invalidHtmlInlineListenersPattern, [$this, 'escapeEqualSign'], $string);

// ...
protected function escapeEqualSign(array $matches): string
	{
		return str_replace('=', '&#x3d;', $matches[0]);
	}

But I'm not sure about how to prevent the javascript:code attack using escaped replacements.
Let me know what do you think and if you believe this is enough to propose a pull request (or feel free to apply the changes directly if you like).

BTW, thanks for your work on this middleware.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions