Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/db-migrations/databases/fxa/patches/patch-175-176.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SET NAMES utf8mb4 COLLATE utf8mb4_bin;

-- Bump these to your next migration numbers
CALL assertPatchLevel('175');

INSERT INTO securityEventNames (name) VALUES
('account.password_upgrade_success'),
('account.password_upgraded'),
('account.recovery_phone_setup_failed'),
('account.mfa_send_otp_code'),
('account.mfa_verify_otp_code_success'),
('account.mfa_verify_otp_code_failed');

UPDATE dbMetadata SET value = '176' WHERE name = 'schema-patch-level';
11 changes: 11 additions & 0 deletions packages/db-migrations/databases/fxa/patches/patch-176-175.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- SET NAMES utf8mb4 COLLATE utf8mb4_bin;
--
-- -- Remove only the rows this migration inserted.
-- DELETE FROM securityEventNames WHERE name = 'account.password_upgrade_success';
-- DELETE FROM securityEventNames WHERE name = 'account.password_upgraded';
-- DELETE FROM securityEventNames WHERE name = 'account.recovery_phone_setup_failed';
-- DELETE FROM securityEventNames WHERE name = 'account.mfa_send_otp_code';
-- DELETE FROM securityEventNames WHERE name = 'account.mfa_verify_otp_code_success';
-- DELETE FROM securityEventNames WHERE name = 'account.mfa_verify_otp_code_failed';
--
-- UPDATE dbMetadata SET value = '175' WHERE name = 'schema-patch-level';
2 changes: 1 addition & 1 deletion packages/db-migrations/databases/fxa/target-patch.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"level": 175
"level": 176
}
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/lib/routes/recovery-phone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class RecoveryPhoneHandler {
if (!replacedSuccess) {
await this.glean.twoStepAuthPhoneReplace.failure(request);
this.statsd.increment('account.recoveryPhone.changePhoneNumber.failure');
await recordSecurityEvent('account.recovery_phone_replace_failed', {
await recordSecurityEvent('account.recovery_phone_replace_failure', {
db: this.db,
request,
});
Expand Down
21 changes: 11 additions & 10 deletions packages/fxa-shared/db/models/auth/security-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ export const EVENT_NAMES: Record<string, number> = {
'account.recovery_codes_created': 33,
'account.recovery_codes_signin_complete': 34,
'account.must_reset': 35,
'account.recovery_phone_reset_password_success': 36,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not found in code, but the new recovery_phone_reset_password_complete is.

'account.recovery_phone_reset_password_complete': 36,
'account.recovery_phone_reset_password_failed': 37,
'account.password_upgrade_success': 38,
'account.password_upgraded': 39,
'account.recovery_phone_setup_failed': 40,
'account.recovery_phone_replace_failed': 41,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, _failed is what was in code, but the db had it as _failure. I'm unsure if we should keep the db as the source of truth or update it to match the model here so I went with the former given the comment at the top

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just digging into how events are written and, since they're written with whatever name is passed to recordSecurityEvent then this is probably not a great idea to change. We'd have some events with the old _failed and then all new events would have the _failure name.

Maybe it makes more sense to update the event name in the db instead of code/model?

'account.recovery_phone_replace_complete': 42,
'account.recovery_phone_reset_password_complete': 43,
'account.mfa_send_otp_code': 44,
'account.mfa_verify_otp_code_success': 45,
'account.mfa_verify_otp_code_failed': 46,
'account.recovery_phone_replace_complete': 38,
'account.recovery_phone_replace_failure': 39,
'account.two_factor_replace_success': 40,
'account.two_factor_replace_failure': 41,
'account.password_upgrade_success': 42,
'account.password_upgraded': 43,
'account.recovery_phone_setup_failed': 44,
'account.mfa_send_otp_code': 45,
'account.mfa_verify_otp_code_success': 46,
'account.mfa_verify_otp_code_failed': 47,
} as const;

export type SecurityEventNames = keyof typeof EVENT_NAMES;
Expand Down