fix: sanitize jobId and fix typo in filename sanitization
- Fix typo: santizedFileName -> sanitizedFileName in upload.tsx - Add sanitize(jobId) in download.tsx for defense-in-depth path traversal protection Even though jobId is validated against the database, sanitizing it prevents any potential path traversal via malicious job IDs.
This commit is contained in:
parent
1ba82cf1b2
commit
678424b2d2
2 changed files with 5 additions and 5 deletions
|
|
@ -24,7 +24,7 @@ export const download = new Elysia()
|
|||
const jobId = decodeURIComponent(params.jobId);
|
||||
const fileName = sanitize(decodeURIComponent(params.fileName));
|
||||
|
||||
const filePath = `${outputDir}${userId}/${jobId}/${fileName}`;
|
||||
const filePath = `${outputDir}${userId}/${sanitize(jobId)}/${fileName}`;
|
||||
return Bun.file(filePath);
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@ export const upload = new Elysia().use(userService).post(
|
|||
if (body?.file) {
|
||||
if (Array.isArray(body.file)) {
|
||||
for (const file of body.file) {
|
||||
const santizedFileName = sanitize(file.name);
|
||||
await Bun.write(`${userUploadsDir}${santizedFileName}`, file);
|
||||
const sanitizedFileName = sanitize(file.name);
|
||||
await Bun.write(`${userUploadsDir}${sanitizedFileName}`, file);
|
||||
}
|
||||
} else {
|
||||
const santizedFileName = sanitize(body.file["name"]);
|
||||
await Bun.write(`${userUploadsDir}${santizedFileName}`, body.file);
|
||||
const sanitizedFileName = sanitize(body.file["name"]);
|
||||
await Bun.write(`${userUploadsDir}${sanitizedFileName}`, body.file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue