Skip to content

Commit 88a95c9

Browse files
committed
404 if no NG_BROWSER_OUTPUT_PATH
1 parent b1709ad commit 88a95c9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/angular/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import { createReadStream } from 'fs';
77
import { mediaTypes } from '@hapi/accept';
88

99
const LOCALE_FORMATS = [/^ALL_[a-z]+$/, /^[a-z]+_ALL$/, /^[a-z]+(_[a-z]+)?$/];
10+
const NG_BROWSER_OUTPUT_PATH = process.env.__NG_BROWSER_OUTPUT_PATH__
1011

1112
export 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

Comments
 (0)