Skip to content

feat: read enrolled recovery identifiers and bind escrow challenges to the profile - #11149

Merged
ieow merged 5 commits into
mainfrom
feat/mfa-recovery-get-identifiers
Nov 10, 2026
Merged

ieow merged 5 commits into
mainfrom
feat/mfa-recovery-get-identifiers

Conversation

@huggingbot

@huggingbot huggingbot commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Explanation

Stacked on #10883. Adds getIdentifiers() and profile-bound challenges.

  • getIdentifiers(): AAL1 read returning enrolled identifiers at the highest escrow version (epoch) plus Auth's identifiers. Use it to build updateIdentifiers.
  • generateChallenge takes the operation's approval.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@huggingbot
huggingbot force-pushed the feat/mfa-recovery-get-identifiers branch from 325168d to 8e5ddad Compare October 28, 2026 09:46
@huggingbot
huggingbot marked this pull request as ready for review October 28, 2026 14:49
@huggingbot
huggingbot requested review from a team as code owners October 28, 2026 14:49
Base automatically changed from feat/mfa-recovery-auth-approvals to main October 29, 2026 06:49
@huggingbot
huggingbot requested a review from a team as a code owner October 29, 2026 06:49
huggingbot and others added 3 commits October 29, 2026 15:39
Add getIdentifiers to the controller and CubistEscrowProvider (escrow #8),
and pass the operation's AuthController token to generateChallenge (escrow #10).

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@huggingbot
huggingbot force-pushed the feat/mfa-recovery-get-identifiers branch from cc92526 to 3d6bb9b Compare October 29, 2026 07:42
@ieow

ieow commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@metamaskbot publish-preview

@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Partly-written escrows lead to a stuck update (design, medium)

MfaRecoveryController.ts
Ln 468–477

const epoch = Math.max(...responses.map(({ version }) => version));
const highest = responses.filter(({ version }) => version === epoch);
const hashes = await Promise.all(
  highest.map(async ({ identifiers }) => await hash(identifiers)),
);
if (new Set(hashes).size !== 1) {
  throw new MfaRecoveryError('Replica corruption', 'replica_corruption');
}
return { identifiers: highest[0].identifiers, epoch, authIdentifiers };
Escrows reporting a lower version are dropped without any signal. Suppose an old device left a mutation half-applied, so escrow A is at version 3 and escrow B is at version 2. The record of that pending write lives only on the old device. The new device gets epoch = 3, which ARCHITECTURE.md tells it to use as expectedVersion. When it calls updateIdentifiers:

A accepts.
B rejects, because it expects version 2.
The rejection isn't unanimous, so the controller saves a pending write and throws IncompleteMutationError.
Every resume() retries B with expectedVersion: 3, which B can never accept.
The replicas stay out of sync and the client is stuck until someone aborts manually. A single faulty escrow reporting an inflated version causes the same failure.

@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

The approval is the same for every getIdentifiers call

MfaRecoveryController.ts
Ln 450–453

await this.#authProvider.authorizeRecoveryRequest({
  requestHash: await hash({ operation: 'getIdentifiers' }),
  audiences: available.map((escrow) => escrow.authAudience),
});

The request hash is the same constant for every call. It has no request ID or nonce, unlike getRecoverySecret. Anyone who captures one of these low-assurance approvals can replay it until it expires and read the user's enrolled identifiers (emails, passkeys, wallet addresses). That's a privacy leak, not a way to take over the account. The fix is to include a randomId() in the hash, as the other operations do.

@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Identifier order causes false "replica corruption" errors
hash(identifiers) uses json-stable-stringify, which sorts object keys but not arrays. Two escrows holding the same set in a different order produce different hashes and trigger replica_corruption. Unless escrows guarantee a canonical order, sort the identifiers by type, namespace, and value before hashing. Comparing them as a set, like countDistinctIdentifiers does, would also work.

@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

