@@ -360,7 +360,7 @@ describe('File HTTP API', () => {
360360 . expect ( 200 ) ;
361361
362362 const { body : buffer , header } = await request
363- // By providing a file name like "myfilename.pdf" we imply that we want a pdf
363+ // "myfilename.pdf" has a mime type that matches the metadata
364364 . get ( root , `/api/files/public/blob/myfilename.pdf?token=${ token } ` )
365365 . set ( 'x-elastic-internal-origin' , 'files-test' )
366366 . buffer ( )
@@ -377,7 +377,6 @@ describe('File HTTP API', () => {
377377 mimeType : 'application/pdf' ,
378378 } ) ;
379379
380- // Share the file
381380 const {
382381 body : { token } ,
383382 } = await request
@@ -386,7 +385,6 @@ describe('File HTTP API', () => {
386385 . send ( { } )
387386 . expect ( 200 ) ;
388387
389- // Upload content
390388 await request
391389 . put ( root , `/api/files/files/${ fileKind } /${ id } /blob` )
392390 . set ( 'Content-Type' , 'application/octet-stream' )
@@ -409,7 +407,6 @@ describe('File HTTP API', () => {
409407 mimeType : 'image/png' ,
410408 } ) ;
411409
412- // Share the file
413410 const {
414411 body : { token } ,
415412 } = await request
@@ -418,7 +415,6 @@ describe('File HTTP API', () => {
418415 . send ( { } )
419416 . expect ( 200 ) ;
420417
421- // Upload content
422418 await request
423419 . put ( root , `/api/files/files/${ fileKind } /${ id } /blob` )
424420 . set ( 'Content-Type' , 'application/octet-stream' )
@@ -444,7 +440,6 @@ describe('File HTTP API', () => {
444440 mimeType : 'text/plain' ,
445441 } ) ;
446442
447- // Share the file
448443 const {
449444 body : { token } ,
450445 } = await request
@@ -453,7 +448,6 @@ describe('File HTTP API', () => {
453448 . send ( { } )
454449 . expect ( 200 ) ;
455450
456- // Upload content
457451 await request
458452 . put ( root , `/api/files/files/${ fileKind } /${ id } /blob` )
459453 . set ( 'Content-Type' , 'application/octet-stream' )
@@ -468,8 +462,6 @@ describe('File HTTP API', () => {
468462 . buffer ( )
469463 . expect ( 200 ) ;
470464
471- // Content-type comes from stored file MIME type, not URL filename
472- // Should be either the stored MIME type or default fallback - but never from URL filename
473465 expect ( [ 'text/plain' , 'text/plain; charset=utf-8' , 'application/octet-stream' ] ) . toContain (
474466 header [ 'content-type' ]
475467 ) ;
@@ -482,7 +474,6 @@ describe('File HTTP API', () => {
482474 mimeType : 'image/jpeg' ,
483475 } ) ;
484476
485- // Share the file
486477 const {
487478 body : { token } ,
488479 } = await request
@@ -491,7 +482,6 @@ describe('File HTTP API', () => {
491482 . send ( { } )
492483 . expect ( 200 ) ;
493484
494- // Upload content
495485 await request
496486 . put ( root , `/api/files/files/${ fileKind } /${ id } /blob` )
497487 . set ( 'Content-Type' , 'application/octet-stream' )
@@ -517,7 +507,6 @@ describe('File HTTP API', () => {
517507 mimeType : 'text/plain' ,
518508 } ) ;
519509
520- // Share the file
521510 const {
522511 body : { token } ,
523512 } = await request
@@ -526,7 +515,6 @@ describe('File HTTP API', () => {
526515 . send ( { } )
527516 . expect ( 200 ) ;
528517
529- // Upload content
530518 await request
531519 . put ( root , `/api/files/files/${ fileKind } /${ id } /blob` )
532520 . set ( 'Content-Type' , 'application/octet-stream' )
@@ -542,8 +530,6 @@ describe('File HTTP API', () => {
542530 . buffer ( )
543531 . expect ( 200 ) ;
544532
545- // Content-type comes from stored file MIME type, not URL filename
546- // Note: Text files may include charset information
547533 expect ( response . header [ 'content-type' ] ) . toMatch ( / ^ t e x t \/ p l a i n ( ; c h a r s e t = u t f - 8 ) ? $ / ) ;
548534
549535 // For text content with .buffer(), use response.text instead of response.body
@@ -563,7 +549,6 @@ describe('File HTTP API', () => {
563549 mimeType : 'application/json' ,
564550 } ) ;
565551
566- // Share the file
567552 const {
568553 body : { token } ,
569554 } = await request
@@ -572,7 +557,6 @@ describe('File HTTP API', () => {
572557 . send ( { } )
573558 . expect ( 200 ) ;
574559
575- // Upload content
576560 await request
577561 . put ( root , `/api/files/files/${ fileKind } /${ id } /blob` )
578562 . set ( 'Content-Type' , 'application/octet-stream' )
@@ -592,13 +576,12 @@ describe('File HTTP API', () => {
592576 expect ( result . body . message ) . not . toContain ( 'application/json' ) ;
593577 } ) ;
594578
595- test ( 'prevents MIME type manipulation through URL filename (security fix) ' , async ( ) => {
579+ test ( 'prevents MIME type manipulation through URL filename' , async ( ) => {
596580 const { id } = await createFile ( {
597581 name : 'safe-document.pdf' ,
598582 mimeType : 'application/pdf' ,
599583 } ) ;
600584
601- // Share the file
602585 const {
603586 body : { token } ,
604587 } = await request
@@ -607,31 +590,18 @@ describe('File HTTP API', () => {
607590 . send ( { } )
608591 . expect ( 200 ) ;
609592
610- // Upload content
611593 await request
612594 . put ( root , `/api/files/files/${ fileKind } /${ id } /blob` )
613595 . set ( 'Content-Type' , 'application/octet-stream' )
614596 . set ( 'x-elastic-internal-origin' , 'files-test' )
615597 . send ( 'PDF content' )
616598 . expect ( 200 ) ;
617599
618- // Security layer 1: Extension validation blocks dangerous mismatched downloads
600+ // Extension validation blocks dangerous mismatched downloads
619601 await request
620602 . get ( root , `/api/files/public/blob/malicious-script.html?token=${ token } ` )
621603 . set ( 'x-elastic-internal-origin' , 'files-test' )
622604 . expect ( 400 ) ; // Correctly blocked!
623-
624- // Security layer 2: When download is allowed, MIME type comes from server, not URL
625- const { body : buffer , header } = await request
626- . get ( root , `/api/files/public/blob/document.pdf?token=${ token } ` )
627- . set ( 'x-elastic-internal-origin' , 'files-test' )
628- . buffer ( )
629- . expect ( 200 ) ;
630-
631- // Content-type comes from stored file MIME type, never from URL filename
632- expect ( header [ 'content-type' ] ) . toEqual ( 'application/pdf' ) ;
633- expect ( header [ 'content-disposition' ] ) . toEqual ( 'attachment; filename=document.pdf' ) ;
634- expect ( buffer . toString ( 'utf8' ) ) . toEqual ( 'PDF content' ) ;
635605 } ) ;
636606 } ) ;
637607} ) ;
0 commit comments