File tree Expand file tree Collapse file tree 3 files changed +4
-0
lines changed
Expand file tree Collapse file tree 3 files changed +4
-0
lines changed Original file line number Diff line number Diff line change 1+ - Security/Media route: add ` X-Content-Type-Options: nosniff ` header regression assertions for successful and not-found media responses (#30356 ) (thanks @13otKmdr )
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ describe("media server", () => {
6161 const file = await writeMediaFile ( "file1" , "hello" ) ;
6262 const res = await fetch ( mediaUrl ( "file1" ) ) ;
6363 expect ( res . status ) . toBe ( 200 ) ;
64+ expect ( res . headers . get ( "x-content-type-options" ) ) . toBe ( "nosniff" ) ;
6465 expect ( await res . text ( ) ) . toBe ( "hello" ) ;
6566 await waitForFileRemoval ( file ) ;
6667 } ) ;
@@ -113,6 +114,7 @@ describe("media server", () => {
113114 it ( "returns not found for missing media IDs" , async ( ) => {
114115 const res = await fetch ( mediaUrl ( "missing-file" ) ) ;
115116 expect ( res . status ) . toBe ( 404 ) ;
117+ expect ( res . headers . get ( "x-content-type-options" ) ) . toBe ( "nosniff" ) ;
116118 expect ( await res . text ( ) ) . toBe ( "not found" ) ;
117119 } ) ;
118120
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ export function attachMediaRoutes(
3333 const mediaDir = getMediaDir ( ) ;
3434
3535 app . get ( "/media/:id" , async ( req , res ) => {
36+ res . setHeader ( "X-Content-Type-Options" , "nosniff" ) ;
3637 const id = req . params . id ;
3738 if ( ! isValidMediaId ( id ) ) {
3839 res . status ( 400 ) . send ( "invalid path" ) ;
You can’t perform that action at this time.
0 commit comments