@@ -7,17 +7,19 @@ import { createReadStream } from 'fs';
7
7
import { mediaTypes } from '@hapi/accept' ;
8
8
9
9
const 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__
10
11
11
12
export const handle = async ( req : Request , res : Response ) => {
12
13
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 ) ;
21
23
const { default : sharp } = await import ( "sharp" ) ;
22
24
const width = typeof req . query . width === "string" ? parseInt ( req . query . width ) : undefined ;
23
25
const accepts = mediaTypes ( req . headers . accept ) ;
0 commit comments