Skip to content

Commit

Permalink
chore: use trimmed challenge response
Browse files Browse the repository at this point in the history
  • Loading branch information
jjarvisp committed Oct 24, 2024
1 parent 3493336 commit 2975f90
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/auth/src/providers/cognito/utils/signInHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ export async function handleMFASetupChallenge({
}: HandleAuthChallengeRequest): Promise<RespondToAuthChallengeCommandOutput> {
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;

if (challengeResponse === 'EMAIL') {
const trimmedChallengeResponse = challengeResponse.trim();

if (trimmedChallengeResponse === 'EMAIL') {
return {
ChallengeName: 'MFA_SETUP',
Session: session,
Expand All @@ -166,7 +168,7 @@ export async function handleMFASetupChallenge({
};
}

if (challengeResponse === 'TOTP') {
if (trimmedChallengeResponse === 'TOTP') {
return {
ChallengeName: 'MFA_SETUP',
Session: session,
Expand All @@ -181,7 +183,7 @@ export async function handleMFASetupChallenge({
USERNAME: username,
};

const isTOTPCode = /^\d+$/.test(challengeResponse.trim());
const isTOTPCode = /^\d+$/.test(trimmedChallengeResponse);

if (isTOTPCode) {
const verifySoftwareToken = createVerifySoftwareTokenClient({
Expand All @@ -196,7 +198,7 @@ export async function handleMFASetupChallenge({
userAgentValue: getAuthUserAgentValue(AuthAction.ConfirmSignIn),
},
{
UserCode: challengeResponse,
UserCode: trimmedChallengeResponse,
Session: session,
FriendlyDeviceName: deviceName,
},
Expand Down Expand Up @@ -227,10 +229,10 @@ export async function handleMFASetupChallenge({
);
}

const isEmail = /^\S+@\S+\.\S+$/.test(challengeResponse.trim());
const isEmail = /^\S+@\S+\.\S+$/.test(trimmedChallengeResponse);

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '!@' and with many repetitions of '!@'.
This
regular expression
that depends on
library input
may run slow on strings starting with '!@!.' and with many repetitions of '!.'.

if (isEmail) {
challengeResponses.EMAIL = challengeResponse;
challengeResponses.EMAIL = trimmedChallengeResponse;

const jsonReq: RespondToAuthChallengeCommandInput = {
ChallengeName: 'MFA_SETUP',
Expand Down

0 comments on commit 2975f90

Please sign in to comment.