Skip to content

Commit

Permalink
fix(cloud-function): normalize encoded leading slash
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed May 12, 2023
1 parent aedce9b commit c575481
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cloud-function/src/middlewares/redirect-leading-slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ export async function redirectLeadingSlash(
next: NextFunction
) {
const pathname = req.url;
if (pathname.startsWith("//")) {
return redirect(res, pathname.replace(/^\/+/g, "/"));
const normalizedPathname = normalizeLeadingSlash(pathname);
if (pathname !== normalizedPathname) {
return redirect(res, normalizedPathname);
}

next();
}

function normalizeLeadingSlash(pathname: string): string {
return pathname.replace(/^(\/|%2f)+/i, "/");
}

0 comments on commit c575481

Please sign in to comment.