Skip to content

Commit c1b75a1

Browse files
committed
chore: sanitize filename
1 parent a8ed60d commit c1b75a1

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

bun.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"@elysiajs/jwt": "^1.2.0",
1818
"@elysiajs/static": "^1.2.0",
1919
"@kitajs/html": "^4.2.7",
20-
"elysia": "^1.2.12"
20+
"elysia": "^1.2.12",
21+
"sanitize-filename": "^1.6.3"
2122
},
2223
"module": "src/index.tsx",
2324
"type": "module",

src/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { jwt, type JWTPayloadSpec } from "@elysiajs/jwt";
77
import { staticPlugin } from "@elysiajs/static";
88
import { Database } from "bun:sqlite";
99
import { Elysia, t } from "elysia";
10+
import sanitize from "sanitize-filename";
1011
import { BaseHtml } from "./components/base";
1112
import { Header } from "./components/header";
1213
import {
@@ -886,6 +887,10 @@ const app = new Elysia({
886887
const converterName = body.convert_to.split(",")[1];
887888
const fileNames = JSON.parse(body.file_names) as string[];
888889

890+
for (let i = 0; i < fileNames.length; i++) {
891+
fileNames[i] = sanitize(fileNames[i] || "");
892+
}
893+
889894
if (!Array.isArray(fileNames) || fileNames.length === 0) {
890895
return redirect(`${WEBROOT}/`, 302);
891896
}
@@ -1411,7 +1416,7 @@ const app = new Elysia({
14111416
// parse from url encoded string
14121417
const userId = decodeURIComponent(params.userId);
14131418
const jobId = decodeURIComponent(params.jobId);
1414-
const fileName = decodeURIComponent(params.fileName);
1419+
const fileName = sanitize(decodeURIComponent(params.fileName));
14151420

14161421
const filePath = `${outputDir}${userId}/${jobId}/${fileName}`;
14171422
return Bun.file(filePath);

0 commit comments

Comments
 (0)