-
Notifications
You must be signed in to change notification settings - Fork 319
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
Swap out simple-xss for sanitize-html #190
Conversation
Advantages: * **Works** unlike simple-xss * Lots of maintainers/contributors * Smaller than simple-xss * Correctly allows sanitizing text **first** then applying markdown * Optional list is included for current defaults... this **can be removed** but I would feel safer matching it in case something comes down the line we don't like. * Does filter out `javascript:` items just like xss [npm homepage](https://www.npmjs.org/package/sanitize-html) [gh homepage](https://github.com/punkave/sanitize-html) Related: * OpenUserJS#168 * OpenUserJS#125 Tested in dev on [this page](http://localhost:8080/scripts/marti/httplocalhost.localdomain/RFC_2606%C2%A73_-_license_and_licence_Unit_Test)
Everyone please let me know if you want any default tags/attributes removed or added... I personally have never heard of the The goal here is to encourage markdown but still allow some markup since md does have some disadvantages. Does have one issue with highlighting but so does simple-xss... working on this. // *********************
// This code is fenced via gfm and highlighted?
// *********************
var hello = "world"; <html>
<head></head>
<body>
</body>
</html> |
* Swap to markdown first then sanitize-html to allow html code blocks * Allow img tag ... this deviates from their defaults so we need to define our own.
hmmm don't think that last commit is going to generate the DOM correctly if and when highlighting gets fixed. |
For compatibility, use the settings GitHub uses. |
@sizzlemctwizzle |
We don't have anything else (but I could always fork it again). What was the problem with running sanitize before the markdown renderer? |
HTML as denoted in the commit message. This is why I never use |
…ilities even though it doesn't currently work
What happens to the HTML in the code blocks? My working tree is dirty so I can't test right now. |
Totally stripped in code fences and I haven't tried inside a JavaScript block yet... I suppose we could tell them to use pre and code tags and go with intended behavior. Do you really want to support githubs schemes? e.g. |
…) stuff. * Still need to see if sanitize-html has a wildcard
See also: blehh this is going to be lengthy. |
No.
Which it should. This might help if added to function escape(html, encode) {
return html
.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
renderer.code = function (code, lang) {
code = this.options.highlight(escape(code, true), lang);
if (!lang) {
return '<pre><code>' + code + '\n</code></pre>';
}
return '<pre><code class="'
+ this.options.langPrefix
+ escape(lang, true)
+ '">'
+ code
+ '\n</code></pre>\n';
}; Edit: Nvm the code blocks need be escaped before or during HTML sanitization. |
EDIT:
That makes JavaScript code fences look like this:
instead of:
I'm running out of steam for the night but I do want to follow up with this when I get back from the weekend. This should give some time for sanitize-html maintainers to answer a question too. hopefully
This might be what is fubarring the highlighting btw. I noticed a |
* Prepping for when I get back
* Gotta run now
Essentially we've ran into a catch-22. If we sanitize before we render, we strip html inside markdown code blocks (plus the sanitizer is meant for html, not markdown). But if we sanitize after, we lose the highlighted code because of the
It does actually (check the page source to see). We're supposed to escape it before we send it to the highlighter. As far as I can tell, the only solution: markdown (w/ escape code blocks) -> sanitize -> highlight. This might mean that we need to give the markdown library a |
Possibly two pass as well. |
I fixed it. I should have spent more time trying to understand our markdown renderer. |
Okay, so ended up having to individually sanitize the output of the various block level markdown renders (obviously omitting the code one) and now everything seems to work correctly. |
tables + images are broken. https://openuserjs.org/discuss/The_new_layout#comment-146bdc24a14 |
@sizzlemctwizzle |
I've looked at their code and the answer is "no, there isn't". But I've identified the code that could be modified to add the wildcard, so I'll probably submit a PR sometime. Until then, I've added some code to whitelist a list of attributes for all whitelisted tags.
No need to do this by hand. |
PR is NOT COMPLETE... better than what we have and also may have future dependencies
Advantages:
javascript:
items just like simple-xssnpm homepage
gh homepage
Related:
Tested in dev on this page
Additional bug report(s):
MISSING:
Refs: