-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Security question: Use HTML by default for Toasts/Tooltips/Autocomplete and expose an XSS #6286
Comments
If it needs to support custom content, it could take HTMLElement as argument. That's better than taking string as argument and then rendering it as HTML. |
@FINDarkside, I'm agree with you but in 80% of use case you will use text. If you present your example with html content by defaut, all developer will use it. Sanitize input parameters is an another subject. If we had the choice between html or text, it can be well but with a toast/tooltips, we have just html option. So include a vulnerability by default. |
I see no XSS here. If you have a found a real XSS with a PoC, please directly contact @Dogfalo in private (responsible disclosure). |
@DanielRuf to be honest, what is a XSS for you?
On my first post you have a POC for each component. I can execute a JavaScript, it's a XSS. MaterializeCss use by default HTML and for me it's a lack of security. You want use a content HTML, you must sanitizes datas.
The problem for me about toasts, it's the documentation. all examples used
Why use html for all examples and after to have an exemple for the Custom HTML. I'm a developer, I copy paste this simple example with the html parameter and I added a vulnerability in my project. For a static value it isn't a problem, for a dynamic value... If you want allow html, sanitaze "inputs datas", if you want use a trust content, you can use this syntaxe :
https://www.npmjs.com/package/sanitize-html Bootstrap do this:
It's explained in the documentation
How can I disable html content? For me it's HTML only.
Same story, if you allow unsafe html, you can inject javascript...
If you check XSS for bootstrap, you have the same problem and it doesn't allow an unsafe html |
Sorry but this is not how XSS works. Show me a codepen with a default setup of our components which parse user input from a default field or the URL. So far devs have to ensure what the data is allowed to contain and sanitize it. |
User input can not create a malicious data object like you have shown. Using the console does not show that there is a real XSS vuln as this is not user controlled input (form fields, addressbar, ...). |
Reflected XSS is for example this: Enter HTML and JS into search form. |
This is exactly how XSS works. If you, for example do auto completion on user search, you can do XSS by naming your user properly. But as you've said, might not be the best idea to talk about this here, I've made a PoC and reported it to npm. They'll contact the package owner if they deem it to be XSS. You don't have to form any objects, the malicious input in the example by @lucianot54 is a string. |
No, there is no real direct input. Still, no real XSS when a dev allows user input to be unsanitized in the output. |
What is a Real XSS? You are confuse with a vulnerability and an exploitability.
Also, Do you want a use case to exploit this vulnerability? |
Of course it is, because it's completely clear that the searchable input should be rendered as text instead of html. And Materializecss is what handles the output, so by your definition this is a vulnerability. There's nothing wrong with the input, there's lot of wrong on how autocomplete handles the input. I'm not going to argue about this anymore as it doesn't really matter, I've already made the report with PoC. What comes to sanitizing the input, it's actually not possible to do without breaking the auto completion. |
To be clear, it is intended that we support HTML there. We do not explicitely filter or sanitize it. If you use any user input in there you should ensure to sanitize any user input in general. As this is not the normal use case the sanitizing part is out of the projects scope imo. Sure you can trigger this manually with malicious snippets like you demonstrated. But when such code can be executed through UI interactions you have a much bigger issue (no X-XSS header, no WAF and sanitization rules and so on). |
It's actually very clear that it's not supposed to support HTML, as it indeed does not (XSS is possible though), HTML tags will break the auto completion. And it also makes no sense, as the search is performed on your whole input, which makes no sense if it's meant to be HTML. WAF nor X-XSS also have nothing to do with this and can't prevent this. And as I already said, the input can't be sanitized in a way that auto completion works properly. The right side of input is supposed to be url. Are you really claiming that it's intended to be rendered as html, inside a img source attribute? The only use case for rendering string as html inside img tag source attribute is to do XSS attack. There's no reason for developers to expect that this library handles input that's supposed to be url as html. Would you say that if materialize ran the input trough eval it would also be users fault for not sanitizing the input?
Doubt this is the "official" opinion. And if it were, the readme will need a big warning about it. |
Well, this is valid HTML an there are many attributes and things to sanitize.
These do prevent reflected XSS. Reflected (not stored) XSS is about user controllable input (and its output).
|
We do not know and can not know how you process and use user input. 0.x will not get any updates anymore and 1.0 dev is a bit paused at the moment. |
This is how you render text (with jquery as done in autocomplete)
Again, this is not about how "we" handle input, it's about how materialize handles input. If something is supposed to be url, it's reasonable to expect that it'll be handled as text instead of html. If something is supposed to be string to be auto completed, it's reasonable to expect it'll be handled as text instead of html.
Yes, but you're the only one who's talking about Reflected XSS. Besides you're not supposed to rely on X-XSS, it's just a safe guard. If it saves you from something, you have done something seriously wrong. |
Well, I did not, see #6286 (comment) Anyway, this will not be fixed in 0.x, and probably also not in 1.x as far as I can say. |
Okay, thanks for the input. Also, I was only talking about the case with autocomplete, where it's not expected that the input is handled as html. With toasts it's obviously completely clear as you have to supply an object with html field. |
And to make this clear again: https://materializecss.com/toasts.html To rephrase you:
|
If you use blacklist yes it's impossible, if you use a white list,it's possible. OR sanitaze by default and if you want use a safe HTML. You can allow it with a parameter. Angular(not angularjs) is 100% safe because it escape all by default.
YES but that's a reason to keep a vulnerability? It's a library not your custom website. Everybody doesn't know what is a XSS. So HTTP Headers (x-xss-protection/Content-Security-Policy) or a WAF...
An XSS is always output, you change the dom and update the html,if you have a script, you execute a XSS. And to protect output, you need control input...
You can...
Just 3 options with flexibility and security
If you allow XSS, it's ok for me, but MaterializeCSS need a CVE to explain that publicly |
There is 0 example without html and the result of the community: Use HTML is a feature, with risk but a feature. Why present him like a default usage? for autocompletion, MaterializeCSS have an XSS on a image source. Explain me, why allow a html in a SRC from the tag |
You need sanitizer only if you want to allow subset of html. It's way easier you intend to just render it as text, since you just use $.text or |
Hi folks, Liran from Snyk and The Node.js Security WG chiming in here 👋 Appreciate the detailed report @lucianot54 and @FINDarkside's elaborate reasoning as well. There is definitely merit here, and I wanted to share my own as well to see if we can get to an alignment. As for the Toast related vulnerability
I believe that there’s room to create a more secure API by default with either encoding by default (with an opt out) as was suggested, or creating another property altogether Regardless of whether the APIs will change or not, which is at the discretion of the maintainer and their time to handle this, at the very least the maintainer should add a very clear and obvious security disclosure in the docs and README to make users aware of the dangers and pitfalls of using the insecure For autocomplete and tooltip related vulnerabilityI believe there is indeed a case for valid vulnerabilities in these as it is completely not obvious that HTML is allowed there, plus not sure it makes too much sense either, and I don't think the maintainers have intended for users to put HTML there. Would require @DanielRuf's assessment on that. -- EDIT: also want to invite @MarcinHoppe my colleague from the WG to see if he has similar or different opinions on this. |
Thanks for your input! The main thing which points that autocomplete rendering html is not intentional, is that you have to actually escape all html characters to render them as html. All the html tags will be stripped in _hihlight function, so |
@FINDarkside completely agree. |
Hi @FINDarkside, However, we will make a change to sanitize html input for all 3 of the components to help protect developers who haven't sanitized their inputs. |
This is still reported here https://www.npmjs.com/advisories/818 on npm as moderate vulnerability, that means Github and npm will keep popping up the security issue. @Dogfalo any idea when we can expect the fix for this ? |
Does this really apply if we aren't using the Exa. import { updateTextFields } from 'materialize-css'; Also, it's been a month. Any fix coming some time soon, or would someone want to work with me on a PR to do so? |
Probably not.
A PR is very welcome but as mentioned before this would be a breaking change. Also only v1.x is further developed. Developers can already filter user input in their code using available solutions. |
Expected Behavior
Don't execute html/javascript by default for Toasts, Tooltips and Autocomplete
Current Behavior
By default when you add dynamics contents like Toast, Tooltips and autocomplete you inject inputs data as HTML. I think all people who use MaterializeCss implement compontents like your examples.
It's a bad practice and by default, your input data could be sanitize or use jquery.text('untrustData') instead jquery.html('untrustData') or innerHTML = 'untrustData'.
Possible Solution
If you want allow HTML, why not but sanitize the html and don't allow javascript. If the end user want allow HTML and javascript add a new configuration with a parameter like
options : { allowUnsafeData: true }
Steps to Reproduce (for bugs)
Toast
Tooltips
<a class="btn tooltipped" data-position="bottom" data-tooltip="<IFRAME SRC='javascript:alert(document.cookie);'></IFRAME></script>">Hover me!</a>
Autocomplete
Context
I'm agree about the developper need control his data before inject it in a third party library but sametime we forget to do it.
How i find this case :
It's my fault, I didn't validate datas and I returned this script without sanitize. If by default your library don't allow html, I will not find this behavior.
Your Environment
The text was updated successfully, but these errors were encountered: