Files
Marc Seitz 2ef3a7ffaf feat: add shared folder path validation schema
Introduced a Zod schema for validating folder path parameters to prevent type confusion and path traversal attacks. Updated all relevant API routes to use this schema for input validation, improving security and consistency across folder-related endpoints.
2025-07-24 08:30:36 +02:00

31 lines
773 B
TypeScript

import { z } from "zod";
/**
* Schema to validate folder path parameters in catch-all routes.
* Protects against both type confusion and path traversal attacks.
*/
export const folderPathSchema = z
.array(
z
.string()
.min(1, "Folder name cannot be empty")
.refine(
(name) => !name.includes(".."),
"Path traversal attempts are not allowed",
)
.refine(
(name) => !name.includes("/"),
"Folder names cannot contain forward slashes",
)
.refine(
(name) => !name.includes("\\"),
"Folder names cannot contain backslashes",
),
)
.min(1, "Folder path cannot be empty");
/**
* Type for validated folder path
*/
export type FolderPath = z.infer<typeof folderPathSchema>;