@bymax-one/nest-auth 1.4.19 → 1.4.20

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
@@ -18,6 +18,49 @@ what moves, and that note is the compatibility contract until strict SemVer begi
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [1.4.20] - 2026-11-07
22
+
23
+ ### Apply to a derived backend
24
+
25
+ - **`SelfOrAdminGuard` no longer admits a request addressed to another tenant.** It decided by the
26
+ caller's id and role alone, so a token for tenant `t1` and user `u1` was admitted on
27
+ `/tenants/t2/users/u1`, and the `admin` role, which is held inside one tenant, was admitted on any
28
+ tenant's users; the guard's documentation left the tenant check to the controller. When the route
29
+ captures the tenant as `tenantId`, `tenant_id` or `tenant`, every capture present must now equal
30
+ the token's `tenantId`, otherwise the guard answers `INSUFFICIENT_ROLE` (`403`) before it looks at
31
+ the id or the role. Captures that disagree with one another, are empty, or are arrays are refused,
32
+ and so is a token with no tenant. A route that captures no tenant is not tenant-checked, and
33
+ the controller or service must still enforce the tenant there. A host that relied on the guard
34
+ to admit an admin across tenants on such a route now gets a `403`. The `userId` or `id` capture
35
+ must now be one non-empty path segment: an empty value or one carrying a slash (a decoded `%2F`)
36
+ is refused with `INSUFFICIENT_ROLE` for an admin as well, and so is an owner whose own id contains a
37
+ slash, who could reach their own resource through a `%2F` before. A route that names the tenant any
38
+ other way, or sits on a router mounted without `mergeParams`, is not tenant-checked either.
39
+
40
+ ### Fixed
41
+
42
+ - **A cross-tenant request is no longer admitted by `SelfOrAdminGuard`.** See the note above.
43
+
44
+ ### Changed
45
+
46
+ - **`MfaService` moves private methods to internal modules.** They moved out of the class as plain
47
+ functions; behaviour, error codes and log text are unchanged, and none of them was part of the
48
+ public API.
49
+
50
+ ### Documentation
51
+
52
+ - **The shared contract states when the password-reset cooldown is released.**
53
+ `responseBodies.passwordResetRequest.failures.cooldown` said "released on any failure"; it now says
54
+ the cooldown is released when the request itself observes the failure (the account lookup, the
55
+ code or token store, or a send awaited inside the request), and that a send which fails after the
56
+ response has left never releases it. No behaviour changes. The contract's sha256 changes with it, so a copy kept elsewhere is refreshed
57
+ from `conformance/wire-contract.json`.
58
+ - **Correction to the 1.4.19 notes on the resend cooldown.** The 1.4.19 entry for the password-reset
59
+ `500` split says the cooldown a request took "is released on any failure". That is wrong for a
60
+ send that fails after the response has left (a detached send): it keeps the cooldown, as the code
61
+ and its documentation state. The cooldown is released only for a failure the request
62
+ itself observes. The 1.4.19 text stands as published; this line supersedes it.
63
+
21
64
  ## [1.4.19] - 2026-11-07
22
65
 
23
66
  ### Apply to a derived backend
@@ -4557,7 +4600,8 @@ ever installable.
4557
4600
  - 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
4558
4601
  - 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
4559
4602
 
4560
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.19...HEAD
4603
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.20...HEAD
4604
+ [1.4.20]: https://github.com/bymaxone/nest-auth/compare/v1.4.19...v1.4.20
4561
4605
  [1.4.19]: https://github.com/bymaxone/nest-auth/compare/v1.4.18...v1.4.19
4562
4606
  [1.4.18]: https://github.com/bymaxone/nest-auth/compare/v1.4.17...v1.4.18
4563
4607
  [1.4.17]: https://github.com/bymaxone/nest-auth/compare/v1.4.16...v1.4.17
package/README.md CHANGED
@@ -2263,7 +2263,7 @@ conditional on nothing having invalidated in between, which this service does no
2263
2263
  | `ApiKeyGuard` | `@ServiceKey('read')` | Service API key for machine callers; fails closed without scopes |
2264
2264
 
2265
2265
  > [!NOTE]
2266
- > Three additional guards — `SelfOrAdminGuard` (ownership checks), `OptionalAuthGuard` (routes that behave differently for anonymous vs authenticated users), and `WsJwtGuard` (JWT authentication on WebSocket gateways) — are exported from the public `@bymax-one/nest-auth` barrel. Use them exactly like the core guards above.
2266
+ > Three additional guards — `SelfOrAdminGuard` (ownership checks), `OptionalAuthGuard` (routes that behave differently for anonymous vs authenticated users), and `WsJwtGuard` (JWT authentication on WebSocket gateways) — are exported from the public `@bymax-one/nest-auth` barrel. Use them exactly like the core guards above. `SelfOrAdminGuard` also holds a route that captures the tenant (`:tenantId`, `:tenant_id` or `:tenant`) to the token's tenant: a capture that differs from `req.user.tenantId`, disagrees with another capture, or is empty is refused with `403` before the self-or-admin decision, so neither a matching id nor the `admin` role reaches into another tenant. A wildcard capture arrives as an array and is refused, and the id (`:userId` or `:id`) must be one non-empty path segment, so an empty value or a decoded `%2F` is refused too. Only those three capture names are read: a route that names the tenant `{org}` or captures none is decided by identity and role alone, and your handler must bind the tenant itself. If a capture name is used at two nesting levels Express keeps the inner value, and a parent router mounted without `mergeParams` does not expose its captures to the inner route, so the guard does not see them.
2267
2267
 
2268
2268
  ### One error envelope
2269
2269