Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:unprintable characters not scrubbed from script tag #124

Closed
bbugh opened this issue Sep 24, 2017 · 3 comments
Closed

:unprintable characters not scrubbed from script tag #124

bbugh opened this issue Sep 24, 2017 · 3 comments

Comments

@bbugh
Copy link

bbugh commented Sep 24, 2017

The unprintable scrubber is not removing unprintables from a script tag. Examples:

def strip_unprintables(raw_content)
  Loofah.fragment(raw_content).scrub!(:unprintable).to_s
end  

# bug: regular tag + script
> strip_unprintables("hack<script>\u2028</script>protected<div>\u2028</div>\u2028")
=> "hack<script>\u2028</script>protected<div></div>"
                ^^^^^^

# bug: forbidden tag + script
> strip_unprintables("hack<script>\u2028</script>protected<div>\u2028</div>\u2028<object>\u2028</object>")
=> "hack<script>\u2028</script>protected<div></div><object></object>"
                ^^^^^^

# bug: other forbidden tag + script
> strip_unprintables("hack<script>\u2028</script>protected<div>\u2028</div>\u2028<iframe>\u2028</iframe>")
=> "hack<script>\u2028</script>protected<div></div><iframe></iframe>"
                ^^^^^^

# bug: when using `strip`
> raw_content = "hack<script>\u2028</script>protected<div>\u2028</div>\u2028<iframe>\u2028</iframe>"
> Loofah.fragment(raw_content).scrub!(:unprintable).scrub!(:strip).to_s
=> "hack\u2028protected<div></div>"
        ^^^^^^

> Loofah.fragment(raw_content).scrub!(:strip).scrub!(:unprintable).to_s
=> "hack\u2028protected<div></div>"
        ^^^^^^

# correct: but `prune` works (in either order)
Loofah.fragment(raw_content).scrub!(:prune).scrub!(:unprintable).to_s
=> "hackprotected<div></div>"
@flavorjones
Copy link
Owner

Great catch. We're not looking at CDATA nodes, which is what a <script> tag contains. Will fix.

@flavorjones
Copy link
Owner

Committed a fix. Will be in the next release.

@flavorjones
Copy link
Owner

This is fixed in v2.1.0 that shipped earlier today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants