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

false positive 'aaa<bbb' #41

Closed
revelt opened this issue Oct 1, 2017 · 2 comments
Closed

false positive 'aaa<bbb' #41

revelt opened this issue Oct 1, 2017 · 2 comments

Comments

@revelt
Copy link

revelt commented Oct 1, 2017

hi guys,

check this out:

var striptags = require("striptags")
console.log(striptags('aaa<bbb'))
// => aaa

See this on Runkit: https://runkit.com/embed/nfxue95dyxv5

This is wrong isn't it?

@ericnorris
Copy link
Owner

@revelt thanks for reporting! I would not consider this incorrect behavior for three reasons.

One, since the text does not close the opening tag, it is still dangerous HTML. Imagine this:

var striptags = require("striptags")

stripped_input = striptags('aaa<script src="blah" ');

console.log(stripped_input + other_html);

If striptags did not remove the unclosed script tag, then the resulting output could execute JavaScript. Since striptags is a state machine, it will unequivocally remove anything that appears to be a tag.

Two, that < should be HTML-encoded if it is truly plaintext.

Finally, the third reason is that PHP does it this way as well. You can see the behavior yourself here.

@revelt
Copy link
Author

revelt commented Oct 2, 2017

I see your points. The main difference between our thinking is I assume nothing from the input string, it can or can't be HTML, it can be encoded or not. I came looking for a stripping library with these expectations and obviously they didn't match :) I guess I'll have to code up my own library that does what I need. Anyway, thank you for prompt investigation and resolve.

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