-
Notifications
You must be signed in to change notification settings - Fork 229
task(settings): Wrap disable 2FA with MFA guard #19444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,7 +262,7 @@ module.exports = ( | |
| } | ||
| } | ||
|
|
||
| return [ | ||
| const routes = [ | ||
| { | ||
| method: 'POST', | ||
| path: '/totp/create', | ||
|
|
@@ -588,6 +588,27 @@ module.exports = ( | |
| } | ||
| }, | ||
| }, | ||
| { | ||
| method: 'POST', | ||
| path: '/mfa/totp/destroy', | ||
| options: { | ||
| ...TOTP_DOCS.MFA_TOTP_DESTROY_POST, | ||
| auth: { | ||
| strategy: 'mfa', | ||
| scope: ['mfa:2fa'], | ||
| payload: false, | ||
| }, | ||
| response: {}, | ||
| }, | ||
| handler: async function (request) { | ||
| return routes | ||
| .find( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MagentaManifold @nshirley @vpomerleau I like this approach for the simple reason that it doesn't corrupt the git history of the previous route handler and makes the diff nicer.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, neat! 🤯
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
| (route) => | ||
| route.path === '/v1/totp/destroy' && route.method === 'POST' | ||
| ) | ||
| .handler(request); | ||
| }, | ||
| }, | ||
| { | ||
| method: 'POST', | ||
| path: '/totp/destroy', | ||
|
|
@@ -1163,4 +1184,6 @@ module.exports = ( | |
| handler: handleTotpReplaceConfirm, | ||
| }, | ||
| ]; | ||
|
|
||
| return routes; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import React, { useCallback, useEffect } from 'react'; | ||
| import * as Sentry from '@sentry/browser'; | ||
| import { useErrorHandler } from 'react-error-boundary'; | ||
| import LinkExternal from 'fxa-react/components/LinkExternal'; | ||
| import { useBooleanState } from 'fxa-react/lib/hooks'; | ||
| import Modal from '../Modal'; | ||
|
|
@@ -22,6 +24,8 @@ import { useNavigateWithQuery } from '../../../lib/hooks/useNavigateWithQuery'; | |
| import { formatPhoneNumber } from '../../../lib/recovery-phone-utils'; | ||
| import { RecoveryPhoneSetupReason } from '../../../lib/types'; | ||
| import ModalVerifySession from '../ModalVerifySession'; | ||
| import { MfaGuard } from '../MfaGuard'; | ||
| import { isInvalidJwtError } from '../../../lib/mfa-guard-utils'; | ||
|
|
||
| const route = `${SETTINGS_PATH}/two_step_authentication`; | ||
| const replaceCodesRoute = `${route}/replace_codes`; | ||
|
|
@@ -209,7 +213,14 @@ export const UnitRowTwoStepAuth = () => { | |
| /> | ||
| )} | ||
| {disable2FAModalRevealed && ( | ||
| <DisableTwoStepAuthModal {...{ hideDisable2FAModal }} /> | ||
| <MfaGuard | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| requiredScope={'2fa'} | ||
| onDismissCallback={async () => { | ||
| hideDisable2FAModal(); | ||
| }} | ||
| > | ||
| <DisableTwoStepAuthModal {...{ hideDisable2FAModal }} /> | ||
| </MfaGuard> | ||
| )} | ||
| </UnitRow> | ||
| </> | ||
|
|
@@ -221,6 +232,7 @@ const DisableTwoStepAuthModal = ({ | |
| }: { | ||
| hideDisable2FAModal: () => void; | ||
| }) => { | ||
| const errorHandler = useErrorHandler(); | ||
| const alertBar = useAlertBar(); | ||
| const account = useAccount(); | ||
| const ftlMsgResolver = useFtlMsgResolver(); | ||
|
|
@@ -243,15 +255,23 @@ const DisableTwoStepAuthModal = ({ | |
| () => GleanMetrics.accountPref.twoStepAuthDisableSuccessView() | ||
| ); | ||
| } catch (e) { | ||
| if (isInvalidJwtError(e)) { | ||
| // JWT invalid/expired. | ||
| errorHandler(e); | ||
| return; | ||
| } | ||
|
|
||
| hideDisable2FAModal(); | ||
| alertBar.error( | ||
| ftlMsgResolver.getMsg( | ||
| 'tfa-row-cannot-disable-2', | ||
| 'Two-step authentication could not be disabled' | ||
| ) | ||
| ); | ||
|
|
||
| Sentry.captureException(e); | ||
| } | ||
| }, [account, hideDisable2FAModal, alertBar, ftlMsgResolver]); | ||
| }, [account, hideDisable2FAModal, alertBar, ftlMsgResolver, errorHandler]); | ||
|
|
||
| return ( | ||
| <VerifiedSessionGuard | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.