@bymax-one/nest-auth 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,52 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.3.2] - 2026-08-10
11
+
12
+ Binds the MFA challenge to its tenant and scopes every MFA key, counter and write by it — the
13
+ multi-tenant hardening rust-auth mirrors byte-for-byte. It stays in the 1.3.x line, where the
14
+ library still has no published dependents; the one breaking change is the
15
+ `IUserRepository.updateMfa` signature, which a derived backend adopts as it upgrades.
16
+
17
+ ### Security
18
+
19
+ - **The MFA challenge is bound to its tenant, and every MFA key is scoped by it.** The MFA temp
20
+ token carried no tenant, so the challenge resolved its subject by id across every tenant
21
+ (`findById(sub)` with no tenant) — and the status gate, the decrypted secret, the recovery
22
+ digests and the account the session was finally minted for all ran against whatever row the
23
+ repository returned. A library cannot assume a host's user ids are unique across tenants —
24
+ `findById` takes a tenant precisely because they may not be — so under a schema that numbers users
25
+ per tenant, every tenant has a user `1`. The token now carries `tenantId` (present on the
26
+ dashboard plane, absent on the platform plane), `verifyMfaTempToken` refuses a dashboard token
27
+ that lacks it and a platform token that carries it — a refusal, not a fallback (RFC 8725 §3.9 /
28
+ §3.12, ASVS 5.0 6.6.2) — and `assertPlaneTenant` enforces the same rule at the five public
29
+ `MfaService` entry points before any repository read.
30
+
31
+ - **Eight MFA store keys and failure counters were scoped by plane but not by tenant**, so two
32
+ tenants' user `1` shared all of them. The three `lf:` counters were the worst: a shared lockout
33
+ counter is a credential-free cross-tenant lockout — failures against one tenant's user spend
34
+ another's budget, and a success on either clears the other — which is not the per-subscriber
35
+ rate limiting NIST SP 800-63B requires. All eight now derive from one tenant-scoped `mfaSubject`,
36
+ driven by the plane rather than by whether a tenant was supplied. The wire contract gains
37
+ `mfaSubjectPreimages` and `mfaSubjectDerivedKeys`, pinning the shape rust-auth mirrors byte-for-byte.
38
+
39
+ - **The MFA write is scoped by tenant too, and a blank tenant is refused.** Every MFA transition
40
+ writes — the recovery-code splice and the key-rotation re-encrypt — and both wrote through
41
+ `updateMfa(id, data)`, keyed by id alone, so under colliding ids the write could land on another
42
+ tenant's row and leave a spent recovery code in the list. **`IUserRepository.updateMfa` now takes
43
+ the tenant: `updateMfa(id, tenantId, data)`** — a breaking change that forces every implementation
44
+ to scope the write as its read is scoped (the platform repository is unchanged). And
45
+ `assertPlaneTenant` now refuses a blank `tenantId`, not merely a missing one: `''` — what an unset
46
+ environment variable becomes — would build `dashboard::{userId}`, a third keyspace.
47
+
48
+ **Apply to a derived backend:** upgrade and deploy this release **in full** before the one that
49
+ follows it. For a rolling upgrade this release dual-writes the anti-replay marker and the three
50
+ failure counters (every read consults both the old plane-only key and the new tenant-scoped key,
51
+ every write touches both) and dual-acquires the transition lock, so old and new pods stay
52
+ consistent while both are live. A later release drops the legacy arm; deploying it before this one
53
+ has fully rolled out would split the anti-replay and lockout state across the two key shapes. No
54
+ host code changes: the tenant is sourced from the authenticated account, never from the request.
55
+
10
56
  ## [1.3.1] - 2026-08-08
11
57
 
12
58
  Adds the revocation checker and the overridable default auth-email provider, carries the tenant
@@ -1273,7 +1319,8 @@ ever installable.
1273
1319
  - Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
1274
1320
  - Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
1275
1321
 
1276
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.3.1...HEAD
1322
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.3.2...HEAD
1323
+ [1.3.2]: https://github.com/bymaxone/nest-auth/compare/v1.3.1...v1.3.2
1277
1324
  [1.3.1]: https://github.com/bymaxone/nest-auth/compare/v1.3.0...v1.3.1
1278
1325
  [1.3.0]: https://github.com/bymaxone/nest-auth/compare/v1.2.0...v1.3.0
1279
1326
  [1.2.0]: https://github.com/bymaxone/nest-auth/compare/v1.1.1...v1.2.0
package/README.md CHANGED
@@ -209,9 +209,11 @@ export class PrismaUserRepository implements IUserRepository {
209
209
  await this.prisma.user.update({ where: { id }, data: { passwordHash } })
210
210
  }
211
211
 
212
- async updateMfa(id: string, data: UpdateMfaData): Promise<void> {
213
- await this.prisma.user.update({
214
- where: { id },
212
+ async updateMfa(id: string, tenantId: string | undefined, data: UpdateMfaData): Promise<void> {
213
+ // Scoped by tenant, like findById: `updateMany` with both id and tenantId so an id shared
214
+ // across tenants cannot cross the write onto the wrong account.
215
+ await this.prisma.user.updateMany({
216
+ where: { id, tenantId },
215
217
  data: {
216
218
  mfaEnabled: data.mfaEnabled,
217
219
  mfaSecret: data.mfaSecret,