File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ unreleased
22==========
33
44 * Send complete HTML document in redirect & error responses
5+ * Set default CSP header in redirect & error responses
56
670.14.2 / 2017-01-23
78===================
Original file line number Diff line number Diff line change @@ -293,6 +293,7 @@ SendStream.prototype.error = function error (status, error) {
293293 res . statusCode = status
294294 res . setHeader ( 'Content-Type' , 'text/html; charset=UTF-8' )
295295 res . setHeader ( 'Content-Length' , Buffer . byteLength ( doc ) )
296+ res . setHeader ( 'Content-Security-Policy' , "default-src 'self'" )
296297 res . setHeader ( 'X-Content-Type-Options' , 'nosniff' )
297298 res . end ( doc )
298299}
@@ -455,6 +456,7 @@ SendStream.prototype.redirect = function redirect (path) {
455456 res . statusCode = 301
456457 res . setHeader ( 'Content-Type' , 'text/html; charset=UTF-8' )
457458 res . setHeader ( 'Content-Length' , Buffer . byteLength ( doc ) )
459+ res . setHeader ( 'Content-Security-Policy' , "default-src 'self'" )
458460 res . setHeader ( 'X-Content-Type-Options' , 'nosniff' )
459461 res . setHeader ( 'Location' , loc )
460462 res . end ( doc )
Original file line number Diff line number Diff line change @@ -342,6 +342,14 @@ describe('send(file).pipe(res)', function () {
342342 . expect ( 301 , / > R e d i r e c t i n g t o < a h r e f = " \/ p e t s \/ " > \/ p e t s \/ < \/ a > < / , done )
343343 } )
344344
345+ it ( 'should respond with default Content-Security-Policy' , function ( done ) {
346+ request ( createServer ( { root : fixtures } ) )
347+ . get ( '/pets' )
348+ . expect ( 'Location' , '/pets/' )
349+ . expect ( 'Content-Security-Policy' , "default-src 'self'" )
350+ . expect ( 301 , done )
351+ } )
352+
345353 it ( 'should not redirect to protocol-relative locations' , function ( done ) {
346354 request ( createServer ( { root : fixtures } ) )
347355 . get ( '//pets' )
@@ -369,6 +377,13 @@ describe('send(file).pipe(res)', function () {
369377 . get ( '/foobar' )
370378 . expect ( 404 , / > N o t F o u n d < / , done )
371379 } )
380+
381+ it ( 'should respond with default Content-Security-Policy' , function ( done ) {
382+ request ( createServer ( { root : fixtures } ) )
383+ . get ( '/foobar' )
384+ . expect ( 'Content-Security-Policy' , "default-src 'self'" )
385+ . expect ( 404 , done )
386+ } )
372387 } )
373388
374389 describe ( 'with conditional-GET' , function ( ) {
You can’t perform that action at this time.
0 commit comments