Implement basic XSS filter

This commit is contained in:
calzoneman 2013-10-31 00:39:35 -05:00
parent bf014530f9
commit 271a23cdad
2 changed files with 187 additions and 0 deletions

16
tests/xss.js Normal file
View file

@ -0,0 +1,16 @@
var sanitize = require('../lib/xss').sanitizeHTML;
var assert = require('assert');
function basicTest() {
assert(sanitize("< script src = bad.js>blah</script>") ===
"[tag removed]blah[tag removed]");
assert(sanitize("< img src=asdf onerror='alert(\"xss\")'>") ===
"<img src=\"asdf\">");
assert(sanitize("<a href='javascript:alert(document.cookie)'>") ===
"<a href=\":()\">");
}
basicTest();
console.log("Tests passed.");