File tree Expand file tree Collapse file tree 2 files changed +33
-17
lines changed Expand file tree Collapse file tree 2 files changed +33
-17
lines changed Original file line number Diff line number Diff line change 1
- var utils = require ( './utils' ) ,
2
- stringSaveRE = / " (?: [ ^ " \\ ] | \\ .) * " | ' (?: [ ^ ' \\ ] | \\ .) * ' / g,
1
+ var utils = require ( './utils' ) ,
2
+ stringSaveRE = / " (?: [ ^ " \\ ] | \\ .) * " | ' (?: [ ^ ' \\ ] | \\ .) * ' / g,
3
3
stringRestoreRE = / " ( \d + ) " / g,
4
- constructorRE = / ( ^ | \. ) c o n s t r u c t o r \( /
4
+ constructorRE = new RegExp ( 'constructor' . split ( '' ) . join ( '[\'"+, ]*' ) ) ,
5
+ unicodeRE = / \\ u \d \d \d \d /
5
6
6
7
// Variable extraction scooped from https://github.com/RubyLouvre/avalon
7
8
@@ -110,7 +111,8 @@ module.exports = {
110
111
* created as bindings.
111
112
*/
112
113
parse : function ( exp , compiler ) {
113
- if ( constructorRE . test ( exp ) ) {
114
+ // unicode and 'constructor' are not allowed for XSS security.
115
+ if ( unicodeRE . test ( exp ) || constructorRE . test ( exp ) ) {
114
116
utils . warn ( 'Unsafe expression: ' + exp )
115
117
return function ( ) { }
116
118
}
Original file line number Diff line number Diff line change @@ -112,20 +112,34 @@ describe('UNIT: Expression Parser', function () {
112
112
113
113
} )
114
114
115
- describe ( 'Basic XSS protection' , function ( ) {
115
+ describe ( 'XSS protection' , function ( ) {
116
116
117
- var cases = [ {
118
- xss : true ,
119
- exp : "constructor.constructor('alert(1)')()" ,
120
- vm : { } ,
121
- expectedValue : undefined
122
- } ,
123
- {
124
- xss : true ,
125
- exp : "\"\".toString.constructor.constructor('alert(1)')()" ,
126
- vm : { } ,
127
- expectedValue : undefined
128
- } ]
117
+ var cases = [
118
+ {
119
+ xss : true ,
120
+ exp : "constructor.constructor('alert(1)')()" ,
121
+ vm : { } ,
122
+ expectedValue : undefined
123
+ } ,
124
+ {
125
+ xss : true ,
126
+ exp : "\"\".toString.constructor.constructor('alert(1)')()" ,
127
+ vm : { } ,
128
+ expectedValue : undefined
129
+ } ,
130
+ {
131
+ xss : true ,
132
+ exp : "\"\".toString['cons' + 'tructor']['cons' + 'tructor']('alert(1)')()" ,
133
+ vm : { } ,
134
+ expectedValue : undefined
135
+ } ,
136
+ {
137
+ xss : true ,
138
+ exp : "\"\".toString['\\u0063ons' + 'tructor']['\\u0063ons' + 'tructor']('alert(1)')()" ,
139
+ vm : { } ,
140
+ expectedValue : undefined
141
+ }
142
+ ]
129
143
130
144
cases . forEach ( describeCase )
131
145
You can’t perform that action at this time.
0 commit comments