nits
parseIdentifiers validates with superstruct's type(), which accepts objects that have extra keys. It then returns value.identifiers unchanged, so any extra fields from an escrow:

get hashed, which can cause another false corruption error;
get returned to the caller;
end up in the next updateIdentifiers payload.

@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

The mutation approval is now sent to more places. The request-bound AAL2 approval now also goes to generateChallenge and getIdentifiers. Each additional endpoint that receives the bearer token is another place it can leak or be replayed (for example, into logs or intermediaries). This is worth calling out in the threat model.

@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

The code and its docs disagree on which escrows get SIWE proofs. The applyMutation docs in types.ts say each escrow gets "one proof per SIWE identifier the escrow has not enrolled". The code instead computes one list for all escrows: any wallet missing from any escrow is proven to every escrow. The stub rejects an extra proof for an already-enrolled identifier (Exactly one enrolled identifier authorization required). It only gets away with it because the stub replays an already-applied mutation before checking proofs. Either compute proofs per escrow, or fix the docs and make sure the real escrow ignores extra proofs.

@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

One lookup failure blocks the whole write. #findNewSiweIdentifiers uses Promise.all over getIdentifiers, so if any remaining escrow's lookup fails, the write aborts with that raw error instead of an MfaRecoveryError. It also doesn't check that each escrow's returned version equals expectedVersion, which would catch a version mismatch before asking for an approval and wallet signatures.

1 similar comment
@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

One lookup failure blocks the whole write. #findNewSiweIdentifiers uses Promise.all over getIdentifiers, so if any remaining escrow's lookup fails, the write aborts with that raw error instead of an MfaRecoveryError. It also doesn't check that each escrow's returned version equals expectedVersion, which would catch a version mismatch before asking for an approval and wallet signatures.

@ieow

ieow commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

getIdentifiers ignores a pending mutation. It returns an epoch even when a mutation is in flight. A caller who builds updateIdentifiers from that result then hits pending_mutation. Consider rejecting, or returning the current phase alongside the result.

@huggingbot

Copy link
Copy Markdown
Member Author

Partly-written escrows lead to a stuck update (design, medium)

MfaRecoveryController.ts Ln 468–477

const epoch = Math.max(...responses.map(({ version }) => version));
const highest = responses.filter(({ version }) => version === epoch);
const hashes = await Promise.all(
  highest.map(async ({ identifiers }) => await hash(identifiers)),
);
if (new Set(hashes).size !== 1) {
  throw new MfaRecoveryError('Replica corruption', 'replica_corruption');
}
return { identifiers: highest[0].identifiers, epoch, authIdentifiers };
Escrows reporting a lower version are dropped without any signal. Suppose an old device left a mutation half-applied, so escrow A is at version 3 and escrow B is at version 2. The record of that pending write lives only on the old device. The new device gets epoch = 3, which ARCHITECTURE.md tells it to use as expectedVersion. When it calls updateIdentifiers:

A accepts. B rejects, because it expects version 2. The rejection isn't unanimous, so the controller saves a pending write and throws IncompleteMutationError. Every resume() retries B with expectedVersion: 3, which B can never accept. The replicas stay out of sync and the client is stuck until someone aborts manually. A single faulty escrow reporting an inflated version causes the same failure.

this is addressed in: #11200

@huggingbot

huggingbot commented Nov 6, 2026 •

Copy link
Copy Markdown
Member Author

The approval is the same for every getIdentifiers call

MfaRecoveryController.ts Ln 450–453

await this.#authProvider.authorizeRecoveryRequest({
  requestHash: await hash({ operation: 'getIdentifiers' }),
  audiences: available.map((escrow) => escrow.authAudience),
});

The request hash is the same constant for every call. It has no request ID or nonce, unlike getRecoverySecret. Anyone who captures one of these low-assurance approvals can replay it until it expires and read the user's enrolled identifiers (emails, passkeys, wallet addresses). That's a privacy leak, not a way to take over the account. The fix is to include a randomId() in the hash, as the other operations do.

