@@ -4,7 +4,8 @@ XSS.InjectionChecker = (async () => {
44 "/lib/Base64.js" ,
55 "/lib/Timing.js" ,
66 "/xss/FlashIdiocy.js" ,
7- "/xss/ASPIdiocy.js" ]
7+ "/xss/ASPIdiocy.js" ,
8+ "/lib/he.js" ]
89 ) ;
910
1011 var { FlashIdiocy, ASPIdiocy} = XSS ;
@@ -1030,9 +1031,8 @@ XSS.InjectionChecker = (async () => {
10301031 if ( await this . checkHTML ( s ) || await this . checkJS ( s ) || this . checkSQLI ( s ) || this . checkHeaders ( s ) )
10311032 return true ;
10321033
1033- if ( s . indexOf ( "&" ) !== - 1 ) {
1034- let unent = await Entities . convertAll ( s ) ;
1035- if ( unent !== s && await this . _checkRecursive ( unent , depth ) ) return true ;
1034+ if ( await this . _checkEntities ( s , depth ) ) {
1035+ return true ;
10361036 }
10371037
10381038 if ( -- depth <= 0 )
@@ -1050,8 +1050,7 @@ XSS.InjectionChecker = (async () => {
10501050 return true ;
10511051
10521052 if ( / [ \u0000 - \u001f ] | & # / . test ( unescaped ) ) {
1053- let unent = await Entities . convertAll ( unescaped . replace ( / [ \u0000 - \u001f ] + / g, '' ) ) ;
1054- if ( unescaped != unent && await this . _checkRecursive ( unent , depth ) ) {
1053+ if ( await this . _checkEntities ( unescaped , depth , u => u . replace ( / [ \u0000 - \u001f ] + / g, '' ) ) ) {
10551054 this . log ( "Trash-stripped nested URL match!" ) ;
10561055 return true ;
10571056 }
@@ -1089,6 +1088,19 @@ XSS.InjectionChecker = (async () => {
10891088 return false ;
10901089 } ,
10911090
1091+ async _checkEntities ( s , depth , preTransform = null ) {
1092+ if ( ! ( preTransform || s . includes ( "&" ) ) ) return false ;
1093+ let value = preTransform ? preTransform ( s ) : s ;
1094+ for ( let opts = { isAttributeValue : true } ; ; opts . isAttributeValue = false ) {
1095+ let heDecoded = he . decode ( value , opts ) ;
1096+ if ( heDecoded !== s && await this . _checkRecursive ( heDecoded , depth ) ) {
1097+ return true ;
1098+ }
1099+ if ( ! ( opts . isAttributeValue && heDecoded . includes ( "&" ) ) ) break ;
1100+ }
1101+ return false ;
1102+ } ,
1103+
10921104 _checkOverDecoding : function ( s , unescaped ) {
10931105 if ( / % [ 8 - 9 a - f ] / i. test ( s ) ) {
10941106 const rx = / [ < ' " ] / g;
0 commit comments