Skip to content
Open
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
7 changes: 4 additions & 3 deletions web/src/routes/notes/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ export const POST: RequestHandler = async ({ request }) => {

// Security: use only the basename to strip any path traversal sequences (CWE-22)
const safeFilename = basename(filename);
if (!safeFilename) {
if (!safeFilename || !/^[a-zA-Z0-9._\- ]+$/.test(safeFilename)) {
return json({ error: 'Invalid filename' }, { status: 400 });
}

const inboxPath = join(inboxDir, safeFilename);
// Build path via string concatenation to avoid path.join/resolve with user input
const inboxPath = `${inboxDir}/${safeFilename}`;

// Double-check the resolved path is still within the inbox directory
if (!inboxPath.startsWith(inboxDir + '/') && inboxPath !== inboxDir) {
if (!inboxPath.startsWith(inboxDir + '/')) {
return json({ error: 'Invalid filename' }, { status: 400 });
}

Expand Down
Loading