i think this is acceptable. Reading identifiers using an aal1 token is fine. We can change the authorization model for this API in the wasm if needed. Let's wait for the auditors' findings. The proposed fix on the client side wouldn't work

@huggingbot

Copy link
Copy Markdown
Member Author

Identifier order causes false "replica corruption" errors hash(identifiers) uses json-stable-stringify, which sorts object keys but not arrays. Two escrows holding the same set in a different order produce different hashes and trigger replica_corruption. Unless escrows guarantee a canonical order, sort the identifiers by type, namespace, and value before hashing. Comparing them as a set, like countDistinctIdentifiers does, would also work.

Not applicable to the current escrow: it preserves the submitted identifier order through validation, storage, and reads. Since every replica receives the same ordered array, no canonical sort is needed.

@huggingbot

Copy link
Copy Markdown
Member Author

nits parseIdentifiers validates with superstruct's type(), which accepts objects that have extra keys. It then returns value.identifiers unchanged, so any extra fields from an escrow:

get hashed, which can cause another false corruption error; get returned to the caller; end up in the next updateIdentifiers payload.

fixed here

@huggingbot

huggingbot commented Nov 6, 2026 •

Copy link
Copy Markdown
Member Author

The code and its docs disagree on which escrows get SIWE proofs. The applyMutation docs in types.ts say each escrow gets "one proof per SIWE identifier the escrow has not enrolled". The code instead computes one list for all escrows: any wallet missing from any escrow is proven to every escrow. The stub rejects an extra proof for an already-enrolled identifier (Exactly one enrolled identifier authorization required). It only gets away with it because the stub replays an already-applied mutation before checking proofs. Either compute proofs per escrow, or fix the docs and make sure the real escrow ignores extra proofs.

fixed here
this belongs in another PR btw

@huggingbot

Copy link
Copy Markdown
Member Author

One lookup failure blocks the whole write. #findNewSiweIdentifiers uses Promise.all over getIdentifiers, so if any remaining escrow's lookup fails, the write aborts with that raw error instead of an MfaRecoveryError. It also doesn't check that each escrow's returned version equals expectedVersion, which would catch a version mismatch before asking for an approval and wallet signatures.

Failing the write on a lookup failure is intentional, and Cubist already normalizes those errors. Earlier version checks are useful, but must distinguish conflicts from already-applied mutations; #11200 adds that reconciliation handling.

@huggingbot

Copy link
Copy Markdown
Member Author

getIdentifiers ignores a pending mutation. It returns an epoch even when a mutation is in flight. A caller who builds updateIdentifiers from that result then hits pending_mutation. Consider rejecting, or returning the current phase alongside the result.

Reads are intentionally allowed while a mutation is pending. Callers can use resume() before starting another write.

@ieow ieow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@ieow
ieow added this pull request to the merge queue Nov 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@ieow
ieow added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 4a2704b Nov 10, 2026
43 checks passed
@ieow
ieow deleted the feat/mfa-recovery-get-identifiers branch November 10, 2026 02:00
Naz-Ovh pushed a commit to 0x-fork/metamask-core that referenced this pull request Nov 14, 2026
)

## Explanation

Stacked on MetaMask#11149. SIWE wallets prove control themselves (Auth doesn't
vouch for them).

- `applyMutation` takes `IdentifierAuthorization[]`, sharing one
challenge per escrow.
- Each SIWE identifier an escrow hasn't enrolled gets a proof, including
at `register`. SIWE is exempt from the `approvedIdentifiers` check.

## References

- Escrow:
consensys-vertical-apps/cubist-secret-escrow#7

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by updating changelogs
for packages I've changed
- [ ] I've introduced breaking changes in this PR and have prepared
draft pull requests for clients and consumer packages to resolve them

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants