Skip to content

Commit 2d5d699

Browse files
committed
Remove the XSS filter.
The xss() function was originally a port of the XSS filter from CodeIgniter. I added it to the library because there wasn't an alternative at the time. Unfortunately I don't have the time or expertise to maintain the XSS filter or keep merging upstream changes. If you need one for your app, I suggest looking at Caja sanitisation engine maintained by Google. (https://code.google.com/p/google-caja/ source/browse/trunk/src/com/google/caja/plugin/html-sanitizer.js) Closes #123, #138, #181, #206, #210, #221, #223, #226, #227, #231, #232
1 parent afd1a45 commit 2d5d699

7 files changed

+3
-482
lines changed

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var int = sanitize('0123').toInt(); //123
3434
var bool = sanitize('true').toBoolean(); //true
3535
var str = sanitize(' \t\r hello \n').trim(); //'hello'
3636
var str = sanitize('aaaaaaaaab').ltrim('a'); //'b'
37-
var str = sanitize(large_input_str).xss();
3837
var str = sanitize('&lt;a&gt;').entityDecode(); //'<a>'
3938
```
4039

@@ -58,7 +57,6 @@ get('/', function (req, res) {
5857
req.checkHeader('referer').contains('localhost');
5958

6059
//Sanitize user input
61-
req.sanitize('textarea').xss();
6260
req.sanitize('foo').toBoolean();
6361

6462
//etc.
@@ -130,8 +128,6 @@ toBooleanStrict() //False unless str = '1' or 'true'
130128
entityDecode() //Decode HTML entities
131129
entityEncode()
132130
escape() //Escape &, <, >, and "
133-
xss() //Remove common XSS attack vectors from user-supplied HTML
134-
xss(true) //Remove common XSS attack vectors from images
135131
```
136132

137133
## Extending the library
@@ -221,7 +217,6 @@ var errors = validator.getErrors(); // ['Invalid email', 'String is too small']
221217
- [oris](https://github.com/orls) - Added in()
222218
- [mren](https://github.com/mren) - Decoupled rules
223219
- [Thorsten Basse](https://github.com/tbasse) - Cleanup and refinement of existing validators
224-
- [Neal Poole](https://github.com/nealpoole) - Port the latest xss() updates from CodeIgniter
225220

226221
## LICENSE
227222

lib/filter.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var entities = require('./entities');
2-
var xss = require('./xss');
32

43
var Filter = exports.Filter = function() {}
54

@@ -28,11 +27,6 @@ Filter.prototype.convert = Filter.prototype.sanitize = function(str) {
2827
return this;
2928
}
3029

31-
Filter.prototype.xss = function(is_image) {
32-
this.modify(xss.clean(this.str, is_image));
33-
return this.wrap(this.str);
34-
}
35-
3630
Filter.prototype.entityDecode = function() {
3731
this.modify(entities.decode(this.str));
3832
return this.wrap(this.str);

lib/xss.js

-228
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"description" : "Data validation, filtering and sanitization for node.js",
33
"version" : "1.5.1",
44
"homepage" : "http://github.com/chriso/node-validator",
5-
"keywords" : ["validator", "validation", "assert", "params", "sanitization", "xss", "entities", "sanitize", "sanitisation", "input"],
5+
"keywords" : ["validator", "validation", "assert", "params", "sanitization", "entities", "sanitize", "sanitisation", "input"],
66
"author" : "Chris O'Hara <[email protected]>",
77
"main" : "./lib",
88
"directories" : { "lib" : "./lib" },

test/filter.test.js

-33
Original file line numberDiff line numberDiff line change
@@ -132,39 +132,6 @@ module.exports = {
132132
assert.equal('&frac12;', Filter.sanitize('½').entityEncode());
133133
},
134134

135-
'test #xss()': function () {
136-
//Need more tests!
137-
assert.equal('[removed] foobar', Filter.sanitize('javascript : foobar').xss());
138-
assert.equal('[removed] foobar', Filter.sanitize('j a vasc ri pt: foobar').xss());
139-
assert.equal('<a >some text</a>', Filter.sanitize('<a href="javascript:alert(\'xss\')">some text</a>').xss());
140-
141-
assert.equal('<s <> <s >This is a test</s>', Filter.sanitize('<s <onmouseover="alert(1)"> <s onmouseover="alert(1)">This is a test</s>').xss());
142-
assert.equal('<a >">test</a>', Filter.sanitize('<a href="javascriptJ a V a S c R iPt::alert(1)" "<s>">test</a>').xss());
143-
assert.equal('<div ><h1>You have won</h1>Please click the link and enter your login details: <a href="http://example.com/">http://good.com</a></div>', Filter.sanitize('<div style="z-index: 9999999; background-color: green; width: 100%; height: 100%"><h1>You have won</h1>Please click the link and enter your login details: <a href="http://example.com/">http://good.com</a></div>').xss());
144-
assert.equal('<scrRedirec[removed]t 302ipt type="text/javascript">prompt(1);</scrRedirec[removed]t 302ipt>', Filter.sanitize('<scrRedirecRedirect 302t 302ipt type="text/javascript">prompt(1);</scrRedirecRedirect 302t 302ipt>').xss());
145-
assert.equal('<img src="a" ', Filter.sanitize('<img src="a" onerror=\'eval(atob("cHJvbXB0KDEpOw=="))\'').xss());
146-
147-
148-
// Source: http://blog.kotowicz.net/2012/07/codeigniter-210-xssclean-cross-site.html
149-
assert.equal('<img src=">" >', Filter.sanitize('<img/src=">" onerror=alert(1)>').xss());
150-
assert.equal('<button a=">" autofocus ></button>', Filter.sanitize('<button/a=">" autofocus onfocus=alert&#40;1&#40;></button>').xss());
151-
assert.equal('<button a=">" autofocus >', Filter.sanitize('<button a=">" autofocus onfocus=alert&#40;1&#40;>').xss());
152-
assert.equal('<a target="_blank">clickme in firefox</a>', Filter.sanitize('<a target="_blank" href="data:text/html;BASE64youdummy,PHNjcmlwdD5hbGVydCh3aW5kb3cub3BlbmVyLmRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5pbm5lckhUTUwpPC9zY3JpcHQ+">clickme in firefox</a>').xss());
153-
assert.equal('<a/\'\'\' target="_blank" href=[removed]PHNjcmlwdD5hbGVydChvcGVuZXIuZG9jdW1lbnQuYm9keS5pbm5lckhUTUwpPC9zY3JpcHQ+>firefox11</a>', Filter.sanitize('<a/\'\'\' target="_blank" href=data:text/html;;base64,PHNjcmlwdD5hbGVydChvcGVuZXIuZG9jdW1lbnQuYm9keS5pbm5lckhUTUwpPC9zY3JpcHQ+>firefox11</a>').xss());
154-
155-
var url = 'http://www.example.com/test.php?a=b&b=c&c=d';
156-
assert.equal(url, Filter.sanitize(url).xss());
157-
},
158-
159-
'test chaining': function () {
160-
assert.equal('&amp;amp;amp;', Filter.sanitize('&').chain().entityEncode().entityEncode().entityEncode().value());
161-
162-
//Return the default behaviour
163-
Filter.wrap = function (str) {
164-
return str;
165-
}
166-
},
167-
168135
'test #escape': function () {
169136
assert.equal('&amp;&lt;&quot;&gt;', Filter.sanitize('&<">').escape());
170137
}

0 commit comments

Comments
 (0)