Skip to content

Commit 1edb201

Browse files
committed
Validate local formats
1 parent ccc8af4 commit 1edb201

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/angular/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import { basename, join, normalize, relative } from 'path';
66
import { createReadStream } from 'fs';
77
import { mediaTypes } from '@hapi/accept';
88

9+
const LOCALE_FORMATS = [/^ALL_[a-z]+$/, /^[a-z]+_ALL$/, /^[a-z]+(_[a-z]+)?$/];
10+
911
export const handle = async (req: Request, res: Response) => {
1012
if (basename(req.path) === '__image__') {
1113
const src = req.query.src;
1214
if (typeof src !== "string") return res.sendStatus(404);
13-
let locale = req.query.locale || "";
15+
const locale = req.query.locale || "";
1416
if (typeof locale !== "string") return res.sendStatus(404);
17+
if (!LOCALE_FORMATS.some(it => locale.match(it))) return res.sendStatus(404);
1518
const serveFrom = `./dist/hosting/browser/${locale}`;
1619
const normalizedPath = normalize(join(serveFrom, src));
1720
if (relative(serveFrom, normalizedPath).startsWith("..")) return res.sendStatus(404);

0 commit comments

Comments
 (0)