Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/zettel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,12 @@ const routes = api
const arrayBuffer = await file.arrayBuffer();
const data = Buffer.from(arrayBuffer);

const safeFileName = file.name.replace(/[^a-zA-Z0-9.-]/g, "_");
// Sanitize the filename to prevent Windows-style path traversal attacks
// path.basename does not strip backslashes on POSIX systems
const safeFilename = path.basename(file.name).replace(/[^a-zA-Z0-9.-]/g, '_');
const tmpPath = path.join(
os.tmpdir(),
`zettel-audio-${Date.now()}-${safeFileName}`,
`zettel-audio-${Date.now()}-${safeFilename}`,
);
fs.writeFileSync(tmpPath, data);

Expand Down
Loading