Skip to content

Commit afeedd2

Browse files
authored
Ensure the redirect path starts with a slash (#210)
1 parent f069beb commit afeedd2

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/lambda-edge/parse-auth/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const handler: CloudFrontRequestHandler = async (event) => {
3030
cookies,
3131
});
3232
CONFIG.logger.debug("Query string and cookies are valid");
33-
redirectedFromUri += requestedUri;
33+
redirectedFromUri += common.ensureValidRedirectPath(requestedUri);
3434

3535
const body = stringifyQueryString({
3636
grant_type: "authorization_code",

src/lambda-edge/refresh-auth/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ export const handler: CloudFrontRequestHandler = async (event) => {
7676
location: [
7777
{
7878
key: "location",
79-
value: `https://${domainName}${
80-
typeof requestedUri === "string" ? requestedUri : "/"
81-
}`,
79+
value: `https://${domainName}${common.ensureValidRedirectPath(
80+
requestedUri
81+
)}`,
8282
},
8383
],
8484
"set-cookie": common.generateCookieHeaders.refresh({

src/lambda-edge/shared/shared.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,8 @@ export function generateSecret(
605605
.map(() => allowedCharacters[randomInt(0, allowedCharacters.length)])
606606
.join("");
607607
}
608+
609+
export function ensureValidRedirectPath(path: unknown) {
610+
if (typeof path !== "string") return "/";
611+
return path.startsWith("/") ? path : `/${path}`;
612+
}

0 commit comments

Comments
 (0)