Skip to content

Commit

Permalink
fix: validate MFA claim before allowing TOTP device removal
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Nov 22, 2024
1 parent 264fe2d commit 6a58bdf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adds `getCookieNameForTokenType` config option to allow customizing the cookie name for a token type.
- Adds `getResponseHeaderNameForTokenType` config option to allow customizing the response header name for a token type.
- Please note, that using this will require further customizations on the frontend
- Fixes an issue where `removeDevice` API allowed removing TOTP devices without the user completing MFA.

## [21.0.0] - 2024-10-07

Expand Down
6 changes: 5 additions & 1 deletion lib/build/recipe/totp/api/removeDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ async function removeDeviceAPI(apiImplementation, options, userContext) {
const session = await session_1.default.getSession(
options.req,
options.res,
{ overrideGlobalClaimValidators: () => [], sessionRequired: true },
{
overrideGlobalClaimValidators: (globalClaimValidators) =>
globalClaimValidators.filter((v) => v.id === "st-mfa"),
sessionRequired: true,
},
userContext
);
const bodyParams = await options.req.getJSONBody();
Expand Down
6 changes: 5 additions & 1 deletion lib/ts/recipe/totp/api/removeDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export default async function removeDeviceAPI(
const session = await Session.getSession(
options.req,
options.res,
{ overrideGlobalClaimValidators: () => [], sessionRequired: true },
{
overrideGlobalClaimValidators: (globalClaimValidators) =>
globalClaimValidators.filter((v) => v.id === "st-mfa"),
sessionRequired: true,
},
userContext
);

Expand Down
10 changes: 10 additions & 0 deletions test/test-server/src/testFunctionMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ export function getFunc(evalStr: string): (...args: any[]) => any {
}

if (evalStr.startsWith("multifactorauth.init.override.functions")) {
if (evalStr.includes(`getMFARequirementsForAuth:async()=>["totp"]`)) {
return (e) => {
return {
...e,
getMFARequirementsForAuth: (e) => {
return ["totp"];
},
};
};
}
return (e) => {
return {
...e,
Expand Down

0 comments on commit 6a58bdf

Please sign in to comment.