-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
User assisted XSS #4717
Comments
NetBox's entire logic around rendering Markdown consists of the following: def render_markdown(value):
"""
Render text as Markdown
"""
# Strip HTML tags
value = strip_tags(value)
# Render Markdown
html = markdown(value, extensions=['fenced_code', 'tables'])
return mark_safe(html) As far as I can tell, the Python-Markdown library doesn't provide any mechanisms for filtering hyperlink content. This is a feature that might be requested of the upstream library but IMO is not something that we can reasonably take on in NetBox. |
Hi However please beware of the potentially severe impact to your users. Because this requires user interaction (on the part of a privileged user) the likelihood of this attack is fairly low however the impact can be quite high. Because of the implicit power of the template logic, if a low privileged user can abuse this to escalate to to an account with the ability to add template code (such as 'extras | export template | Can add export template' for example) - s/he can execute arbitrary commands on the server running Netbox. As such I think it might be worth contemplating some form of mitigation if the upstream library either does not plan on issuing a patch or it takes a long time to issue one. |
For referens I filed the following ticket with Python-Markdown: Python-Markdown/markdown#976 |
I understand the risk, however:
Modifying an object requires elevated privileges to begin with. There is no risk from unauthenticated accounts or accounts with read-only permission. Given NetBox's role as an infrastructure management system, it seems reasonable that write access of any kind would be granted only to trusted individuals (as opposed to a publicly-facing application). Addressing this without native support from the Markdown library would require implementing an entire new layer of processing for rendered HTML, e.g. using Bleach. This is non-trivial as it involves the manual whitelisting of allowed tags as well as writing tests to ensure all Markdown rendering remains functional. I'll leave this open for a while to see if anyone wants to volunteer. |
Sounds reasonable. I agree that any user with write access would already enjoy a certain amount of trust and like I said the fact that it requires a privileged user to actively click on the link obviously makes it lowers the risk. |
Perhaps this issue could also be used to gather feedback as well on how exactly our user base interacts with markdown. This would help pin-pointing what should be done with Bleach later on. Also to quote their doc:
So we should keep that in mind... |
Regarding performance, if we adopt anything more complex than the current rendering logic, we'll likely move to saving pre-rendered content in the database alongside the raw content. This would require rendering only at write time. |
Might it be sufficient to just strip out any string matching e.g. |
I ended up introducing the |
Hello again
In my humble opinion this should be easier fixed after the Markdown processor has returned. While sanitising untrusted html is very hard and the reason you should use something like bleach, you actually only have to clean the Markdown output which should produce highly compliant html. I think it would be enough to use pythons html.parser lib for this. I wrote the following test code (which could be written much cleaner I'm sure)
Kind Regards |
It would probably be easier to just tweak the regex to ensure multi-line links are captured. |
That would definitely solve my bypass - the question is whether it fixes all? Because the input before the Markdown parser is untrusted you have to get the regex logic exactly the same as what's used in Markdown or run the risk of a bypass. However I admittedly only found this one bypass.. |
Hi |
ping @jeremystretch |
Perhaps open a new issue with your new specific use-case (It would get more traction)? Are you exposing netbox to untrusted users ? |
We're not exposing our instance to untrusted users - I just figured you wanted to plug up this bypass. You already did the hard work of implementing ALLOWED_URL_SCHEMES, why not just fix the regex and be done with it? I can open a new issue if you want, just figured that was unnecessary noise for what amounts to a one line fix? |
Environment
Steps to Reproduce
[click me for XSS](javascript:alert(1))
Expected Behavior
Javascript URIs to be filtered (or more accurately only http/https URIs to be allowed)
Observed Behavior
User supplied javascript was executed (this could potentially be used to escalate to admin privileges).
The text was updated successfully, but these errors were encountered: