@@ -106,7 +106,7 @@ describe('res', function(){
106106. set ( 'Accept' , 'text/html' )
107107. expect ( 'Content-Type' , / h t m l / )
108108. 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 )
110110} )
111111
112112it ( 'should escape the url' , function ( done ) {
@@ -122,9 +122,27 @@ describe('res', function(){
122122. set ( 'Accept' , 'text/html' )
123123. expect ( 'Content-Type' , / h t m l / )
124124. 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 )
126126} )
127127
128+ it ( 'should not render evil javascript links in anchor href (prevent XSS)' , function ( done ) {
129+ var app = express ( ) ;
130+ var xss = '#"diff-71d08e453c986a86b96dcbb60125d64576700c40f2eb7f758ca2377dfefa0be4-127-131-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
131+ var encodedXss = '#"diff-71d08e453c986a86b96dcbb60125d64576700c40f2eb7f758ca2377dfefa0be4-127-132-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
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+
128146it ( 'should include the redirect type' , function ( done ) {
129147var app = express ( ) ;
130148
@@ -137,7 +155,7 @@ describe('res', function(){
137155. set ( 'Accept' , 'text/html' )
138156. expect ( 'Content-Type' , / h t m l / )
139157. 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 ) ;
141159} )
142160} )
143161