Skip to content

Commit 993d1ab

Browse files
authored
Fix case where oidc integration can redirect to a url ending with double triailling slash (#913)
* Fix case where oidc integration can redirect to a url with double trailing slash * Add changeset
1 parent 6be1004 commit 993d1ab

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.changeset/upset-rings-follow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/integration-oidc': patch
3+
---
4+
5+
Fix case where oidc integration can redirect to a url ending with double triailling slash

integrations/oidc/src/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,15 @@ const handleFetchEvent: FetchEventCallback<OIDCRuntimeContext> = async (request,
368368
}
369369

370370
const state = request.query.state?.toString();
371-
const location = state ? state.substring(state.indexOf('-') + 1) : '';
372-
373-
const url = new URL(`${publishedContentUrl}${location || ''}`);
371+
let location = state ? state.substring(state.indexOf('-') + 1) : '';
372+
location = location.startsWith('/') ? location.slice(1) : location;
373+
const url = new URL(
374+
`${
375+
publishedContentUrl.endsWith('/')
376+
? publishedContentUrl
377+
: `${publishedContentUrl}/`
378+
}${location || ''}`,
379+
);
374380
url.searchParams.append('jwt_token', jwtToken);
375381

376382
return Response.redirect(url.toString());

0 commit comments

Comments
 (0)