@@ -1542,22 +1542,18 @@ describe('prod ssr', () => {
15421542 let response = await app . render ( request ) ;
15431543 const body = await response . text ( ) ;
15441544
1545- // Most paths are malformed local paths (500), but some backslash patterns
1546- // are now correctly detected as remote and get 403
15471545 const { isRemotePath } = await import ( '@astrojs/internal-helpers/path' ) ;
1548- const isDetectedAsRemote = isRemotePath ( path ) ;
1549- const expectedStatus = isDetectedAsRemote ? 403 : 500 ;
1550- const expectedBodyText = isDetectedAsRemote ? 'Forbidden' : 'Internal Server Error' ;
1546+ const expectedStatuses = isRemotePath ( path ) ? [ 403 ] : [ 400 , 404 , 500 ] ;
15511547
15521548 assert . equal (
1553- response . status ,
1554- expectedStatus ,
1555- `Path "${ path } " should return ${ expectedStatus } ` ,
1549+ expectedStatuses . includes ( response . status ) ,
1550+ true ,
1551+ `Path "${ path } " should return ${ expectedStatuses . join ( ' or ' ) } ` ,
15561552 ) ;
15571553 assert . equal (
1558- body . includes ( expectedBodyText ) ,
1554+ [ 'Invalid request' , 'Forbidden' , 'Not Found' , 'Internal Server Error' ] . includes ( body ) ,
15591555 true ,
1560- `Path "${ path } " body should include " ${ expectedBodyText } " ` ,
1556+ `Path "${ path } " should return an opaque error ` ,
15611557 ) ;
15621558 }
15631559
@@ -1567,6 +1563,28 @@ describe('prod ssr', () => {
15671563 assert . equal ( response . status , 200 ) ;
15681564 } ) ;
15691565
1566+ it ( 'returns 400 for local paths with parent directory segments' , async ( ) => {
1567+ const app = await fixture . loadTestAdapterApp ( ) ;
1568+ const paths = [ '/../../../.env' , '/foo/../../../.env' , '/foo\\..\\..\\.env' , '/%2e%2e/.env' ] ;
1569+
1570+ for ( const path of paths ) {
1571+ const request = new Request ( 'http://example.com/_image?href=' + encodeURIComponent ( path ) ) ;
1572+ const response = await app . render ( request ) ;
1573+
1574+ assert . equal ( response . status , 400 , `Path "${ path } " should return 400` ) ;
1575+ assert . equal ( await response . text ( ) , 'Invalid request' ) ;
1576+ }
1577+ } ) ;
1578+
1579+ it ( 'returns 404 when a valid local image is not found' , async ( ) => {
1580+ const app = await fixture . loadTestAdapterApp ( ) ;
1581+ const request = new Request ( 'http://example.com/_image?href=/does-not-exist.png' ) ;
1582+ const response = await app . render ( request ) ;
1583+
1584+ assert . equal ( response . status , 404 ) ;
1585+ assert . equal ( await response . text ( ) , 'Not Found' ) ;
1586+ } ) ;
1587+
15701588 it ( 'prerendered routes images are built' , async ( ) => {
15711589 const html = await fixture . readFile ( '/client/prerender/index.html' ) ;
15721590 const $ = cheerio . load ( html ) ;
0 commit comments