diff --git a/README.md b/README.md
index 528e01139..36d36f544 100755
--- a/README.md
+++ b/README.md
@@ -34,7 +34,6 @@ var int = sanitize('0123').toInt(); //123
var bool = sanitize('true').toBoolean(); //true
var str = sanitize(' \t\r hello \n').trim(); //'hello'
var str = sanitize('aaaaaaaaab').ltrim('a'); //'b'
-var str = sanitize(large_input_str).xss();
var str = sanitize('<a>').entityDecode(); //''
```
@@ -58,7 +57,6 @@ get('/', function (req, res) {
req.checkHeader('referer').contains('localhost');
//Sanitize user input
- req.sanitize('textarea').xss();
req.sanitize('foo').toBoolean();
//etc.
@@ -130,8 +128,6 @@ toBooleanStrict() //False unless str = '1' or 'true'
entityDecode() //Decode HTML entities
entityEncode()
escape() //Escape &, <, >, and "
-xss() //Remove common XSS attack vectors from user-supplied HTML
-xss(true) //Remove common XSS attack vectors from images
```
## Extending the library
@@ -221,7 +217,6 @@ var errors = validator.getErrors(); // ['Invalid email', 'String is too small']
- [oris](https://github.com/orls) - Added in()
- [mren](https://github.com/mren) - Decoupled rules
- [Thorsten Basse](https://github.com/tbasse) - Cleanup and refinement of existing validators
-- [Neal Poole](https://github.com/nealpoole) - Port the latest xss() updates from CodeIgniter
## LICENSE
diff --git a/lib/filter.js b/lib/filter.js
index f828c33ee..c739d8498 100755
--- a/lib/filter.js
+++ b/lib/filter.js
@@ -1,5 +1,4 @@
var entities = require('./entities');
-var xss = require('./xss');
var Filter = exports.Filter = function() {}
@@ -28,11 +27,6 @@ Filter.prototype.convert = Filter.prototype.sanitize = function(str) {
return this;
}
-Filter.prototype.xss = function(is_image) {
- this.modify(xss.clean(this.str, is_image));
- return this.wrap(this.str);
-}
-
Filter.prototype.entityDecode = function() {
this.modify(entities.decode(this.str));
return this.wrap(this.str);
diff --git a/lib/xss.js b/lib/xss.js
deleted file mode 100755
index 4a2ed9e66..000000000
--- a/lib/xss.js
+++ /dev/null
@@ -1,228 +0,0 @@
-//This module is adapted from the CodeIgniter framework
-//The license is available at http://codeigniter.com/
-
-var html_entity_decode = require('./entities').decode;
-
-var never_allowed_str = {
- 'document.cookie': '[removed]',
- 'document.write': '[removed]',
- '.parentNode': '[removed]',
- '.innerHTML': '[removed]',
- 'window.location': '[removed]',
- '-moz-binding': '[removed]',
- '': '-->',
- '(': '<comment>'
-};
-
-var never_allowed_regex = {
- 'javascript\\s*:': '[removed]',
- 'expression\\s*(\\(|()': '[removed]',
- 'vbscript\\s*:': '[removed]',
- 'Redirect\\s+302': '[removed]',
- "([\"'])?data\\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?": '[removed]'
-};
-
-var non_displayables = [
- /%0[0-8bcef]/g, // url encoded 00-08, 11, 12, 14, 15
- /%1[0-9a-f]/g, // url encoded 16-31
- /[\x00-\x08]/g, // 00-08
- /\x0b/g, /\x0c/g, // 11,12
- /[\x0e-\x1f]/g // 14-31
-];
-
-var compact_words = [
- 'javascript', 'expression', 'vbscript',
- 'script', 'base64', 'applet', 'alert',
- 'document', 'write', 'cookie', 'window'
-];
-
-exports.clean = function(str, is_image) {
-
- //Remove invisible characters
- str = remove_invisible_characters(str);
-
- //Protect query string variables in URLs => 901119URL5918AMP18930PROTECT8198
- var hash;
- do {
- // ensure str does not contain hash before inserting it
- hash = xss_hash();
- } while(str.indexOf(hash) >= 0)
- str = str.replace(/\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)/ig, hash + '$1=$2');
-
- //Validate standard character entities. Add a semicolon if missing. We do this to enable
- //the conversion of entities to ASCII later.
- str = str.replace(/(?[0-9a-z]{2,})([\x00-\x20])*;?/ig, '$1;$2');
-
- //Validate UTF16 two byte encoding (x00) - just as above, adds a semicolon if missing.
- str = str.replace(/(?)([0-9A-F]+);?/ig, '$1$2;');
-
- //Un-protect query string variables
- str = str.replace(new RegExp(hash, 'g'), '&');
-
- //Decode just in case stuff like this is submitted:
- //Google
- try{
- str = decodeURIComponent(str);
- }
- catch(error){
- // str was not actually URI-encoded
- }
-
- //Convert character entities to ASCII - this permits our tests below to work reliably.
- //We only convert entities that are within tags since these are the ones that will pose security problems.
- str = str.replace(/[a-z]+=([\'\"]).*?\1/gi, function(m, match) {
- return m.replace(match, convert_attribute(match));
- });
- str = str.replace(/<\w+.*/gi, function(m) {
- return m.replace(m, html_entity_decode(m));
- });
-
- //Remove invisible characters again
- str = remove_invisible_characters(str);
-
- //Convert tabs to spaces
- str = str.replace('\t', ' ');
-
- //Captured the converted string for later comparison
- var converted_string = str;
-
- //Remove strings that are never allowed
- for (var i in never_allowed_str) {
- str = str.replace(new RegExp(i, "gi"), never_allowed_str[i]);
- }
-
- //Remove regex patterns that are never allowed
- for (var i in never_allowed_regex) {
- str = str.replace(new RegExp(i, 'gi'), never_allowed_regex[i]);
- }
-
- //Compact any exploded words like: j a v a s c r i p t
- // We only want to do this when it is followed by a non-word character
- for (var i = 0, l = compact_words.length; i < l; i++) {
- var spacified = compact_words[i].split('').join('\\s*')+'\\s*';
-
- str = str.replace(new RegExp('('+spacified+')(\\W)', 'ig'), function(m, compat, after) {
- return compat.replace(/\s+/g, '') + after;
- });
- }
-
- //Remove disallowed Javascript in links or img tags
- do {
- var original = str;
-
- if (str.match(/]*?)(>|$)/gi, function(m, attributes, end_tag) {
- var filtered_attributes = filter_attributes(attributes.replace('<','').replace('>',''));
- filtered_attributes = filtered_attributes.replace(/href=.*?(?:alert\(|alert(|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|