Skip to content

Commit

Permalink
auth-backend: Encode the OAuth state param using URL safe chars (#3281)
Browse files Browse the repository at this point in the history
  • Loading branch information
freben committed Nov 12, 2020
1 parent d5a2bf9 commit 4628763
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-bobcats-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-auth-backend': patch
---

Encode the OAuth state parameter using URL safe chars only, so that providers have an easier time forming the callback URL.
4 changes: 2 additions & 2 deletions plugins/auth-backend/src/lib/oauth/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { OAuthState } from './types';

export const readState = (stateString: string): OAuthState => {
const state = Object.fromEntries(
new URLSearchParams(decodeURIComponent(stateString)),
new URLSearchParams(Buffer.from(stateString, 'hex').toString('utf-8')),
);
if (
!state.nonce ||
Expand All @@ -40,7 +40,7 @@ export const encodeState = (state: OAuthState): string => {
searchParams.append('nonce', state.nonce);
searchParams.append('env', state.env);

return encodeURIComponent(searchParams.toString());
return Buffer.from(searchParams.toString(), 'utf-8').toString('hex');
};

export const verifyNonce = (req: express.Request, providerId: string) => {
Expand Down

0 comments on commit 4628763

Please sign in to comment.