chore(deps): replace uuid with native crypto - #20956
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates UUID generation across the FxA monorepo from the uuid npm package to Node/browser-native crypto APIs, reducing dependency surface while preserving deterministic UUIDv5 output for Nimbus IDs (a stored-data contract).
Changes:
- Replace most UUIDv4 call sites with
crypto.randomUUID()orcrypto.randomBytes(16)(hex/buffer as appropriate). - Remove
uuid/@types/uuidfrom select package manifests, while bumping the remaining requireduuiddependency to^11.1.1. - Add a local
uuidv5implementation and fixed-vector tests, and update Nimbus ID derivation to use it.
Reviewed changes
Copilot reviewed 58 out of 59 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Removes @types/uuid entries and updates uuid resolution to ^11.1.1. |
| package.json | Bumps root uuid to ^11.1.1 and removes @types/uuid. |
| packages/fxa-shared/package.json | Drops uuid and @types/uuid from devDependencies. |
| packages/fxa-shared/test/sentry/pii-filter-actions.ts | Switches token UUID generation in tests to crypto.randomUUID(). |
| packages/fxa-shared/test/experiments/base.js | Replaces uuid.v4() in experiment chooser tests with crypto.randomUUID(). |
| packages/fxa-shared/speed-trap/guid.js | Replaces uuidv4() with crypto.randomUUID() for SpeedTrap UUIDs. |
| packages/fxa-settings/package.json | Drops uuid and @types/uuid from dependencies/devDependencies. |
| packages/fxa-settings/src/setupTests.tsx | Extends the Jest crypto shim to include randomUUID. |
| packages/fxa-settings/src/lib/metrics.ts | Switches device/user UUID generation to crypto.randomUUID(). |
| packages/fxa-settings/src/lib/metrics-flow.ts | Switches deviceId generation to crypto.randomUUID(). |
| packages/fxa-settings/src/lib/cache.ts | Switches uniqueUserId generation to crypto.randomUUID(). |
| packages/fxa-event-broker/package.json | Drops uuid and @types/uuid from dependencies/devDependencies. |
| packages/fxa-event-broker/src/jwtset/jwtset.service.ts | Switches JWT jti to crypto.randomUUID(). |
| packages/fxa-event-broker/src/firestore/firestore.service.spec.ts | Uses crypto.randomUUID() in test UIDs. |
| packages/fxa-auth-server/package.json | Bumps uuid to ^11.1.1 and removes @types/uuid. |
| packages/fxa-auth-server/test/remote/totp.in.spec.ts | Switches JWT jti to crypto.randomUUID(). |
| packages/fxa-auth-server/test/remote/recovery_email_emails.in.spec.ts | Switches JWT jti to crypto.randomUUID(). |
| packages/fxa-auth-server/test/remote/recovery_email_change_email.in.spec.ts | Switches JWT jti to crypto.randomUUID() and reformats long calls. |
| packages/fxa-auth-server/test/remote/recovery_codes.in.spec.ts | Switches JWT jti to crypto.randomUUID() and reformats long objects/calls. |
| packages/fxa-auth-server/test/remote/push_db_tests.in.spec.ts | Replaces UUIDv4-buffer-to-hex uid generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/test/remote/password_change.in.spec.ts | Switches JWT jti to crypto.randomUUID(). |
| packages/fxa-auth-server/test/remote/db.in.spec.ts | Replaces UUIDv4-buffer-to-hex uid generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/unblock-codes.spec.ts | Replaces UUIDv4-buffer-to-hex uid generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/subscriptions/support.spec.ts | Replaces UUIDv4-buffer-to-hex UID constant with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/subscriptions/stripe.spec.ts | Replaces UUIDv4-buffer-to-hex UID constants with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/subscriptions/stripe-webhooks.spec.ts | Replaces UUIDv4-buffer-to-hex UID constant with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/subscriptions/play-pubsub.spec.ts | Replaces UUIDv4-buffer-to-hex UID constant with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/subscriptions/paypal-notifications.spec.ts | Replaces UUIDv4-buffer-to-hex UID constant with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/subscriptions/mozilla.spec.ts | Replaces UUIDv4-buffer-to-hex UID constant with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/subscriptions/google.spec.ts | Replaces UUIDv4-buffer-to-hex UID constant with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/security-events.spec.ts | Replaces UUIDv4-buffer-to-hex UID constant with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/recovery-key.spec.ts | Replaces UUIDv4-buffer-to-hex uid constant with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/mfa.ts | Switches JWT jti to crypto.randomUUID(). |
| packages/fxa-auth-server/lib/routes/passwordless.ts | Switches account uid generation to await random.hex(16). |
| packages/fxa-auth-server/lib/routes/linked-accounts.ts | Switches account uid generation to await random.hex(16). |
| packages/fxa-auth-server/lib/routes/account.ts | Switches account uid generation to await random.hex(16) (multiple call sites) and reformats import. |
| packages/fxa-auth-server/lib/routes/auth-schemes/mfa.spec.ts | Switches JWT jti to crypto.randomUUID() and expands inline object formatting. |
| packages/fxa-auth-server/lib/routes/passwordless.spec.ts | Replaces UUIDv4-buffer-to-hex uid generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/password.spec.ts | Replaces UUIDv4-buffer-to-hex uid generation with crypto.randomBytes(16).toString('hex') across test cases. |
| packages/fxa-auth-server/lib/routes/ip-profiling.spec.ts | Replaces uuid-based UID generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/emails.spec.ts | Replaces uuid-based uid/deviceId generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/devices-and-sessions.spec.ts | Replaces uuid-based uid generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/attached-clients.spec.ts | Replaces uuid-based uid generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/routes/account.spec.ts | Replaces uuid-based uid generation with crypto.randomBytes(16).toString('hex') across test cases. |
| packages/fxa-auth-server/lib/payments/stripe.spec.ts | Replaces uuid usage in tests with crypto.randomUUID() (string form). |
| packages/fxa-auth-server/lib/devices.spec.ts | Replaces uuid-based uid generation with crypto.randomBytes(16).toString('hex'). |
| packages/fxa-auth-server/lib/account-delete.spec.ts | Replaces uuid-based uid buffer generation with crypto.randomBytes(16). |
| libs/shared/sentry/src/lib/pii/filter-actions.spec.ts | Switches token UUID generation in tests to crypto.randomUUID(). |
| libs/shared/sentry-utils/src/lib/pii/filter-actions.spec.ts | Switches token UUID generation in tests to crypto.randomUUID(). |
| libs/shared/experiments/src/lib/utils/uuidv5.ts | Adds local deterministic UUIDv5 implementation using SHA-1. |
| libs/shared/experiments/src/lib/utils/uuidv5.spec.ts | Adds fixed-vector tests to lock UUIDv5 output for Nimbus IDs. |
| libs/shared/experiments/src/lib/utils/generateNimbusId.ts | Switches Nimbus ID generation from uuid package v5 to local uuidv5. |
| libs/shared/db/mysql/core/src/lib/core.ts | Replaces uuidv4-based hex ID generator with crypto.randomBytes(16).toString('hex'). |
| libs/shared/db/mysql/account/src/lib/tests.ts | Switches test DB name generation to crypto.randomUUID(). |
| libs/shared/account/account/src/lib/account.manager.ts | Switches account stub uid generation to randomBytesAsync(16) instead of UUIDv4. |
| libs/payments/cart/src/lib/cart.manager.ts | Replaces UUIDv4 buffer cart id generation with crypto.randomBytes(16). |
| libs/payments/cart/src/lib/cart.manager.in.spec.ts | Replaces UUIDv4-buffer-to-hex test ID generation with crypto.randomBytes(16).toString('hex'). |
| apps/payments/next/app/[locale]/subscriptions/payments/stripe/page.tsx | Switches instanceKey UUID generation to crypto.randomUUID() for server component rendering. |
| apps/payments/next/app/[locale]/subscriptions/payments/stripe/page.test.tsx | Updates UUID mocking to mock crypto instead of uuid, and adjusts test naming. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 58 out of 59 changed files in this pull request and generated no new comments.
Suppressed comments (1)
packages/fxa-shared/speed-trap/guid.js:10
guid()assumes the globalcrypto.getRandomValuesexists. In older browsers, non-browser execution, or insecure contexts wherecryptois missing/partial, this will throw duringspeedTrap.init()and break page telemetry (and potentially page load if unhandled). Add a small capability check and fallback so speed-trap remains non-fatal when WebCrypto is unavailable.
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
| import { v4 as uuidv4 } from 'uuid'; | ||
|
|
||
| import crypto from 'crypto'; |
There was a problem hiding this comment.
Nit, offical docs say to use node:crypto. Do this in all imports.
| "twilio": "5.3.5", | ||
| "typedi": "^0.8.0", | ||
| "uuid": "^10.0.0", | ||
| "uuid": "^11.1.1", |
There was a problem hiding this comment.
Do we need this in the root? It sounds like it's only needed by auth-server now.
Because
uuidwas a direct dependency in five manifests with open Dependabot alerts.cryptocovers every use we had.This pull request
uuidcall sites withcrypto.randomBytes(16)orcrypto.randomUUID().uuidand@types/uuidfrom fxa-settings, fxa-shared and fxa-event-broker.uuidto^11.1.1in root and auth-server, which still need it for autogenerated Glean code.uuidv5forgenerateNimbusId, verified bit-exact against the old package over 5110 vectors.random.hex(16)helper for auth-server uid generation to satisfyfxa/async-crypto-random.randomUUIDto the fxa-settings test crypto shim, and explicitcryptoimports where Jest's node env lacks the global.Issue that this pull request solves
Closes: FXA-13926
Checklist
Put an
xin the boxes that applyHow to review (Optional)
account.ts,linked-accounts.ts,passwordless.tsandaccount.manager.ts(uid generation) pluscart.manager.ts(cart id).uuidv5.tsbacks Nimbus IDs, which Glean Shredder re-derives to delete telemetry, so its output is a stored-data contract.Other information (Optional)
uuidcannot be fully removed yet: glean_parser's template emitsimport { v4 as uuidv4 } from 'uuid'into generated Glean code, and the payments copy is regenerated on every build.