File tree Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff 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 ( {
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments