@bymax-one/nest-auth 1.3.1 → 1.4.0

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
@@ -5,7 +5,76 @@ All notable changes to `@bymax-one/nest-auth` will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [Unreleased]
8
+ ## [1.4.0] - 2026-08-11
9
+
10
+ ### Changed
11
+
12
+ - **BREAKING: `ioredis` peer range raised to `^6.0.0`** ([`package.json`](package.json); the `^5`
13
+ and `^6` ranges are disjoint, so an existing ioredis 5 consumer no longer satisfies the peer
14
+ contract). A host that also
15
+ runs `@bymax-one/nest-queue` (which peers `ioredis ^6.0.0`) can now resolve a single copy of
16
+ `ioredis` across the workspace, which is what lets a queue `Redis` and the client injected here
17
+ as `BYMAX_AUTH_REDIS_CLIENT` be the same instance and typecheck as such. The bump is a peer
18
+ contract only: this package imports `ioredis` for its `Redis` type alone — it never constructs a
19
+ client — so no runtime path changed. ioredis 6 defaults to the RESP3 protocol but keeps its
20
+ legacy reply mapping, so every reply shape this library reads is byte-for-byte what it read under
21
+ ioredis 5; the wire contract with `rust-auth` is untouched. **Apply to a derived backend:** raise the
22
+ `ioredis` version your app installs to `^6.0.0` so it satisfies the new peer range.
23
+
24
+ - **Mutation gate raised to a perfect score** ([`stryker.config.json`](stryker.config.json)). The
25
+ `break`, `high` and `low` thresholds are now 100, and the suite meets it: every mutant in
26
+ `src/` is killed or a documented equivalent, with no survivors. Six equivalent mutants in
27
+ `otp.service.ts` — the empty-code guard and the EXPIRED/MAX arms of `verify`, each of which
28
+ answers the same `OTP_INVALID` after the same padding as the constant-time comparison that
29
+ follows — are marked inline with their reason rather than being removed, keeping the verifier's
30
+ defense in depth and anti-enumeration structure intact. **Apply to a derived backend:** if your
31
+ backend runs the shared mutation gate, expect it to require 100 rather than 95.
32
+
33
+ ## [1.3.2] - 2026-08-10
34
+
35
+ Binds the MFA challenge to its tenant and scopes every MFA key, counter and write by it — the
36
+ multi-tenant hardening rust-auth mirrors byte-for-byte. It stays in the 1.3.x line, where the
37
+ library still has no published dependents; the one breaking change is the
38
+ `IUserRepository.updateMfa` signature, which a derived backend adopts as it upgrades.
39
+
40
+ ### Security
41
+
42
+ - **The MFA challenge is bound to its tenant, and every MFA key is scoped by it.** The MFA temp
43
+ token carried no tenant, so the challenge resolved its subject by id across every tenant
44
+ (`findById(sub)` with no tenant) — and the status gate, the decrypted secret, the recovery
45
+ digests and the account the session was finally minted for all ran against whatever row the
46
+ repository returned. A library cannot assume a host's user ids are unique across tenants —
47
+ `findById` takes a tenant precisely because they may not be — so under a schema that numbers users
48
+ per tenant, every tenant has a user `1`. The token now carries `tenantId` (present on the
49
+ dashboard plane, absent on the platform plane), `verifyMfaTempToken` refuses a dashboard token
50
+ that lacks it and a platform token that carries it — a refusal, not a fallback (RFC 8725 §3.9 /
51
+ §3.12, ASVS 5.0 6.6.2) — and `assertPlaneTenant` enforces the same rule at the five public
52
+ `MfaService` entry points before any repository read.
53
+
54
+ - **Eight MFA store keys and failure counters were scoped by plane but not by tenant**, so two
55
+ tenants' user `1` shared all of them. The three `lf:` counters were the worst: a shared lockout
56
+ counter is a credential-free cross-tenant lockout — failures against one tenant's user spend
57
+ another's budget, and a success on either clears the other — which is not the per-subscriber
58
+ rate limiting NIST SP 800-63B requires. All eight now derive from one tenant-scoped `mfaSubject`,
59
+ driven by the plane rather than by whether a tenant was supplied. The wire contract gains
60
+ `mfaSubjectPreimages` and `mfaSubjectDerivedKeys`, pinning the shape rust-auth mirrors byte-for-byte.
61
+
62
+ - **The MFA write is scoped by tenant too, and a blank tenant is refused.** Every MFA transition
63
+ writes — the recovery-code splice and the key-rotation re-encrypt — and both wrote through
64
+ `updateMfa(id, data)`, keyed by id alone, so under colliding ids the write could land on another
65
+ tenant's row and leave a spent recovery code in the list. **`IUserRepository.updateMfa` now takes
66
+ the tenant: `updateMfa(id, tenantId, data)`** — a breaking change that forces every implementation
67
+ to scope the write as its read is scoped (the platform repository is unchanged). And
68
+ `assertPlaneTenant` now refuses a blank `tenantId`, not merely a missing one: `''` — what an unset
69
+ environment variable becomes — would build `dashboard::{userId}`, a third keyspace.
70
+
71
+ **Apply to a derived backend:** upgrade and deploy this release **in full** before the one that
72
+ follows it. For a rolling upgrade this release dual-writes the anti-replay marker and the three
73
+ failure counters (every read consults both the old plane-only key and the new tenant-scoped key,
74
+ every write touches both) and dual-acquires the transition lock, so old and new pods stay
75
+ consistent while both are live. A later release drops the legacy arm; deploying it before this one
76
+ has fully rolled out would split the anti-replay and lockout state across the two key shapes. No
77
+ host code changes: the tenant is sourced from the authenticated account, never from the request.
9
78
 
