views:

128

answers:

3

Hi all,

Any idea how one would go about preventing XSS attacks on a node.js app? Any libs out there that handle removing javascript in hrefs, onclick attributes,etc. from POSTed data?

I don't want to have to write a regex for all that :)

Any suggestions?

A: 

One of the answers to Sanitize/Rewrite HTML on the Client Side suggests borrowing the whitelist-based HTML sanitizer in JS from Google Caja which, as far as I can tell from a quick scroll-through, implements an HTML SAX parser without relying on the browser's DOM.

Update: Also, keep in mind that the Caja sanitizer has apparently been given a full, professional security review while regexes are known for being very easy to typo in security-compromising ways.

ssokolow
Thanks, I've got it basically figured out with regex (yuck) - but I'd love to look into creating a connect middle-ware to sanitize all params.
Techwraith
A: 

You can also look at EASPI (http://www.owasp.org/index.php/EASPI). There is a javascript version of the library. It's pretty sturdy.

jeandenis
A: 

I've created a module that bundles the Caja HTML Sanitizer

npm install sanitizer

http://github.com/theSmaw/Caja-HTML-Sanitizer

Feedback appreciated.

theSmaw
I'll take a look, thanks!
Techwraith