@@ -7,17 +7,19 @@ import { createReadStream } from 'fs';
77import { mediaTypes } from '@hapi/accept' ;
88
99const LOCALE_FORMATS = [ / ^ A L L _ [ a - z ] + $ / , / ^ [ a - z ] + _ A L L $ / , / ^ [ a - z ] + ( _ [ a - z ] + ) ? $ / ] ;
10+ const NG_BROWSER_OUTPUT_PATH = process . env . __NG_BROWSER_OUTPUT_PATH__
1011
1112export const handle = async ( req : Request , res : Response ) => {
1213 if ( basename ( req . path ) === '__image__' ) {
13- const src = req . query . src ;
14- if ( typeof src !== "string" ) return res . sendStatus ( 404 ) ;
15- const locale = req . query . locale || "" ;
16- if ( typeof locale !== "string" ) return res . sendStatus ( 404 ) ;
17- if ( ! LOCALE_FORMATS . some ( it => locale . match ( it ) ) ) return res . sendStatus ( 404 ) ;
18- const serveFrom = `./${ process . env . __NG_BROWSER_OUTPUT_PATH__ } ` ;
19- const normalizedPath = normalize ( join ( serveFrom , locale , src ) ) ;
20- if ( relative ( serveFrom , normalizedPath ) . startsWith ( ".." ) ) return res . sendStatus ( 404 ) ;
14+ const { src, locale= "" } = req . query ;
15+ if (
16+ typeof src !== "string" ||
17+ typeof locale !== "string" ||
18+ ! LOCALE_FORMATS . some ( it => locale . match ( it ) ) ||
19+ ! NG_BROWSER_OUTPUT_PATH
20+ ) return res . sendStatus ( 404 ) ;
21+ const normalizedPath = normalize ( join ( NG_BROWSER_OUTPUT_PATH , locale , src ) ) ;
22+ if ( relative ( NG_BROWSER_OUTPUT_PATH , normalizedPath ) . startsWith ( ".." ) ) return res . sendStatus ( 404 ) ;
2123 const { default : sharp } = await import ( "sharp" ) ;
2224 const width = typeof req . query . width === "string" ? parseInt ( req . query . width ) : undefined ;
2325 const accepts = mediaTypes ( req . headers . accept ) ;
0 commit comments