Skip to content

Commit

Permalink
fix: verify state parameter and specify node v20 in .nvmrc for crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
joemays committed Apr 10, 2024
1 parent 019c0e9 commit b185009
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"devDependencies": {
"@aws-sdk/client-cognito-identity-provider": "^3.465.0",
"@types/jsdom": "^21.1.5",
"@types/node": "^20",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"esbuild": "^0.20.2",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/cognito-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,19 +883,22 @@ export class CognitoClient {
*
* @throws {Error}
*/
async handleCodeFlow(returnUrl: string, pkce: string): Promise<Session> {
async handleCodeFlow(returnUrl: string, pkce: string, state: string): Promise<Session> {
if (this.oAuth === undefined) {
throw Error('You have to define oAuth options to use handleCodeFlow');
}

const url = new URL(returnUrl);
const code = url.searchParams.get('code');
const state = url.searchParams.get('state');

if (code === null || state === null) {
if (code === null) {
throw Error('code or state parameter is missing from return url.');
}

if (url.searchParams.get('state') !== state) {
throw Error('State parameter does not match.');
}

const urlParams = new URLSearchParams();

urlParams.append('grant_type', 'authorization_code');
Expand Down

0 comments on commit b185009

Please sign in to comment.