diff --git a/lib/utils/escape-html.ts b/lib/utils/escape-html.ts new file mode 100644 index 0000000..8a82233 --- /dev/null +++ b/lib/utils/escape-html.ts @@ -0,0 +1,8 @@ +export function escapeHtml(value: string): string { + return value + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'") +} diff --git a/routes/admin/files/get.ts b/routes/admin/files/get.ts index 046d202..1ca3a2b 100644 --- a/routes/admin/files/get.ts +++ b/routes/admin/files/get.ts @@ -1,4 +1,5 @@ import { withRouteSpec } from "lib/middleware/with-winter-spec" +import { escapeHtml } from "lib/utils/escape-html" import { z } from "zod" export default withRouteSpec({ @@ -15,10 +16,16 @@ export default withRouteSpec({ return new Response("File not found", { status: 404 }) } + const encodedPath = file.file_path + .split("/") + .map(encodeURIComponent) + .join("/") + const encodedPathWithoutLeadingSlash = encodedPath.replace(/^\/+/, "") + return new Response( ` - File Details - ${file.file_path} + File Details - ${escapeHtml(file.file_path)}