@@ -106,7 +106,7 @@ describe('res', function(){
106
106
. set ( 'Accept' , 'text/html' )
107
107
. expect ( 'Content-Type' , / h t m l / )
108
108
. expect ( 'Location' , 'http://google.com' )
109
- . expect ( 302 , '<p>Found. Redirecting to <a href=" http://google.com">http://google.com</a> </p>' , done )
109
+ . expect ( 302 , '<p>Found. Redirecting to http://google.com</p>' , done )
110
110
} )
111
111
112
112
it ( 'should escape the url' , function ( done ) {
@@ -122,9 +122,27 @@ describe('res', function(){
122
122
. set ( 'Accept' , 'text/html' )
123
123
. expect ( 'Content-Type' , / h t m l / )
124
124
. expect ( 'Location' , '%3Cla\'me%3E' )
125
- . expect ( 302 , '<p>Found. Redirecting to <a href=" %3Cla'me%3E">%3Cla'me%3E</a> </p>' , done )
125
+ . expect ( 302 , '<p>Found. Redirecting to %3Cla'me%3E</p>' , done )
126
126
} )
127
127
128
+ it ( 'should not render evil javascript links in anchor href (prevent XSS)' , function ( done ) {
129
+ var app = express ( ) ;
130
+ var xss = 'javascript:eval(document.body.innerHTML=`<p>XSS</p>`);' ;
131
+ var encodedXss = 'javascript:eval(document.body.innerHTML=%60%3Cp%3EXSS%3C/p%3E%60);' ;
132
+
133
+ app . use ( function ( req , res ) {
134
+ res . redirect ( xss ) ;
135
+ } ) ;
136
+
137
+ request ( app )
138
+ . get ( '/' )
139
+ . set ( 'Host' , 'http://example.com' )
140
+ . set ( 'Accept' , 'text/html' )
141
+ . expect ( 'Content-Type' , / h t m l / )
142
+ . expect ( 'Location' , encodedXss )
143
+ . expect ( 302 , '<p>Found. Redirecting to ' + encodedXss + '</p>' , done ) ;
144
+ } ) ;
145
+
128
146
it ( 'should include the redirect type' , function ( done ) {
129
147
var app = express ( ) ;
130
148
@@ -137,7 +155,7 @@ describe('res', function(){
137
155
. set ( 'Accept' , 'text/html' )
138
156
. expect ( 'Content-Type' , / h t m l / )
139
157
. expect ( 'Location' , 'http://google.com' )
140
- . expect ( 301 , '<p>Moved Permanently. Redirecting to <a href=" http://google.com">http://google.com</a> </p>' , done ) ;
158
+ . expect ( 301 , '<p>Moved Permanently. Redirecting to http://google.com</p>' , done ) ;
141
159
} )
142
160
} )
143
161
0 commit comments