-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Escape mod name in mod pack typeahead #388
Escape mod name in mod pack typeahead #388
Conversation
This comment has been minimized.
This comment has been minimized.
2964a09
to
de75d60
Compare
I don't think I agree. Escaping like this can only be done correctly if we know the context where the output will be used, and we don't. The current code assumes an HTML context, but for example the CKAN bot will consume this data and almost never put it into an HTML context. Example of when this can go wrong: Raw / unescaped output makes sense for the API (except for those minimal changes needed to stuff it into JSON, of course). Consumers should apply their own processing as needed. |
Then let's do that instead. Would've been nice because it would've caught all places of possible XSS through data received from the API in one go, now I can only close the one I know about. Btw., there is one place where CKAN's infrastructure blindly takes whatever SpaceDock serves it (although not through the API, but as webhook POST body), and places it into an HTML context: the SpaceDock adder |
01c038e
to
ab4ee73
Compare
ab4ee73
to
9609a18
Compare
Is there any way we can approach this as him having to convince me instead? 😏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, let's go.
You can work it out between the two of you. I just want this huge security issue fixed. |
Problem
While we worked on #384, I also created a mod with a name that contains valid HTML with valid JavaScript.
I was relieved that I didn't find any place where this JavaScript is executed, it looked like we / the browser correctly escapes it everywhere (it does so inside header tags like
<h1>
for example).Well, now I was looking at #380 and trying it out, and it turns out that the typeahead library does not escape HTML in its preview drop down:
You could argue this is a bug in the library, and they did actually fix it in release 0.11.0 (we're at 0.10.2):
But at the same time I'd argue that our API (or at least the frontend that consumes it) should do sanitization as well. After asking in the Discord, VITAS responded that it should be done in the API, HebaruSan favors the frontend.
Changes
Now we run the mod name through a
escape_html()
function, as suggested here on SO, before passing it to the typeahead library to display it.We might also want to update the library at some point, however I spotted breaking changes while looking through the docs, and this library is also unmaintained got 6 years now anyway, so maybe we should switch to something else entirely.
Also the background image link in the mod API response is fixed, after #374 this would've caused the file paths instead of web URLs to be returned.