You don't make an app/website secure by deciding on a list of things you need to sanitise.
You sanitise everything to start with.
A very common rookie error.
It would be great if I didn't have to use any Off-the-Shelf code at all, or if I must, if I actually had the time and knowledge to review it for serious vulnerabilities. But posts like this are why I come to HN.
I agree
> You sanitise everything to start with.
So you need to list everything you need to sanitise...
A better approach is to ban "innerHTML" from your code. You should always display user generated text in text nodes.
var t = document.createTextNode(msg);
content.appendChild(t);
That code sanitises all possible content in msg. I don't need to list out HTML tags, script/style tags, do special case for unicode exploits, etc.You need to list what variables are "unsafe", but you don't need to list out the ways they might be unsafe. If it's got the potential to be unsafe, assume it's completely unsafe in every conceivable way, and don't use it in any context apart from as an unsafe text string.
The rookie code is something like:
msg.replace("something I think is unsafe", "something safer");
content.innerHTML+=msg;
And agreed. InnerHTML should be removed from browsers.So it is a bit more complex than that if they want to enable user markup. https://code.google.com/p/pagedown/source/browse/Markdown.Sa... https://code.google.com/p/pagedown/wiki/PageDown
It is [message] -> [parse] -> [sanitize], generally.
A) It was not as simple as you suggested if there was markup involved in the message.
B) They'd have to use a parser and I linked to a parser that sanitizes that was once used in a pretty big network of sites.
I'm uncertain if you misunderstood or are simply agreeing with me in a tone of writing that makes it sound like you disagree.
The safety of widely-deployed Markdown + sanitizer libraries is largely thanks to testing at scale and a history of patches for XSS vulnerabilities.
While it's still the fastest method for changing the page DOM it shouldn't be. When used outside of user inputted scenarios it's fine.
EDIT: Looks like it's CSS, not JS. In case it helps, here's what I'm seeing [1], and here's the code from the message:
[1] http://imgur.com/BoZ6lrFEDIT 2: Yup, style tags don't seem to be escaped. Tried changing colors of the room a few times, and it worked:
EDIT 3: Issue filed here: https://github.com/HashNuke/mogo-chat/issues/2