@bymax-one/nest-auth 1.5.8 → 1.5.10
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 +125 -1
- package/README.md +13 -1
- package/dist/server/index.cjs +670 -173
- package/dist/server/index.d.cts +4 -4
- package/dist/server/index.d.ts +4 -4
- package/dist/server/index.mjs +670 -173
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,128 @@ what moves, and that note is the compatibility contract until strict SemVer begi
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [1.5.10] - 2026-11-18
|
|
22
|
+
|
|
23
|
+
A patch release.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **A flag that is not `true` or `false`, and an option that is not one of its documented values, are refused at startup.**
|
|
28
|
+
A flag is read as `if (x)` in some places and `=== false` in others, so a value that is neither was decided by whichever
|
|
29
|
+
reader saw it: `rateLimit.enabled: ''` (an unset environment variable) switched the rate-limit guard off while the boot
|
|
30
|
+
check still read it as enabled, `emailVerification.required: ''` let login skip the verification, and `'false'` was
|
|
31
|
+
truthy. An option compared with `===` fell through to its default branch on a typo: `environment: 'prodution'` was read
|
|
32
|
+
as not production and dropped `Secure` from every cookie with no error, a misspelled `tokenDelivery` issued cookies, and a
|
|
33
|
+
misspelled `passwordReset.method` silently used the token flow. Every flag (a `controllers` flag passed to
|
|
34
|
+
`registerAsync` included; `workspaces.allowCreate` may also be a function) must be exactly `true` or `false`, and an
|
|
35
|
+
option with a documented set of values must be one of them, with no case folding. The refusal
|
|
36
|
+
names the type of a string and never prints it. A spec reads the option interfaces and fails when a new flag or
|
|
37
|
+
documented-set option is declared and not listed in the validator.
|
|
38
|
+
- `registerAsync` inspects the hooks and the email provider when they are ready-made `useValue` objects: a hook that is
|
|
39
|
+
present and not a function, and an email provider without a method the library calls unguarded, are refused when it is
|
|
40
|
+
called instead of at the first event that fires them. A class, a factory or an alias is not inspected.
|
|
41
|
+
|
|
42
|
+
- `oauth` and `roles` are read by property access too, so a typed configuration class whose `hierarchy`, `platformHierarchy`
|
|
43
|
+
or provider block is a getter on its prototype takes effect. 1.5.9 read the fixed-key groups that way and left these two
|
|
44
|
+
as given, so a class with such a getter reached the validators with no hierarchy or no provider block: startup failed
|
|
45
|
+
or OAuth stayed unconfigured, never a looser setting. A `null` in either is still refused by name.
|
|
46
|
+
- `jwt.accessExpiresIn`'s refusals no longer quote the value: the unreadable case names the type received and the
|
|
47
|
+
too-long case states the lifetime in seconds.
|
|
48
|
+
|
|
49
|
+
### Apply to a derived backend
|
|
50
|
+
|
|
51
|
+
A configuration that booted before is refused at startup when it sets a flag or an option with a documented set of values to
|
|
52
|
+
anything else. `undefined` and `null` still mean the default. An environment variable must be converted before it is passed
|
|
53
|
+
(`process.env.X === 'true'`), and `environment` must be spelled exactly as documented. A
|
|
54
|
+
`BYMAX_AUTH_EMAIL_PROVIDER` registered as an object needs the email methods the library calls without a guard; the
|
|
55
|
+
other methods stay optional, and one that is present must be a function.
|
|
56
|
+
|
|
57
|
+
Also refused at `registerAsync`: a `BYMAX_AUTH_EMAIL_PROVIDER` `useValue`, or a `BYMAX_AUTH_HOOKS` one that is not nullish, that is not an object, and a
|
|
58
|
+
hook (any of the hooks the library calls by name) that is present and not a function. A `null` hook counts as absent.
|
|
59
|
+
A `controllers` flag passed to `registerAsync` is checked like every other flag, and a `null` flag is unset.
|
|
60
|
+
`workspaces.allowCreate` may be `true`, `false` or a function. A refusal of `jwt.accessExpiresIn` has new wording; a test
|
|
61
|
+
or a log filter that matches the old text must change.
|
|
62
|
+
|
|
63
|
+
## [1.5.9] - 2026-11-17
|
|
64
|
+
|
|
65
|
+
A patch release.
|
|
66
|
+
|
|
67
|
+
### Fixed
|
|
68
|
+
|
|
69
|
+
- **A numeric option that is `NaN`, a fraction, a negative or a string is refused at startup, where two of them switched
|
|
70
|
+
a security bound off.** A bound written as `x < min || x > max` accepts `NaN`, because a comparison with `NaN` is false
|
|
71
|
+
both ways. `sessions.defaultMaxSessions: NaN` evicted no session (`length <= NaN` is false and `slice(0, NaN)` is empty),
|
|
72
|
+
so the concurrent-session cap did not exist, and `jwt.absoluteSessionLifetimeDays: NaN` skipped the 30-day
|
|
73
|
+
reauthentication cap that only `0` may switch off. The bounds on `passwordReset.otpLength`, `mfa.totpWindow`,
|
|
74
|
+
`mfa.recoveryCodeCount` and `jwt.refreshGraceWindowSeconds` accepted `NaN` and a fraction too, and failed at runtime
|
|
75
|
+
instead of at boot; other numeric options had no check at all. One module, `config/numeric-options.ts`, now tests each
|
|
76
|
+
value as a whole number (for the lifetime in days, a finite one) before it applies a range with a ceiling, because
|
|
77
|
+
`Number.isInteger(1e300)` is true and a value that large overflows the expiry Redis accepts or the lifetime the cap compares to.
|
|
78
|
+
- **An option that has a default and holds `undefined` or `null` is unset, so its default applies, never "no bound".** The defaults were
|
|
79
|
+
spread under the host's group, so an own key holding `undefined` replaced the default: `Number(process.env.X) || undefined`
|
|
80
|
+
switched the session cap (`sessions.defaultMaxSessions`) and the absolute lifetime cap off, which is the `NaN` bug reached
|
|
81
|
+
through a different value. The options are read once, by property access, into a plain object without the unset keys, at the top level and in
|
|
82
|
+
each option group with fixed keys, so a group that is a typed configuration class is read like an object literal and every default and
|
|
83
|
+
every validator sees the same thing. `null` follows the same rule: some options refused it and some took it through
|
|
84
|
+
`??`. The options that hold a host-defined map or a required value are the exception, and refuse `null` by name:
|
|
85
|
+
`oauth.successRedirectUrl`, `oauth.mfaRedirectUrl`, `oauth.errorRedirectUrl`, `oauth.<provider>`, each
|
|
86
|
+
`roles.hierarchy.<role>` and each `workspaces.permissions.<action>`. `oauth.<provider>` and
|
|
87
|
+
`roles.hierarchy.<role>` refuse `undefined` as well. `jwt.secret` and `roles.hierarchy` have no default, so a
|
|
88
|
+
`null` or `undefined` there is refused as required.
|
|
89
|
+
- `jwt.accessCookieMaxAgeMs` has a floor of 1000: the cookie `Max-Age` is sent in whole seconds, so 1 to 999 became
|
|
90
|
+
`Max-Age=0`, which deletes the cookie.
|
|
91
|
+
- A refusal that receives a value that is not a number, `null` or `undefined` names its type (`received a string`) and does not print it, so a secret
|
|
92
|
+
passed to the wrong option does not reach a log; a number is printed, because `NaN` or `1e300` is what an operator needs to see.
|
|
93
|
+
`jwt.accessExpiresIn`'s refusal still quotes its value; it is fixed in 1.5.10. A message that said `Got: 1.1` for `jwt.refreshExpiresInDays` states the rule:
|
|
94
|
+
days × 86400 must be a whole number of seconds when computed in floating point; 1.5 and 0.25 are, 1.1 and 0.7 are not.
|
|
95
|
+
- A message override of `DefaultAuthEmailProvider` that holds `undefined` keeps the default copy; it threw a `TypeError`
|
|
96
|
+
(`is not a function`) when the message was built.
|
|
97
|
+
- `userStatusCacheTtlSeconds` has a ceiling of 3600 seconds. It is the window in which a suspended account still passes
|
|
98
|
+
the dashboard guards, so it is a security bound and not a tuning knob.
|
|
99
|
+
|
|
100
|
+
### Apply to a derived backend
|
|
101
|
+
|
|
102
|
+
A configuration that booted before is refused at startup when it sets any of these. The message names the option, and
|
|
103
|
+
each line says what was accepted until now:
|
|
104
|
+
|
|
105
|
+
- `sessions.defaultMaxSessions`: anything but a whole number from 1 to 1000. Any number booted, including `NaN` (no
|
|
106
|
+
session was ever evicted), `0` and a negative.
|
|
107
|
+
- `jwt.absoluteSessionLifetimeDays`: anything but `0` (which switches the cap off) or a number of days from one hour
|
|
108
|
+
(`0.0417`) to 3650. Any number booted, including `NaN`, a negative, `Infinity` and `1e306`, whose length in
|
|
109
|
+
milliseconds overflows, so the cap was skipped.
|
|
110
|
+
- `jwt.refreshExpiresInDays`: more than 3650, or a value whose length in seconds is not a whole number. `1.1` days booted
|
|
111
|
+
and then every login failed, because Redis refuses `95040.00000000001` seconds; `1e300` booted too.
|
|
112
|
+
- `passwordReset.tokenTtlSeconds`, `passwordReset.otpTtlSeconds`, `emailVerification.otpTtlSeconds`,
|
|
113
|
+
`emailChange.tokenTtlSeconds`, `invitations.tokenTtlSeconds`: anything but a whole number from 1 to 315360000 (ten
|
|
114
|
+
years). Any number booted, and Redis refused the expiry on every request.
|
|
115
|
+
- `jwt.accessCookieMaxAgeMs`: from 1000 to ten years in milliseconds. Any number booted, and 1 to 999 sent `Max-Age=0`.
|
|
116
|
+
- `bruteForce.windowSeconds`: anything but a whole number from 1 to 604800 (one week). A window of months or years
|
|
117
|
+
booted and locked an account out for that long.
|
|
118
|
+
- `userStatusCacheTtlSeconds`: anything but a whole number from 1 to 3600. Any number booted.
|
|
119
|
+
- `password.parallelization`: more than 16. Any integer from 1 booted, and Node refuses scrypt parameters it cannot run
|
|
120
|
+
on the first derivation, which is the first login after deploy; each unit of `p` is a linear cost an unauthenticated
|
|
121
|
+
request pays.
|
|
122
|
+
- `passwordReset.otpLength` (4 to 8), `mfa.totpWindow`, `mfa.recoveryCodeCount` (1 to 50) and
|
|
123
|
+
`jwt.refreshGraceWindowSeconds` (0 to 300): `NaN`, a fraction, and a numeric string, which the range checks let
|
|
124
|
+
through. `Infinity` was already refused by the range.
|
|
125
|
+
|
|
126
|
+
`null` and `undefined` mean "unset" for every option that has a default: a host that passed `null` to an option that used to refuse it
|
|
127
|
+
boots with the default, and one that relied on an own key holding `undefined` to remove a cap gets the default cap. In
|
|
128
|
+
`jwt.absoluteSessionLifetimeDays` a numeric string such as `'30'` is newly refused; a string was already refused for
|
|
129
|
+
`jwt.refreshExpiresInDays`, which now also refuses more than 3650 days and a length that is not whole seconds.
|
|
130
|
+
|
|
131
|
+
Also refused or changed:
|
|
132
|
+
|
|
133
|
+
- `jwt.accessCookieMaxAgeMs` must be a whole number: `1500.5` booted before.
|
|
134
|
+
- `password.parallelization` has a ceiling of 16, and `sessions.defaultMaxSessions` one of 1000.
|
|
135
|
+
- A group or the options given as a class instance now take effect through their getters and prototype; those values
|
|
136
|
+
were ignored before, so a configuration that relied on the defaults for them now applies the values it declares.
|
|
137
|
+
- Refusal messages read `(received …)` where they read `(current: …)` or `(got: …)`, and a string is no longer quoted
|
|
138
|
+
(the OAuth `callbackUrl`, `rateLimit.clientIpSource` and the redirect URLs); a test or a log filter that matches
|
|
139
|
+
the old text must change.
|
|
140
|
+
|
|
141
|
+
A value read from an environment variable must be converted with `Number(...)` before it is passed, and checked for `NaN`.
|
|
142
|
+
|
|
21
143
|
## [1.5.8] - 2026-11-17
|
|
22
144
|
|
|
23
145
|
A patch release.
|
|
@@ -5255,7 +5377,9 @@ ever installable.
|
|
|
5255
5377
|
- 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
|
|
5256
5378
|
- 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
|
|
5257
5379
|
|
|
5258
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.
|
|
5380
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.10...HEAD
|
|
5381
|
+
[1.5.10]: https://github.com/bymaxone/nest-auth/compare/v1.5.9...v1.5.10
|
|
5382
|
+
[1.5.9]: https://github.com/bymaxone/nest-auth/compare/v1.5.8...v1.5.9
|
|
5259
5383
|
[1.5.8]: https://github.com/bymaxone/nest-auth/compare/v1.5.7...v1.5.8
|
|
5260
5384
|
[1.5.7]: https://github.com/bymaxone/nest-auth/compare/v1.5.6...v1.5.7
|
|
5261
5385
|
[1.5.6]: https://github.com/bymaxone/nest-auth/compare/v1.5.5...v1.5.6
|
package/README.md
CHANGED
|
@@ -307,6 +307,8 @@ export class PrismaUserRepository implements IUserRepository {
|
|
|
307
307
|
|
|
308
308
|
Email delivery is fully delegated to the consumer — the library never imports a mailer SDK. Implement `IEmailProvider` with your transport of choice (Resend, SendGrid, SES, Nodemailer) and bind it to the `BYMAX_AUTH_EMAIL_PROVIDER` token.
|
|
309
309
|
|
|
310
|
+
When the provider (or the `BYMAX_AUTH_HOOKS` object) is registered as a ready-made `useValue` object, `registerAsync` checks it when it is called: each member the library calls by name that is present must be a function (any other member of the object is yours and is not looked at), and the provider must carry the methods the library calls without a guard: `sendPasswordResetToken`, `sendPasswordResetOtp`, `sendEmailVerificationOtp`, `sendMfaEnabledNotification`, `sendMfaDisabledNotification` and `sendInvitation`. A class, a factory or an alias is not inspected.
|
|
311
|
+
|
|
310
312
|
> [!WARNING]
|
|
311
313
|
> Any user-supplied value (display name, tenant name, inviter name) interpolated into HTML email bodies MUST be escaped to prevent stored XSS in notification content. Tokens and OTPs are library-generated and safe, but `inviterName`, `tenantName`, device strings, and any consumer-supplied placeholder are attacker-controllable.
|
|
312
314
|
|
|
@@ -805,6 +807,11 @@ All options are configurable via `registerAsync()`. Here are the key configurati
|
|
|
805
807
|
| **password** (screen) | `blocklist` — extra words the default screen refuses, on top of the ones it ships | `[]` |
|
|
806
808
|
| **controllers** | Toggle individual controllers on/off — passed to `registerAsync()` itself, never returned from `useFactory` (which refuses it at startup) | `auth`, `passwordReset` on; rest opt-in |
|
|
807
809
|
|
|
810
|
+
An option that is omitted, or that holds `undefined` or `null`, is unset and takes its default; it never means "no limit". To switch
|
|
811
|
+
a cap off, use the documented value (`0` for `jwt.absoluteSessionLifetimeDays`), not an absent one. A host-defined map or a required value (`oauth.<provider>`, the `oauth` redirect URLs, `roles.hierarchy.<role>`, `workspaces.permissions.<action>`) refuses `null` by name.
|
|
812
|
+
A flag must be exactly `true` or `false` (`workspaces.allowCreate` may also be a function), and an option with a documented set of values exactly one of them: anything else, an empty string and `'false'` included, is
|
|
813
|
+
refused at startup naming the option, never read as off or as a default.
|
|
814
|
+
|
|
808
815
|
> [!NOTE]
|
|
809
816
|
> When a feature is not enabled (e.g., `mfa`, `sessions`, `platform`), its controllers and services are **not registered** in the NestJS container — zero overhead. A feature is enabled by `controllers.<name>: true` on the `registerAsync()` call together with its configuration group (`mfa.encryptionKey` and `mfa.issuer`, `sessions.enabled`, `platform.enabled`); either half alone leaves it unregistered or fails at startup.
|
|
810
817
|
|
|
@@ -902,7 +909,7 @@ All options are configurable via `registerAsync()`. Here are the key configurati
|
|
|
902
909
|
> be `0..=2`: the window counts 30-second steps on _either_ side of now, so `2n + 1` codes are
|
|
903
910
|
> valid at once (three at the default of 1). `mfa.recoveryCodeCount` must be `1..=50`,
|
|
904
911
|
> because zero enrols an account with no way back if the authenticator is lost.
|
|
905
|
-
> `password.blockSize` must be at least 8 and `password.parallelization`
|
|
912
|
+
> `password.blockSize` must be at least 8 and `password.parallelization` between 1 and 16: scrypt's memory
|
|
906
913
|
> cost is `128 * N * r`, so a smaller block size divides the hardness `password.costFactor`'s floor
|
|
907
914
|
> exists to guarantee.
|
|
908
915
|
|
|
@@ -940,6 +947,10 @@ All options are configurable via `registerAsync()`. Here are the key configurati
|
|
|
940
947
|
> [Invalidating the account cache](./docs/server-services.md#invalidating-the-account-cache--accountstatusserviceinvalidate)).
|
|
941
948
|
> `bumpUserTokenEpoch` is the heavier lever: it ends every session the user has. Lower
|
|
942
949
|
> `userStatusCacheTtlSeconds` if a faster answer matters more than the repository reads it costs.
|
|
950
|
+
>
|
|
951
|
+
> `userStatusCacheTtlSeconds` is a whole number of seconds from **1 to 3600**. It is the window in which a
|
|
952
|
+
> suspended account keeps passing the guard, so the module refuses a longer one (and a fraction, `NaN`
|
|
953
|
+
> or a string) at boot.
|
|
943
954
|
|
|
944
955
|
`jwt.absoluteSessionLifetimeDays` caps how long one login can be extended by rotation, and is
|
|
945
956
|
**on by default at 30 days** — NIST SP 800-63B-4 §3 makes a definite reauthentication timeout a
|
|
@@ -947,6 +958,7 @@ SHALL and puts it at no more than 30 days for AAL1. Without a cap, a client refr
|
|
|
947
958
|
fifteen minutes keeps a session alive forever, and a refresh token stolen once becomes permanent
|
|
948
959
|
access. Raise it to a value the product can justify, or set `0` to accept unbounded sessions
|
|
949
960
|
deliberately.
|
|
961
|
+
Any other value is from one hour (`0.0417` days) to `3650` days.
|
|
950
962
|
|
|
951
963
|
Lowering the value ends sessions that are already older than the new one, at their next rotation;
|
|
952
964
|
raising it or setting `0` ends nothing. Sessions established before the cap existed carry no
|