10
79
  ## [1.3.1] - 2026-08-08
11
80
 
@@ -1273,7 +1342,9 @@ ever installable.
1273
1342
  - 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
1343
  - 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
1344
 
1276
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.3.1...HEAD
1345
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.3.2...HEAD
1346
+ [1.4.0]: https://github.com/bymaxone/nest-auth/compare/v1.3.2...v1.4.0
1347
+ [1.3.2]: https://github.com/bymaxone/nest-auth/compare/v1.3.1...v1.3.2
1277
1348
  [1.3.1]: https://github.com/bymaxone/nest-auth/compare/v1.3.0...v1.3.1
1278
1349
  [1.3.0]: https://github.com/bymaxone/nest-auth/compare/v1.2.0...v1.3.0
1279
1350
  [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,
@@ -956,7 +958,7 @@ When integrating `@bymax-one/nest-auth` in production, verify each of the follow
956
958
  Authentication is critical infrastructure, so the suite is held to a bar beyond "it runs" — every behavior is pinned so that a regression **fails a test**.
957
959
 
958
960
  - ✅ **100% line coverage** — statements, branches, functions, and lines, enforced as a release gate across unit + e2e
959
- - ✅ **100% mutation score** — verified with [Stryker](https://stryker-mutator.io/): 4,870 seeded faults detected (4,849 killed, 21 timed out), **no survivors and nothing left uncovered**, against a `break` threshold of 95 ([measured cold on 2026-08-08](./docs/mutation_testing_results.md#re-measured-cold--2026-08-08))
961
+ - ✅ **100% mutation score** — verified with [Stryker](https://stryker-mutator.io/): 4,870 seeded faults detected (4,849 killed, 21 timed out), **no survivors and nothing left uncovered**, against a `break` threshold of 100 ([measured cold on 2026-08-08](./docs/mutation_testing_results.md#re-measured-cold--2026-08-08))
960
962
  - ✅ **3,547 tests** — 3,420 unit and 127 end-to-end, spanning all five subpaths
961
963
  - ✅ **Every equivalent mutant documented** — the 350 mutants that no test can kill (a redundant guard, a dependency array of stable references) each carry an inline `// Stryker disable` with the reason, so the score is an accounting rather than a number
962
964