@bymax-one/nest-auth 1.4.0 → 1.4.1
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 +130 -3
- package/README.md +72 -1
- package/dist/server/index.cjs +96 -46
- package/dist/server/index.d.cts +38 -8
- package/dist/server/index.d.ts +38 -8
- package/dist/server/index.mjs +96 -47
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,8 +2,134 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@bymax-one/nest-auth` will be documented in this file.
|
|
4
4
|
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
|
-
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
|
|
7
|
+
**Versioning, while the library is pre-adoption.** [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
8
|
+
is the target, not yet the practice. Until the API settles, breaking changes ship in **minor and
|
|
9
|
+
patch** releases rather than driving the major, deliberately: the library has no production
|
|
10
|
+
dependant, the surface is still being corrected as audits land, and a major per breaking change
|
|
11
|
+
would put a young library in double digits while saying nothing useful about its stability.
|
|
12
|
+
Strict SemVer starts when the API is declared stable, and that transition will be announced here.
|
|
13
|
+
|
|
14
|
+
**What this means for you:** do not infer compatibility from the version number in the `1.x` line
|
|
15
|
+
— `^1.4.0` and `~1.4.0` both resolve to releases that may break you. Read the entry before
|
|
16
|
+
upgrading. Every breaking change carries an **Apply to a derived backend** note saying exactly
|
|
17
|
+
what moves, and that note is the compatibility contract until strict SemVer begins.
|
|
18
|
+
|
|
19
|
+
## [1.4.1] - 2026-08-12
|
|
20
|
+
|
|
21
|
+
Aligns every HTTP status with `rust-auth` and makes the pairing structural rather than
|
|
22
|
+
conventional. **Two breaking changes ride along in a patch release** — the `AuthException`
|
|
23
|
+
signature and thirteen HTTP status codes — matching how this line has shipped breaking changes
|
|
24
|
+
before (see `1.3.2`). Both `^1.4.0` and `~1.4.0` resolve to it, so a routine update picks it up:
|
|
25
|
+
read the migration notes below before upgrading. The `AuthException` half is compiler-guided;
|
|
26
|
+
the status half is not, and will surface as failing assertions in any suite that pins statuses.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- **BREAKING: thirteen error codes answered the wrong HTTP status, and five answered two.**
|
|
31
|
+
A consumer's OpenAPI audit surfaced `auth.email_already_exists` answering `401` here and `409`
|
|
32
|
+
in `rust-auth`. It was not one code. `auth.session_not_found` answered `401` instead of `404`;
|
|
33
|
+
`auth.mfa_already_enabled` `401` instead of `409`; `auth.mfa_not_enabled`,
|
|
34
|
+
`auth.mfa_setup_required`, `auth.password_reset_token_invalid`,
|
|
35
|
+
`auth.email_change_token_invalid` and `auth.invalid_invitation_token` `401` instead of `400`.
|
|
36
|
+
Five more disagreed with _themselves_ depending on the throw site: `auth.account_locked` was
|
|
37
|
+
`429` on login but `401` on the MFA and password-reset lockouts — so a client backing off on
|
|
38
|
+
`429` did not back off on the others — and `auth.email_not_verified`, `auth.mfa_required`,
|
|
39
|
+
`auth.forbidden` and `auth.token_invalid` each answered two statuses across the codebase.
|
|
40
|
+
Every value now matches `rust-auth`, which was the correct side throughout.
|
|
41
|
+
|
|
42
|
+
**Root cause, and why no gate caught it.** `conformance/wire-contract.json` pinned the code
|
|
43
|
+
_vocabulary_ and not the status per code, so the field had no gate at all; and
|
|
44
|
+
`AuthException`'s status argument defaulted to `401`, making an omission neither a type error
|
|
45
|
+
nor a lint error but a plausible-looking wrong answer. Both libraries' suites were green
|
|
46
|
+
throughout — each side was self-consistent, and neither read the other.
|
|
47
|
+
|
|
48
|
+
**Apply to a derived backend:** if you assert on HTTP statuses, thirteen codes move. The eight
|
|
49
|
+
above take their new value everywhere. The five that answered two statuses now answer one, and
|
|
50
|
+
a route-level assertion can fail on any of them even where the code itself is unchanged:
|
|
51
|
+
`auth.account_locked` is `429` on every path (it was `401` on the MFA and password-reset
|
|
52
|
+
lockouts), `auth.email_not_verified` is `403` (it was `401` on login and in `UserStatusGuard`),
|
|
53
|
+
`auth.mfa_required` is `403` (it was `401` on the login MFA gate), `auth.forbidden` is `403`
|
|
54
|
+
(it was `401` at every throw site), and `auth.token_invalid` is `401` (it was `400` in
|
|
55
|
+
`SelfOrAdminGuard`'s hash-format rejection). Statuses only — no code string, message or
|
|
56
|
+
envelope shape changed.
|
|
57
|
+
|
|
58
|
+
### Changed
|
|
59
|
+
|
|
60
|
+
- **BREAKING: `AuthException` no longer takes a status argument.** The signature is now
|
|
61
|
+
`new AuthException(code, details?)`; the status is derived from the code via the new
|
|
62
|
+
`AUTH_ERROR_STATUS` table. One code answering two statuses is no longer expressible, which is
|
|
63
|
+
what the defaulted argument allowed. **Apply to a derived backend:** drop the second argument
|
|
64
|
+
where you passed a status — `new AuthException(CODE, HttpStatus.FORBIDDEN)` becomes
|
|
65
|
+
`new AuthException(CODE)`, and `new AuthException(CODE, status, details)` becomes
|
|
66
|
+
`new AuthException(CODE, details)`. TypeScript flags the old three-argument form and any
|
|
67
|
+
numeric status passed where `details` is now expected, so the migration is compiler-guided
|
|
68
|
+
rather than silent.
|
|
69
|
+
|
|
70
|
+
### Added
|
|
71
|
+
|
|
72
|
+
- **`AUTH_ERROR_STATUS`** ([`src/server/errors/auth-error-codes.ts`](src/server/errors/auth-error-codes.ts)),
|
|
73
|
+
exported from the package root: the `code → HTTP status` map every error answers by. Useful
|
|
74
|
+
for a generated client, an API document, or a test asserting against the wire contract.
|
|
75
|
+
|
|
76
|
+
- **`errorCatalog.statuses` in [`conformance/wire-contract.json`](conformance/wire-contract.json)**,
|
|
77
|
+
byte-identical with `rust-auth` like the rest of that file, plus conformance tests asserting
|
|
78
|
+
`AUTH_ERROR_STATUS` against it, that the table covers the catalog exactly, and that each
|
|
79
|
+
internal-only code carries the status of the public code it collapses onto — a differing
|
|
80
|
+
status would hand back through the status line what the collapse removes from the body.
|
|
81
|
+
These are wire statuses: `auth.otp_max_attempts` is `401` because a caller receives it as
|
|
82
|
+
`auth.otp_invalid`, and a `429` would say the address was registered, since only a record
|
|
83
|
+
that exists can reach an attempt ceiling.
|
|
84
|
+
|
|
85
|
+
### Tests
|
|
86
|
+
|
|
87
|
+
- **19 end-to-end status-window assertions replaced with an exact `(code, status)` pair**, across
|
|
88
|
+
six spec files, via a shared `expectAuthError` helper: 16 were a bounded `status >= 400 &&
|
|
89
|
+
status < 500`, and 3 asserted only the `>= 400` lower bound, which is looser still. That form
|
|
90
|
+
is why the drift above survived the suite — `401` where the contract says `404` is still a 4xx,
|
|
91
|
+
so the check was satisfied by the right answer and the wrong one alike. Four of them asserted
|
|
92
|
+
no error code at all and now do.
|
|
93
|
+
|
|
94
|
+
- **Two negated status assertions replaced in the rate-limit spec.** `expect(status).not.toBe(429)`
|
|
95
|
+
accepts every wrong answer but one: the allowed login attempts now assert
|
|
96
|
+
`auth.invalid_credentials` at the contract's status, and the separate-budget reset asserts
|
|
97
|
+
`200` exactly, which also pins the anti-enumeration answer. Same defect as the range, one
|
|
98
|
+
shape further out — and harder to spot, because a negation reads like a deliberate claim
|
|
99
|
+
about a specific status.
|
|
100
|
+
|
|
101
|
+
- **The internal-only code list is now pinned by name.** Every other assertion about those codes
|
|
102
|
+
lives inside a `for … of contract.errorCatalog.internalOnly` loop, so an empty or shortened
|
|
103
|
+
list did not fail them — it stopped them running, and they reported success for having checked
|
|
104
|
+
nothing. Unlike `codes` and `statuses`, nothing had pinned that array's contents.
|
|
105
|
+
|
|
106
|
+
- **MFA specs derive TOTP codes from the live step rather than a remembered one**
|
|
107
|
+
([`mfa-disable-flow`](test/e2e/mfa-disable-flow.e2e-spec.ts),
|
|
108
|
+
[`mfa-recovery-codes-flow`](test/e2e/mfa-recovery-codes-flow.e2e-spec.ts)). The fixtures spend
|
|
109
|
+
two adjacent TOTP counters and then reached one step backwards for a free slot, assuming the
|
|
110
|
+
whole fixture lands inside a single 30-second step. Crossing a step boundary inverted that
|
|
111
|
+
assumption: the slot reached for was the one `verify-enable` had burned, the anti-replay guard
|
|
112
|
+
refused it, and `/mfa/disable` answered `401`, which surfaced as a pre-disable token still
|
|
113
|
+
being accepted. A test defect, not a library one — the guard and the ±1 window behaved as
|
|
114
|
+
designed.
|
|
115
|
+
|
|
116
|
+
- **`AuthException` is now tested against inherited `Object` members** (`constructor`,
|
|
117
|
+
`toString`, `__proto__`, `hasOwnProperty`) and against a code absent from the catalog.
|
|
118
|
+
|
|
119
|
+
### Internal / CI
|
|
120
|
+
|
|
121
|
+
- **OSV-Scanner workflow** ([`.github/workflows/osv-scanner.yml`](.github/workflows/osv-scanner.yml)),
|
|
122
|
+
a thin caller of the shared reusable. It scans the full resolved dependency tree on push, pull
|
|
123
|
+
request and a weekly schedule — coverage neither `dependency-review` (pull-request diff only)
|
|
124
|
+
nor `peer-advisory-drift` (declared ranges only) provides, since an already-installed
|
|
125
|
+
transitive package can turn vulnerable between releases.
|
|
126
|
+
|
|
127
|
+
- **`conformance/wire-contract.json` excluded from Prettier**
|
|
128
|
+
([`.prettierignore`](.prettierignore)). Its bytes are the contract — the file must stay
|
|
129
|
+
byte-identical with `rust-auth`'s copy, and the `lint-staged` glob `*.{json,md,yml,yaml}` runs
|
|
130
|
+
`prettier --write` over it, so an ordinary commit was one formatting-default change away from
|
|
131
|
+
breaking the pairing with no signal at all. Nothing in either repository compares one copy to
|
|
132
|
+
the other, which is what makes a silent reformat unrecoverable rather than merely wrong.
|
|
7
133
|
|
|
8
134
|
## [1.4.0] - 2026-08-11
|
|
9
135
|
|
|
@@ -1342,7 +1468,8 @@ ever installable.
|
|
|
1342
1468
|
- 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
|
|
1343
1469
|
- 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
|
|
1344
1470
|
|
|
1345
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.
|
|
1471
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.1...HEAD
|
|
1472
|
+
[1.4.1]: https://github.com/bymaxone/nest-auth/compare/v1.4.0...v1.4.1
|
|
1346
1473
|
[1.4.0]: https://github.com/bymaxone/nest-auth/compare/v1.3.2...v1.4.0
|
|
1347
1474
|
[1.3.2]: https://github.com/bymaxone/nest-auth/compare/v1.3.1...v1.3.2
|
|
1348
1475
|
[1.3.1]: https://github.com/bymaxone/nest-auth/compare/v1.3.0...v1.3.1
|
package/README.md
CHANGED
|
@@ -958,7 +958,7 @@ When integrating `@bymax-one/nest-auth` in production, verify each of the follow
|
|
|
958
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**.
|
|
959
959
|
|
|
960
960
|
- ✅ **100% line coverage** — statements, branches, functions, and lines, enforced as a release gate across unit + e2e
|
|
961
|
-
- ✅ **100% mutation score** — verified with [Stryker](https://stryker-mutator.io/): 4,
|
|
961
|
+
- ✅ **100% mutation score** — verified with [Stryker](https://stryker-mutator.io/): 4,989 seeded faults detected (4,968 killed, 21 timed out), **no survivors and nothing left uncovered**, against a `break` threshold of 100 ([measured cold on 2026-08-12](./docs/mutation_testing_results.md#re-measured-cold--2026-08-12))
|
|
962
962
|
- ✅ **3,547 tests** — 3,420 unit and 127 end-to-end, spanning all five subpaths
|
|
963
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
|
|
964
964
|
|
|
@@ -1020,6 +1020,47 @@ Conditionally registered controllers (mfa, sessions, platform, invitations, oaut
|
|
|
1020
1020
|
> hand a victim a callback URL and have the victim's browser complete the attacker's login.
|
|
1021
1021
|
> Mount `app.use(cookieParser())` before the module's routes or every callback answers 401.
|
|
1022
1022
|
|
|
1023
|
+
### Request bodies
|
|
1024
|
+
|
|
1025
|
+
Validated by `createAuthValidationPipe()` with `whitelist` and `forbidNonWhitelisted`, so an
|
|
1026
|
+
unknown property is a `400 auth.validation` rather than a silently ignored field. `tenantId` is
|
|
1027
|
+
optional on every **unauthenticated** body below (≤128 chars, no control characters) and scopes
|
|
1028
|
+
the operation to one organization. `POST /password/change` is the exception: it is behind
|
|
1029
|
+
`JwtAuthGuard`, takes its tenant from the JWT, and declares no `tenantId` — so sending one is an
|
|
1030
|
+
unknown property, and `forbidNonWhitelisted` answers `400 auth.validation`. Email fields are
|
|
1031
|
+
trimmed and lowercased before they reach the service, so the stored identity matches the
|
|
1032
|
+
case-insensitive lookup and every email-keyed control.
|
|
1033
|
+
|
|
1034
|
+
| Endpoint | Body |
|
|
1035
|
+
| -------------------------------- | -------------------------------------------------------------------------------- |
|
|
1036
|
+
| `POST /register` | `{ email, password, name }` — `name` 2–128 |
|
|
1037
|
+
| `POST /login` | `{ email, password }` |
|
|
1038
|
+
| `POST /verify-email` | `{ email, otp }` — `otp` is **exactly 6 digits** |
|
|
1039
|
+
| `POST /resend-verification` | `{ email }` |
|
|
1040
|
+
| `POST /password/forgot-password` | `{ email }` |
|
|
1041
|
+
| `POST /password/verify-otp` | `{ email, otp }` |
|
|
1042
|
+
| `POST /password/resend-otp` | `{ email }` |
|
|
1043
|
+
| `POST /password/reset-password` | `{ email, newPassword }` **plus exactly one** of `token`, `otp`, `verifiedToken` |
|
|
1044
|
+
| `POST /password/change` | `{ currentPassword, newPassword }` |
|
|
1045
|
+
|
|
1046
|
+
Three constraints are worth stating because they are not visible from the field names:
|
|
1047
|
+
|
|
1048
|
+
- **`reset-password` carries exactly one proof.** `token` is the emailed URL parameter, `otp` the
|
|
1049
|
+
emailed 4–8 character code, and `verifiedToken` the 64-character handle `POST
|
|
1050
|
+
/password/verify-otp` returns (5-minute TTL) so the OTP need not be re-submitted. All three are
|
|
1051
|
+
optional at the validation boundary and the mutual exclusivity is enforced in the service — a
|
|
1052
|
+
body carrying none or more than one is rejected there, not by the DTO.
|
|
1053
|
+
- **The password length the DTO enforces is not your policy.** `@MinLength(8)` is structural: it
|
|
1054
|
+
is the floor NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a
|
|
1055
|
+
decorator can express, since decorators evaluate before any configuration exists. The real
|
|
1056
|
+
floor is `password.minLength` — **default 15** — enforced by `PasswordService`, which answers
|
|
1057
|
+
the same `auth.validation` code and `details` shape. A client that validates against 8 will see
|
|
1058
|
+
a `400` from the service.
|
|
1059
|
+
- **`login` deliberately floors `password` at 1 character.** Rejecting only the empty string
|
|
1060
|
+
stops a caller from spending a full scrypt derivation for free; enforcing the configured policy
|
|
1061
|
+
length here would leak it as a pre-KDF timing signal, because a request failing validation
|
|
1062
|
+
returns before the hash runs.
|
|
1063
|
+
|
|
1023
1064
|
### Administrative operations — methods, deliberately not routes
|
|
1024
1065
|
|
|
1025
1066
|
Two support-desk operations ship as **methods with no HTTP route**. Every route above is scoped
|
|
@@ -1092,6 +1133,36 @@ It passes an `AuthException` through untouched, keeps the status any other `Http
|
|
|
1092
1133
|
chose, and answers an unhandled throw with `auth.internal` and a generic message — never the
|
|
1093
1134
|
thrown one.
|
|
1094
1135
|
|
|
1136
|
+
#### The HTTP status belongs to the code
|
|
1137
|
+
|
|
1138
|
+
Every code answers exactly one status, and the status is derived from the code rather than
|
|
1139
|
+
chosen at the throw site — `AuthException` takes no status argument. A client can switch on
|
|
1140
|
+
`error.code` and the status line together and get the same answer from either implementation:
|
|
1141
|
+
`@bymax-one/nest-auth` and `rust-auth` read the same table, pinned in
|
|
1142
|
+
[`conformance/wire-contract.json`](./conformance/wire-contract.json) under
|
|
1143
|
+
`errorCatalog.statuses` and asserted by both suites against that file.
|
|
1144
|
+
|
|
1145
|
+
| Status | Codes |
|
|
1146
|
+
| -----: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1147
|
+
| `400` | `auth.validation` · `auth.password_compromised` · `auth.password_reset_token_invalid` · `auth.email_change_token_invalid` · `auth.invalid_invitation_token` · `auth.mfa_not_enabled` · `auth.mfa_setup_required` |
|
|
1148
|
+
| `401` | `auth.invalid_credentials` · `auth.token_invalid` · `auth.refresh_token_invalid` · `auth.mfa_invalid_code` · `auth.mfa_temp_token_invalid` · `auth.otp_invalid` · `auth.oauth_failed` · `auth.platform_auth_required` |
|
|
1149
|
+
| `403` | `auth.account_inactive` · `auth.account_suspended` · `auth.account_banned` · `auth.pending_approval` · `auth.email_not_verified` · `auth.mfa_required` · `auth.insufficient_role` · `auth.forbidden` · `auth.untrusted_origin` · `auth.reauthentication_required` |
|
|
1150
|
+
| `404` | `auth.session_not_found` |
|
|
1151
|
+
| `409` | `auth.email_already_exists` · `auth.mfa_already_enabled` · `auth.mfa_state_conflict` · `auth.oauth_email_mismatch` |
|
|
1152
|
+
| `429` | `auth.account_locked` · `auth.too_many_requests` |
|
|
1153
|
+
| `500` | `auth.internal` |
|
|
1154
|
+
|
|
1155
|
+
`AUTH_ERROR_STATUS` is exported if you need the mapping at runtime — for a typed client, an
|
|
1156
|
+
API document, or a test that asserts against it.
|
|
1157
|
+
|
|
1158
|
+
> **Anti-enumeration reads through the status too.** `POST /forgot-password` answers `200` and
|
|
1159
|
+
> `POST /verify-email` / the resend endpoints answer `204` **whether or not the address exists**.
|
|
1160
|
+
> A `200` there does not mean an email was sent, and treating it as confirmation re-introduces
|
|
1161
|
+
> the account enumeration the endpoints exist to prevent. For the same reason the OTP failures
|
|
1162
|
+
> collapse: a wrong code, a record that expired, and an exhausted attempt ceiling are one code
|
|
1163
|
+
> (`auth.otp_invalid`) at one status (`401`) — a `429` on the ceiling would say the address was
|
|
1164
|
+
> registered, since only a record that exists can reach one.
|
|
1165
|
+
|
|
1095
1166
|
### Server Decorators
|
|
1096
1167
|
|
|
1097
1168
|
| Decorator | Usage |
|
package/dist/server/index.cjs
CHANGED
|
@@ -1622,6 +1622,46 @@ var AUTH_ERROR_CODES = {
|
|
|
1622
1622
|
*/
|
|
1623
1623
|
INTERNAL: "auth.internal"
|
|
1624
1624
|
};
|
|
1625
|
+
var AUTH_ERROR_STATUS = {
|
|
1626
|
+
"auth.invalid_credentials": 401,
|
|
1627
|
+
"auth.account_locked": 429,
|
|
1628
|
+
"auth.account_inactive": 403,
|
|
1629
|
+
"auth.account_suspended": 403,
|
|
1630
|
+
"auth.account_banned": 403,
|
|
1631
|
+
"auth.pending_approval": 403,
|
|
1632
|
+
"auth.token_expired": 401,
|
|
1633
|
+
"auth.token_revoked": 401,
|
|
1634
|
+
"auth.token_invalid": 401,
|
|
1635
|
+
"auth.token_missing": 401,
|
|
1636
|
+
"auth.refresh_token_invalid": 401,
|
|
1637
|
+
"auth.session_not_found": 404,
|
|
1638
|
+
"auth.email_already_exists": 409,
|
|
1639
|
+
"auth.email_not_verified": 403,
|
|
1640
|
+
"auth.email_change_token_invalid": 400,
|
|
1641
|
+
"auth.mfa_required": 403,
|
|
1642
|
+
"auth.mfa_invalid_code": 401,
|
|
1643
|
+
"auth.mfa_already_enabled": 409,
|
|
1644
|
+
"auth.mfa_not_enabled": 400,
|
|
1645
|
+
"auth.mfa_setup_required": 400,
|
|
1646
|
+
"auth.mfa_temp_token_invalid": 401,
|
|
1647
|
+
"auth.mfa_state_conflict": 409,
|
|
1648
|
+
"auth.password_compromised": 400,
|
|
1649
|
+
"auth.password_reset_token_invalid": 400,
|
|
1650
|
+
"auth.otp_invalid": 401,
|
|
1651
|
+
"auth.otp_expired": 401,
|
|
1652
|
+
"auth.otp_max_attempts": 401,
|
|
1653
|
+
"auth.insufficient_role": 403,
|
|
1654
|
+
"auth.forbidden": 403,
|
|
1655
|
+
"auth.validation": 400,
|
|
1656
|
+
"auth.too_many_requests": 429,
|
|
1657
|
+
"auth.untrusted_origin": 403,
|
|
1658
|
+
"auth.reauthentication_required": 403,
|
|
1659
|
+
"auth.invalid_invitation_token": 400,
|
|
1660
|
+
"auth.oauth_failed": 401,
|
|
1661
|
+
"auth.oauth_email_mismatch": 409,
|
|
1662
|
+
"auth.platform_auth_required": 401,
|
|
1663
|
+
"auth.internal": 500
|
|
1664
|
+
};
|
|
1625
1665
|
var AUTH_ERROR_MESSAGES = {
|
|
1626
1666
|
"auth.invalid_credentials": "Invalid email or password",
|
|
1627
1667
|
"auth.account_locked": "Account temporarily locked. Please try again in a few minutes.",
|
|
@@ -1662,27 +1702,34 @@ var AUTH_ERROR_MESSAGES = {
|
|
|
1662
1702
|
"auth.platform_auth_required": "Platform authentication required",
|
|
1663
1703
|
"auth.internal": "Internal server error"
|
|
1664
1704
|
};
|
|
1705
|
+
var MESSAGE_BY_CODE = new Map(Object.entries(AUTH_ERROR_MESSAGES));
|
|
1706
|
+
var STATUS_BY_CODE = new Map(Object.entries(AUTH_ERROR_STATUS));
|
|
1665
1707
|
var AuthException = class extends common.HttpException {
|
|
1666
1708
|
static {
|
|
1667
1709
|
__name(this, "AuthException");
|
|
1668
1710
|
}
|
|
1669
1711
|
/**
|
|
1670
|
-
* @param code - Stable machine-readable error code from `AUTH_ERROR_CODES`.
|
|
1671
|
-
*
|
|
1712
|
+
* @param code - Stable machine-readable error code from `AUTH_ERROR_CODES`. Determines both
|
|
1713
|
+
* the default message and the HTTP status.
|
|
1672
1714
|
* @param details - Optional structured payload attached to the error body under
|
|
1673
1715
|
* `error.details`. An array where the failure is a list — `auth.validation` renders its
|
|
1674
1716
|
* per-field failures that way, matching what rust-auth serializes for the same code.
|
|
1675
1717
|
*/
|
|
1676
|
-
constructor(code,
|
|
1677
|
-
super(
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1718
|
+
constructor(code, details) {
|
|
1719
|
+
super(
|
|
1720
|
+
{
|
|
1721
|
+
error: {
|
|
1722
|
+
code,
|
|
1723
|
+
// Runtime fallback for future/unknown codes not yet in AUTH_ERROR_MESSAGES (type cast in tests, forward-compat).
|
|
1724
|
+
message: MESSAGE_BY_CODE.get(code) ?? code,
|
|
1725
|
+
details: details ?? null
|
|
1726
|
+
}
|
|
1727
|
+
},
|
|
1728
|
+
// A code with no entry is a programming error on the throwing side, not something the
|
|
1729
|
+
// caller did — 500 says so, and says it with a number rather than the `undefined` an
|
|
1730
|
+
// unguarded lookup used to hand to Express.
|
|
1731
|
+
STATUS_BY_CODE.get(code) ?? common.HttpStatus.INTERNAL_SERVER_ERROR
|
|
1732
|
+
);
|
|
1686
1733
|
}
|
|
1687
1734
|
};
|
|
1688
1735
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
@@ -2696,7 +2743,7 @@ exports.AuthRateLimitGuard = class AuthRateLimitGuard {
|
|
|
2696
2743
|
const hits = await this.redis.incrWithFixedTtl(key, windowSeconds);
|
|
2697
2744
|
if (hits <= limit.limit) return true;
|
|
2698
2745
|
context.switchToHttp().getResponse().setHeader("Retry-After", windowSeconds);
|
|
2699
|
-
throw new AuthException(AUTH_ERROR_CODES.TOO_MANY_REQUESTS
|
|
2746
|
+
throw new AuthException(AUTH_ERROR_CODES.TOO_MANY_REQUESTS);
|
|
2700
2747
|
}
|
|
2701
2748
|
/**
|
|
2702
2749
|
* The counter key for one caller on one route.
|
|
@@ -2774,7 +2821,7 @@ function assertNotBlocked(status, blockedStatuses) {
|
|
|
2774
2821
|
if (!blockedStatuses.some((blocked) => blocked.toLowerCase() === canonical)) {
|
|
2775
2822
|
return;
|
|
2776
2823
|
}
|
|
2777
|
-
throw new AuthException(BLOCKED_STATUS_CODES.get(canonical) ?? AUTH_ERROR_CODES.ACCOUNT_INACTIVE
|
|
2824
|
+
throw new AuthException(BLOCKED_STATUS_CODES.get(canonical) ?? AUTH_ERROR_CODES.ACCOUNT_INACTIVE);
|
|
2778
2825
|
}
|
|
2779
2826
|
__name(assertNotBlocked, "assertNotBlocked");
|
|
2780
2827
|
|
|
@@ -3431,12 +3478,12 @@ exports.TrustedOriginGuard = class TrustedOriginGuard {
|
|
|
3431
3478
|
if (typeof origin === "string") {
|
|
3432
3479
|
if (this.options.cookies.trustedOrigins.includes(origin)) return true;
|
|
3433
3480
|
if (sawFetchSite || this.options.cookies.trustedOrigins.length > 0) {
|
|
3434
|
-
throw new AuthException(AUTH_ERROR_CODES.UNTRUSTED_ORIGIN
|
|
3481
|
+
throw new AuthException(AUTH_ERROR_CODES.UNTRUSTED_ORIGIN);
|
|
3435
3482
|
}
|
|
3436
3483
|
return true;
|
|
3437
3484
|
}
|
|
3438
3485
|
if (sawFetchSite) {
|
|
3439
|
-
throw new AuthException(AUTH_ERROR_CODES.UNTRUSTED_ORIGIN
|
|
3486
|
+
throw new AuthException(AUTH_ERROR_CODES.UNTRUSTED_ORIGIN);
|
|
3440
3487
|
}
|
|
3441
3488
|
return true;
|
|
3442
3489
|
}
|
|
@@ -3584,7 +3631,7 @@ function createAuthValidationPipe(options = {}) {
|
|
|
3584
3631
|
whitelist: true,
|
|
3585
3632
|
forbidNonWhitelisted: true,
|
|
3586
3633
|
...options,
|
|
3587
|
-
exceptionFactory: /* @__PURE__ */ __name((errors) => new AuthException(AUTH_ERROR_CODES.VALIDATION,
|
|
3634
|
+
exceptionFactory: /* @__PURE__ */ __name((errors) => new AuthException(AUTH_ERROR_CODES.VALIDATION, flattenValidationErrors(errors)), "exceptionFactory")
|
|
3588
3635
|
});
|
|
3589
3636
|
}
|
|
3590
3637
|
__name(createAuthValidationPipe, "createAuthValidationPipe");
|
|
@@ -4073,7 +4120,7 @@ var PasswordService = class _PasswordService {
|
|
|
4073
4120
|
*/
|
|
4074
4121
|
assertLongEnough(plain, field) {
|
|
4075
4122
|
if (plain.length >= this.minLength) return;
|
|
4076
|
-
throw new AuthException(AUTH_ERROR_CODES.VALIDATION,
|
|
4123
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
|
|
4077
4124
|
{
|
|
4078
4125
|
field,
|
|
4079
4126
|
message: `${field} must be at least ${String(this.minLength)} characters`
|
|
@@ -4113,7 +4160,7 @@ var PasswordService = class _PasswordService {
|
|
|
4113
4160
|
return;
|
|
4114
4161
|
}
|
|
4115
4162
|
if (breached) {
|
|
4116
|
-
throw new AuthException(AUTH_ERROR_CODES.PASSWORD_COMPROMISED
|
|
4163
|
+
throw new AuthException(AUTH_ERROR_CODES.PASSWORD_COMPROMISED);
|
|
4117
4164
|
}
|
|
4118
4165
|
}
|
|
4119
4166
|
async hash(plain) {
|
|
@@ -5659,12 +5706,14 @@ function normalizeEmail(email) {
|
|
|
5659
5706
|
return email.trim().toLowerCase();
|
|
5660
5707
|
}
|
|
5661
5708
|
__name(normalizeEmail, "normalizeEmail");
|
|
5709
|
+
|
|
5710
|
+
// src/server/utils/resolve-tenant-id.ts
|
|
5662
5711
|
async function resolveTenantId(dtoTenantId, req, resolver) {
|
|
5663
5712
|
if (resolver) {
|
|
5664
5713
|
return await resolver(req);
|
|
5665
5714
|
}
|
|
5666
5715
|
if (dtoTenantId === void 0 || dtoTenantId === null) {
|
|
5667
|
-
throw new AuthException(AUTH_ERROR_CODES.VALIDATION,
|
|
5716
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
|
|
5668
5717
|
{
|
|
5669
5718
|
field: "tenantId",
|
|
5670
5719
|
message: "tenantId is required unless the deployment configures tenantIdResolver"
|
|
@@ -5912,7 +5961,7 @@ exports.AuthService = class _AuthService {
|
|
|
5912
5961
|
tenantId,
|
|
5913
5962
|
reason: "locked_out"
|
|
5914
5963
|
}, context);
|
|
5915
|
-
throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED,
|
|
5964
|
+
throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED, {
|
|
5916
5965
|
retryAfterSeconds: remainingSeconds
|
|
5917
5966
|
});
|
|
5918
5967
|
}
|
|
@@ -6537,7 +6586,7 @@ exports.WsTicketService = class _WsTicketService {
|
|
|
6537
6586
|
}
|
|
6538
6587
|
if (payload.mfaEnabled && payload.mfaVerified !== true) {
|
|
6539
6588
|
this.logger.warn(`ws-ticket: refused, MFA not satisfied userId=${payload.sub}`);
|
|
6540
|
-
throw new AuthException(AUTH_ERROR_CODES.MFA_REQUIRED
|
|
6589
|
+
throw new AuthException(AUTH_ERROR_CODES.MFA_REQUIRED);
|
|
6541
6590
|
}
|
|
6542
6591
|
const user = await this.userRepo.findById(payload.sub);
|
|
6543
6592
|
if (!user) throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
@@ -7630,17 +7679,17 @@ exports.InvitationService = class _InvitationService {
|
|
|
7630
7679
|
const normalizedEmail = normalizeEmail(email);
|
|
7631
7680
|
const hierarchy = this.options.roles.hierarchy;
|
|
7632
7681
|
if (!Object.hasOwn(hierarchy, role)) {
|
|
7633
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7682
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7634
7683
|
}
|
|
7635
7684
|
const inviter = await this.userRepo.findById(inviterUserId);
|
|
7636
7685
|
if (!inviter) {
|
|
7637
7686
|
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
7638
7687
|
}
|
|
7639
7688
|
if (inviter.tenantId !== tenantId) {
|
|
7640
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7689
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7641
7690
|
}
|
|
7642
7691
|
if (!hasRole(inviter.role, role, hierarchy)) {
|
|
7643
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7692
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7644
7693
|
}
|
|
7645
7694
|
const rawToken = generateSecureToken(32);
|
|
7646
7695
|
const tokenHash = sha256(rawToken);
|
|
@@ -7769,7 +7818,7 @@ exports.InvitationService = class _InvitationService {
|
|
|
7769
7818
|
const pending = raw === null ? null : this.parseInvitation(raw);
|
|
7770
7819
|
if (pending !== null && !this.mayWithdraw(inviter, pending)) {
|
|
7771
7820
|
this.logger.warn(`create: refused email=${maskEmail(email)} tenantId=${logSafe(tenantId)} inviterRole=${logSafe(inviter.role)} \u2014 outranked by the pending invitation`);
|
|
7772
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7821
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7773
7822
|
}
|
|
7774
7823
|
return tokenHash;
|
|
7775
7824
|
}
|
|
@@ -7804,7 +7853,7 @@ exports.InvitationService = class _InvitationService {
|
|
|
7804
7853
|
if (claim.claimed) return approved;
|
|
7805
7854
|
}
|
|
7806
7855
|
this.logger.warn(`create: refused email=${maskEmail(email)} tenantId=${logSafe(tenantId)} \u2014 the pending invitation kept changing under the rank check`);
|
|
7807
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7856
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7808
7857
|
}
|
|
7809
7858
|
/**
|
|
7810
7859
|
* Atomically points the invitee index at `tokenHash`, answering with the hash it displaced.
|
|
@@ -7871,10 +7920,10 @@ exports.InvitationService = class _InvitationService {
|
|
|
7871
7920
|
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
7872
7921
|
}
|
|
7873
7922
|
if (revoker.tenantId !== tenantId) {
|
|
7874
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7923
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7875
7924
|
}
|
|
7876
7925
|
if (!this.inGoodStanding(revoker)) {
|
|
7877
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7926
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7878
7927
|
}
|
|
7879
7928
|
const indexKey = this.inviteeKey(normalizedEmail, tenantId);
|
|
7880
7929
|
const tokenHash = await this.redis.get(indexKey);
|
|
@@ -8650,7 +8699,7 @@ exports.MfaService = class _MfaService {
|
|
|
8650
8699
|
const acquireLegacy = legacyLockKey !== scopedLockKey;
|
|
8651
8700
|
const lockToken = crypto.randomBytes(16).toString("hex");
|
|
8652
8701
|
if (!await this.redis.setIfAbsent(scopedLockKey, lockToken, MFA_TRANSITION_LOCK_TTL_SECONDS)) {
|
|
8653
|
-
throw new AuthException(AUTH_ERROR_CODES.MFA_STATE_CONFLICT
|
|
8702
|
+
throw new AuthException(AUTH_ERROR_CODES.MFA_STATE_CONFLICT);
|
|
8654
8703
|
}
|
|
8655
8704
|
if (acquireLegacy && !await this.redis.setIfAbsent(legacyLockKey, lockToken, MFA_TRANSITION_LOCK_TTL_SECONDS)) {
|
|
8656
8705
|
await this.redis.eval(RELEASE_LOCK_LUA, [
|
|
@@ -8658,7 +8707,7 @@ exports.MfaService = class _MfaService {
|
|
|
8658
8707
|
], [
|
|
8659
8708
|
lockToken
|
|
8660
8709
|
]);
|
|
8661
|
-
throw new AuthException(AUTH_ERROR_CODES.MFA_STATE_CONFLICT
|
|
8710
|
+
throw new AuthException(AUTH_ERROR_CODES.MFA_STATE_CONFLICT);
|
|
8662
8711
|
}
|
|
8663
8712
|
try {
|
|
8664
8713
|
const current = await this.fetchUserForContext(context, userId, tenantId);
|
|
@@ -9443,7 +9492,7 @@ exports.MfaService = class _MfaService {
|
|
|
9443
9492
|
const recent = await this.redis.get(recentAuthKey(context, userId, this.options.hmacKey, tenantId));
|
|
9444
9493
|
if (recent === null) {
|
|
9445
9494
|
this.logger.warn(`reauthenticate: no recent authentication userId=${userId} context=${context}`);
|
|
9446
|
-
throw new AuthException(AUTH_ERROR_CODES.REAUTHENTICATION_REQUIRED
|
|
9495
|
+
throw new AuthException(AUTH_ERROR_CODES.REAUTHENTICATION_REQUIRED);
|
|
9447
9496
|
}
|
|
9448
9497
|
return;
|
|
9449
9498
|
}
|
|
@@ -9502,7 +9551,7 @@ exports.MfaService = class _MfaService {
|
|
|
9502
9551
|
*/
|
|
9503
9552
|
assertPlaneTenant(context, tenantId) {
|
|
9504
9553
|
if (context === "dashboard" && (tenantId === void 0 || tenantId === "") || context === "platform" && tenantId !== void 0) {
|
|
9505
|
-
throw new AuthException(AUTH_ERROR_CODES.VALIDATION,
|
|
9554
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
|
|
9506
9555
|
{
|
|
9507
9556
|
field: "tenantId",
|
|
9508
9557
|
message: "tenantId must be a non-empty value on the dashboard plane and absent on the platform plane"
|
|
@@ -11273,7 +11322,7 @@ exports.PlatformAuthService = class _PlatformAuthService {
|
|
|
11273
11322
|
if (locked) {
|
|
11274
11323
|
this.logger.warn(`login: account locked email=${maskEmail(dto.email)}`);
|
|
11275
11324
|
const retryAfterSeconds = await this.bruteForce.getRemainingLockoutSeconds(bfIdentifier);
|
|
11276
|
-
throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED,
|
|
11325
|
+
throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED, {
|
|
11277
11326
|
retryAfterSeconds
|
|
11278
11327
|
});
|
|
11279
11328
|
}
|
|
@@ -12130,7 +12179,7 @@ exports.MfaRequiredGuard = class MfaRequiredGuard {
|
|
|
12130
12179
|
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
12131
12180
|
}
|
|
12132
12181
|
if (user.mfaEnabled === true && user.mfaVerified !== true) {
|
|
12133
|
-
throw new AuthException(AUTH_ERROR_CODES.MFA_REQUIRED
|
|
12182
|
+
throw new AuthException(AUTH_ERROR_CODES.MFA_REQUIRED);
|
|
12134
12183
|
}
|
|
12135
12184
|
return true;
|
|
12136
12185
|
}
|
|
@@ -12197,11 +12246,11 @@ exports.PlatformRolesGuard = class PlatformRolesGuard {
|
|
|
12197
12246
|
const userRole = user.role;
|
|
12198
12247
|
const hierarchy = this.options.roles.platformHierarchy;
|
|
12199
12248
|
if (!hierarchy) {
|
|
12200
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
12249
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
12201
12250
|
}
|
|
12202
12251
|
const allowed = requiredRoles.some((required) => hasRole(userRole, required, hierarchy));
|
|
12203
12252
|
if (!allowed) {
|
|
12204
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
12253
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
12205
12254
|
}
|
|
12206
12255
|
return true;
|
|
12207
12256
|
}
|
|
@@ -12265,12 +12314,12 @@ exports.RolesGuard = class RolesGuard {
|
|
|
12265
12314
|
const request = context.switchToHttp().getRequest();
|
|
12266
12315
|
const userRole = request.user?.role;
|
|
12267
12316
|
if (!userRole) {
|
|
12268
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
12317
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
12269
12318
|
}
|
|
12270
12319
|
const hierarchy = this.options.roles.hierarchy;
|
|
12271
12320
|
const allowed = requiredRoles.some((required) => hasRole(userRole, required, hierarchy));
|
|
12272
12321
|
if (!allowed) {
|
|
12273
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
12322
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
12274
12323
|
}
|
|
12275
12324
|
return true;
|
|
12276
12325
|
}
|
|
@@ -12560,7 +12609,7 @@ exports.OAuthService = class _OAuthService {
|
|
|
12560
12609
|
const derivedName = profile.name ?? profile.email.split("@")[0] ?? profile.email;
|
|
12561
12610
|
if (await this.userRepo.findByEmail(profile.email, tenantId)) {
|
|
12562
12611
|
this.logger.warn(`oauth: create refused \u2014 ${maskEmail(profile.email)} already exists in tenant ${tenantId}`);
|
|
12563
|
-
throw new AuthException(AUTH_ERROR_CODES.OAUTH_EMAIL_MISMATCH
|
|
12612
|
+
throw new AuthException(AUTH_ERROR_CODES.OAUTH_EMAIL_MISMATCH);
|
|
12564
12613
|
}
|
|
12565
12614
|
authUser = await this.userRepo.createWithOAuth({
|
|
12566
12615
|
email: profile.email,
|
|
@@ -12595,7 +12644,7 @@ exports.OAuthService = class _OAuthService {
|
|
|
12595
12644
|
}
|
|
12596
12645
|
assertNotBlocked(authUser.status, this.options.blockedStatuses);
|
|
12597
12646
|
if (this.options.emailVerification.required && !authUser.emailVerified) {
|
|
12598
|
-
throw new AuthException(AUTH_ERROR_CODES.EMAIL_NOT_VERIFIED
|
|
12647
|
+
throw new AuthException(AUTH_ERROR_CODES.EMAIL_NOT_VERIFIED);
|
|
12599
12648
|
}
|
|
12600
12649
|
if (authUser.mfaEnabled) {
|
|
12601
12650
|
const mfaTempToken = await this.tokenManager.issueMfaTempToken(authUser.id, "dashboard", authUser.tenantId);
|
|
@@ -14469,22 +14518,22 @@ exports.SelfOrAdminGuard = class SelfOrAdminGuard {
|
|
|
14469
14518
|
canActivate(context) {
|
|
14470
14519
|
const request = context.switchToHttp().getRequest();
|
|
14471
14520
|
if (request.user == null) {
|
|
14472
|
-
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID
|
|
14521
|
+
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
14473
14522
|
}
|
|
14474
14523
|
const rawParam = request.params["userId"] ?? request.params["id"];
|
|
14475
14524
|
if (rawParam === void 0) {
|
|
14476
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
14525
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
14477
14526
|
}
|
|
14478
14527
|
const paramValue = resolveParamString(rawParam);
|
|
14479
14528
|
if (paramValue === void 0) {
|
|
14480
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
14529
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
14481
14530
|
}
|
|
14482
14531
|
if (isHexLooking(paramValue) && !STRICT_SHA256_RE.test(paramValue)) {
|
|
14483
|
-
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID
|
|
14532
|
+
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
14484
14533
|
}
|
|
14485
14534
|
if (request.user.sub === paramValue) return true;
|
|
14486
14535
|
if (hasRole(request.user.role, "admin", this.options.roles.hierarchy)) return true;
|
|
14487
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
14536
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
14488
14537
|
}
|
|
14489
14538
|
};
|
|
14490
14539
|
exports.SelfOrAdminGuard = _ts_decorate64([
|
|
@@ -14698,6 +14747,7 @@ exports.AuthExceptionFilter = _ts_decorate66([
|
|
|
14698
14747
|
|
|
14699
14748
|
exports.AUTH_ERROR_CODES = AUTH_ERROR_CODES;
|
|
14700
14749
|
exports.AUTH_ERROR_MESSAGES = AUTH_ERROR_MESSAGES;
|
|
14750
|
+
exports.AUTH_ERROR_STATUS = AUTH_ERROR_STATUS;
|
|
14701
14751
|
exports.AUTH_THROTTLE_CONFIGS = AUTH_THROTTLE_CONFIGS;
|
|
14702
14752
|
exports.AcceptInvitationDto = AcceptInvitationDto;
|
|
14703
14753
|
exports.AuthException = AuthException;
|
package/dist/server/index.d.cts
CHANGED
|
@@ -2040,6 +2040,31 @@ declare const AUTH_ERROR_CODES: {
|
|
|
2040
2040
|
* `AuthException` and related APIs.
|
|
2041
2041
|
*/
|
|
2042
2042
|
type AuthErrorCode = (typeof AUTH_ERROR_CODES)[keyof typeof AUTH_ERROR_CODES];
|
|
2043
|
+
/**
|
|
2044
|
+
* HTTP status answered for each error code.
|
|
2045
|
+
*
|
|
2046
|
+
* The status is a property of the CODE, not of the call site: `AuthException` derives it from
|
|
2047
|
+
* this table and takes no status argument. That is deliberate, and it is the fix for a real
|
|
2048
|
+
* defect — the constructor used to default to `401`, so omitting the argument was neither a
|
|
2049
|
+
* type error nor a lint error but a plausible-looking wrong answer. Thirteen codes drifted
|
|
2050
|
+
* that way, and five answered *different* statuses at different throw sites (`auth.account_locked`
|
|
2051
|
+
* was `429` on login and `401` on the MFA and password-reset lockouts, so a client backing off
|
|
2052
|
+
* on `429` did not back off on the others).
|
|
2053
|
+
*
|
|
2054
|
+
* Pinned by `conformance/wire-contract.json` (`errorCatalog.statuses`) and asserted against it
|
|
2055
|
+
* by `conformance.spec.ts`, because rust-auth answers the same codes for the same deployment:
|
|
2056
|
+
* a client switching on `error.code` and `response.status` must see one contract whichever
|
|
2057
|
+
* implementation is behind it. Changing a value here is a breaking change to that contract —
|
|
2058
|
+
* make it in both repos in the same change.
|
|
2059
|
+
*
|
|
2060
|
+
* @remarks
|
|
2061
|
+
* These are WIRE statuses. An internal-only code carries the status of the public code it
|
|
2062
|
+
* collapses onto rather than one of its own — `auth.otp_max_attempts` is 401 because it reaches
|
|
2063
|
+
* a caller as `auth.otp_invalid`, and a 429 would hand back through the status line exactly what
|
|
2064
|
+
* the collapse removes from the body: only a record that exists can reach an attempt ceiling, so
|
|
2065
|
+
* a 429 says the address was registered.
|
|
2066
|
+
*/
|
|
2067
|
+
declare const AUTH_ERROR_STATUS: Readonly<Record<AuthErrorCode, number>>;
|
|
2043
2068
|
/**
|
|
2044
2069
|
* Human-readable message for each error code.
|
|
2045
2070
|
*
|
|
@@ -2074,24 +2099,29 @@ declare const AUTH_ERROR_MESSAGES: Readonly<Record<AuthErrorCode, string>>;
|
|
|
2074
2099
|
* }
|
|
2075
2100
|
* ```
|
|
2076
2101
|
*
|
|
2102
|
+
* The HTTP status is NOT a parameter — it is derived from the code via
|
|
2103
|
+
* {@link AUTH_ERROR_STATUS}. There is no way to answer one code with two statuses, which is
|
|
2104
|
+
* what a defaulted status argument allowed: thirteen codes drifted from the status rust-auth
|
|
2105
|
+
* answers for the same code, and five answered differently at different throw sites, none of
|
|
2106
|
+
* it visible to the type system, the linter, or either library's suite. Pass a `details`
|
|
2107
|
+
* payload where the failure carries one; the status follows the code.
|
|
2108
|
+
*
|
|
2077
2109
|
* @example
|
|
2078
2110
|
* ```typescript
|
|
2079
2111
|
* throw new AuthException(AUTH_ERROR_CODES.INVALID_CREDENTIALS)
|
|
2080
|
-
* throw new AuthException(AUTH_ERROR_CODES.FORBIDDEN
|
|
2081
|
-
* throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED,
|
|
2082
|
-
* retryAfterSeconds: 300
|
|
2083
|
-
* })
|
|
2112
|
+
* throw new AuthException(AUTH_ERROR_CODES.FORBIDDEN)
|
|
2113
|
+
* throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED, { retryAfterSeconds: 300 })
|
|
2084
2114
|
* ```
|
|
2085
2115
|
*/
|
|
2086
2116
|
declare class AuthException extends HttpException {
|
|
2087
2117
|
/**
|
|
2088
|
-
* @param code - Stable machine-readable error code from `AUTH_ERROR_CODES`.
|
|
2089
|
-
*
|
|
2118
|
+
* @param code - Stable machine-readable error code from `AUTH_ERROR_CODES`. Determines both
|
|
2119
|
+
* the default message and the HTTP status.
|
|
2090
2120
|
* @param details - Optional structured payload attached to the error body under
|
|
2091
2121
|
* `error.details`. An array where the failure is a list — `auth.validation` renders its
|
|
2092
2122
|
* per-field failures that way, matching what rust-auth serializes for the same code.
|
|
2093
2123
|
*/
|
|
2094
|
-
constructor(code: AuthErrorCode,
|
|
2124
|
+
constructor(code: AuthErrorCode, details?: Record<string, unknown> | readonly unknown[]);
|
|
2095
2125
|
}
|
|
2096
2126
|
|
|
2097
2127
|
/**
|
|
@@ -8714,4 +8744,4 @@ declare function AuthRateLimit(config: {
|
|
|
8714
8744
|
default: AuthRateLimitWindow;
|
|
8715
8745
|
}): MethodDecorator;
|
|
8716
8746
|
|
|
8717
|
-
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|
|
8747
|
+
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -2040,6 +2040,31 @@ declare const AUTH_ERROR_CODES: {
|
|
|
2040
2040
|
* `AuthException` and related APIs.
|
|
2041
2041
|
*/
|
|
2042
2042
|
type AuthErrorCode = (typeof AUTH_ERROR_CODES)[keyof typeof AUTH_ERROR_CODES];
|
|
2043
|
+
/**
|
|
2044
|
+
* HTTP status answered for each error code.
|
|
2045
|
+
*
|
|
2046
|
+
* The status is a property of the CODE, not of the call site: `AuthException` derives it from
|
|
2047
|
+
* this table and takes no status argument. That is deliberate, and it is the fix for a real
|
|
2048
|
+
* defect — the constructor used to default to `401`, so omitting the argument was neither a
|
|
2049
|
+
* type error nor a lint error but a plausible-looking wrong answer. Thirteen codes drifted
|
|
2050
|
+
* that way, and five answered *different* statuses at different throw sites (`auth.account_locked`
|
|
2051
|
+
* was `429` on login and `401` on the MFA and password-reset lockouts, so a client backing off
|
|
2052
|
+
* on `429` did not back off on the others).
|
|
2053
|
+
*
|
|
2054
|
+
* Pinned by `conformance/wire-contract.json` (`errorCatalog.statuses`) and asserted against it
|
|
2055
|
+
* by `conformance.spec.ts`, because rust-auth answers the same codes for the same deployment:
|
|
2056
|
+
* a client switching on `error.code` and `response.status` must see one contract whichever
|
|
2057
|
+
* implementation is behind it. Changing a value here is a breaking change to that contract —
|
|
2058
|
+
* make it in both repos in the same change.
|
|
2059
|
+
*
|
|
2060
|
+
* @remarks
|
|
2061
|
+
* These are WIRE statuses. An internal-only code carries the status of the public code it
|
|
2062
|
+
* collapses onto rather than one of its own — `auth.otp_max_attempts` is 401 because it reaches
|
|
2063
|
+
* a caller as `auth.otp_invalid`, and a 429 would hand back through the status line exactly what
|
|
2064
|
+
* the collapse removes from the body: only a record that exists can reach an attempt ceiling, so
|
|
2065
|
+
* a 429 says the address was registered.
|
|
2066
|
+
*/
|
|
2067
|
+
declare const AUTH_ERROR_STATUS: Readonly<Record<AuthErrorCode, number>>;
|
|
2043
2068
|
/**
|
|
2044
2069
|
* Human-readable message for each error code.
|
|
2045
2070
|
*
|
|
@@ -2074,24 +2099,29 @@ declare const AUTH_ERROR_MESSAGES: Readonly<Record<AuthErrorCode, string>>;
|
|
|
2074
2099
|
* }
|
|
2075
2100
|
* ```
|
|
2076
2101
|
*
|
|
2102
|
+
* The HTTP status is NOT a parameter — it is derived from the code via
|
|
2103
|
+
* {@link AUTH_ERROR_STATUS}. There is no way to answer one code with two statuses, which is
|
|
2104
|
+
* what a defaulted status argument allowed: thirteen codes drifted from the status rust-auth
|
|
2105
|
+
* answers for the same code, and five answered differently at different throw sites, none of
|
|
2106
|
+
* it visible to the type system, the linter, or either library's suite. Pass a `details`
|
|
2107
|
+
* payload where the failure carries one; the status follows the code.
|
|
2108
|
+
*
|
|
2077
2109
|
* @example
|
|
2078
2110
|
* ```typescript
|
|
2079
2111
|
* throw new AuthException(AUTH_ERROR_CODES.INVALID_CREDENTIALS)
|
|
2080
|
-
* throw new AuthException(AUTH_ERROR_CODES.FORBIDDEN
|
|
2081
|
-
* throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED,
|
|
2082
|
-
* retryAfterSeconds: 300
|
|
2083
|
-
* })
|
|
2112
|
+
* throw new AuthException(AUTH_ERROR_CODES.FORBIDDEN)
|
|
2113
|
+
* throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED, { retryAfterSeconds: 300 })
|
|
2084
2114
|
* ```
|
|
2085
2115
|
*/
|
|
2086
2116
|
declare class AuthException extends HttpException {
|
|
2087
2117
|
/**
|
|
2088
|
-
* @param code - Stable machine-readable error code from `AUTH_ERROR_CODES`.
|
|
2089
|
-
*
|
|
2118
|
+
* @param code - Stable machine-readable error code from `AUTH_ERROR_CODES`. Determines both
|
|
2119
|
+
* the default message and the HTTP status.
|
|
2090
2120
|
* @param details - Optional structured payload attached to the error body under
|
|
2091
2121
|
* `error.details`. An array where the failure is a list — `auth.validation` renders its
|
|
2092
2122
|
* per-field failures that way, matching what rust-auth serializes for the same code.
|
|
2093
2123
|
*/
|
|
2094
|
-
constructor(code: AuthErrorCode,
|
|
2124
|
+
constructor(code: AuthErrorCode, details?: Record<string, unknown> | readonly unknown[]);
|
|
2095
2125
|
}
|
|
2096
2126
|
|
|
2097
2127
|
/**
|
|
@@ -8714,4 +8744,4 @@ declare function AuthRateLimit(config: {
|
|
|
8714
8744
|
default: AuthRateLimitWindow;
|
|
8715
8745
|
}): MethodDecorator;
|
|
8716
8746
|
|
|
8717
|
-
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|
|
8747
|
+
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|
package/dist/server/index.mjs
CHANGED
|
@@ -1620,6 +1620,46 @@ var AUTH_ERROR_CODES = {
|
|
|
1620
1620
|
*/
|
|
1621
1621
|
INTERNAL: "auth.internal"
|
|
1622
1622
|
};
|
|
1623
|
+
var AUTH_ERROR_STATUS = {
|
|
1624
|
+
"auth.invalid_credentials": 401,
|
|
1625
|
+
"auth.account_locked": 429,
|
|
1626
|
+
"auth.account_inactive": 403,
|
|
1627
|
+
"auth.account_suspended": 403,
|
|
1628
|
+
"auth.account_banned": 403,
|
|
1629
|
+
"auth.pending_approval": 403,
|
|
1630
|
+
"auth.token_expired": 401,
|
|
1631
|
+
"auth.token_revoked": 401,
|
|
1632
|
+
"auth.token_invalid": 401,
|
|
1633
|
+
"auth.token_missing": 401,
|
|
1634
|
+
"auth.refresh_token_invalid": 401,
|
|
1635
|
+
"auth.session_not_found": 404,
|
|
1636
|
+
"auth.email_already_exists": 409,
|
|
1637
|
+
"auth.email_not_verified": 403,
|
|
1638
|
+
"auth.email_change_token_invalid": 400,
|
|
1639
|
+
"auth.mfa_required": 403,
|
|
1640
|
+
"auth.mfa_invalid_code": 401,
|
|
1641
|
+
"auth.mfa_already_enabled": 409,
|
|
1642
|
+
"auth.mfa_not_enabled": 400,
|
|
1643
|
+
"auth.mfa_setup_required": 400,
|
|
1644
|
+
"auth.mfa_temp_token_invalid": 401,
|
|
1645
|
+
"auth.mfa_state_conflict": 409,
|
|
1646
|
+
"auth.password_compromised": 400,
|
|
1647
|
+
"auth.password_reset_token_invalid": 400,
|
|
1648
|
+
"auth.otp_invalid": 401,
|
|
1649
|
+
"auth.otp_expired": 401,
|
|
1650
|
+
"auth.otp_max_attempts": 401,
|
|
1651
|
+
"auth.insufficient_role": 403,
|
|
1652
|
+
"auth.forbidden": 403,
|
|
1653
|
+
"auth.validation": 400,
|
|
1654
|
+
"auth.too_many_requests": 429,
|
|
1655
|
+
"auth.untrusted_origin": 403,
|
|
1656
|
+
"auth.reauthentication_required": 403,
|
|
1657
|
+
"auth.invalid_invitation_token": 400,
|
|
1658
|
+
"auth.oauth_failed": 401,
|
|
1659
|
+
"auth.oauth_email_mismatch": 409,
|
|
1660
|
+
"auth.platform_auth_required": 401,
|
|
1661
|
+
"auth.internal": 500
|
|
1662
|
+
};
|
|
1623
1663
|
var AUTH_ERROR_MESSAGES = {
|
|
1624
1664
|
"auth.invalid_credentials": "Invalid email or password",
|
|
1625
1665
|
"auth.account_locked": "Account temporarily locked. Please try again in a few minutes.",
|
|
@@ -1660,27 +1700,34 @@ var AUTH_ERROR_MESSAGES = {
|
|
|
1660
1700
|
"auth.platform_auth_required": "Platform authentication required",
|
|
1661
1701
|
"auth.internal": "Internal server error"
|
|
1662
1702
|
};
|
|
1703
|
+
var MESSAGE_BY_CODE = new Map(Object.entries(AUTH_ERROR_MESSAGES));
|
|
1704
|
+
var STATUS_BY_CODE = new Map(Object.entries(AUTH_ERROR_STATUS));
|
|
1663
1705
|
var AuthException = class extends HttpException {
|
|
1664
1706
|
static {
|
|
1665
1707
|
__name(this, "AuthException");
|
|
1666
1708
|
}
|
|
1667
1709
|
/**
|
|
1668
|
-
* @param code - Stable machine-readable error code from `AUTH_ERROR_CODES`.
|
|
1669
|
-
*
|
|
1710
|
+
* @param code - Stable machine-readable error code from `AUTH_ERROR_CODES`. Determines both
|
|
1711
|
+
* the default message and the HTTP status.
|
|
1670
1712
|
* @param details - Optional structured payload attached to the error body under
|
|
1671
1713
|
* `error.details`. An array where the failure is a list — `auth.validation` renders its
|
|
1672
1714
|
* per-field failures that way, matching what rust-auth serializes for the same code.
|
|
1673
1715
|
*/
|
|
1674
|
-
constructor(code,
|
|
1675
|
-
super(
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1716
|
+
constructor(code, details) {
|
|
1717
|
+
super(
|
|
1718
|
+
{
|
|
1719
|
+
error: {
|
|
1720
|
+
code,
|
|
1721
|
+
// Runtime fallback for future/unknown codes not yet in AUTH_ERROR_MESSAGES (type cast in tests, forward-compat).
|
|
1722
|
+
message: MESSAGE_BY_CODE.get(code) ?? code,
|
|
1723
|
+
details: details ?? null
|
|
1724
|
+
}
|
|
1725
|
+
},
|
|
1726
|
+
// A code with no entry is a programming error on the throwing side, not something the
|
|
1727
|
+
// caller did — 500 says so, and says it with a number rather than the `undefined` an
|
|
1728
|
+
// unguarded lookup used to hand to Express.
|
|
1729
|
+
STATUS_BY_CODE.get(code) ?? HttpStatus.INTERNAL_SERVER_ERROR
|
|
1730
|
+
);
|
|
1684
1731
|
}
|
|
1685
1732
|
};
|
|
1686
1733
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
@@ -2694,7 +2741,7 @@ var AuthRateLimitGuard = class {
|
|
|
2694
2741
|
const hits = await this.redis.incrWithFixedTtl(key, windowSeconds);
|
|
2695
2742
|
if (hits <= limit.limit) return true;
|
|
2696
2743
|
context.switchToHttp().getResponse().setHeader("Retry-After", windowSeconds);
|
|
2697
|
-
throw new AuthException(AUTH_ERROR_CODES.TOO_MANY_REQUESTS
|
|
2744
|
+
throw new AuthException(AUTH_ERROR_CODES.TOO_MANY_REQUESTS);
|
|
2698
2745
|
}
|
|
2699
2746
|
/**
|
|
2700
2747
|
* The counter key for one caller on one route.
|
|
@@ -2772,7 +2819,7 @@ function assertNotBlocked(status, blockedStatuses) {
|
|
|
2772
2819
|
if (!blockedStatuses.some((blocked) => blocked.toLowerCase() === canonical)) {
|
|
2773
2820
|
return;
|
|
2774
2821
|
}
|
|
2775
|
-
throw new AuthException(BLOCKED_STATUS_CODES.get(canonical) ?? AUTH_ERROR_CODES.ACCOUNT_INACTIVE
|
|
2822
|
+
throw new AuthException(BLOCKED_STATUS_CODES.get(canonical) ?? AUTH_ERROR_CODES.ACCOUNT_INACTIVE);
|
|
2776
2823
|
}
|
|
2777
2824
|
__name(assertNotBlocked, "assertNotBlocked");
|
|
2778
2825
|
|
|
@@ -3429,12 +3476,12 @@ var TrustedOriginGuard = class {
|
|
|
3429
3476
|
if (typeof origin === "string") {
|
|
3430
3477
|
if (this.options.cookies.trustedOrigins.includes(origin)) return true;
|
|
3431
3478
|
if (sawFetchSite || this.options.cookies.trustedOrigins.length > 0) {
|
|
3432
|
-
throw new AuthException(AUTH_ERROR_CODES.UNTRUSTED_ORIGIN
|
|
3479
|
+
throw new AuthException(AUTH_ERROR_CODES.UNTRUSTED_ORIGIN);
|
|
3433
3480
|
}
|
|
3434
3481
|
return true;
|
|
3435
3482
|
}
|
|
3436
3483
|
if (sawFetchSite) {
|
|
3437
|
-
throw new AuthException(AUTH_ERROR_CODES.UNTRUSTED_ORIGIN
|
|
3484
|
+
throw new AuthException(AUTH_ERROR_CODES.UNTRUSTED_ORIGIN);
|
|
3438
3485
|
}
|
|
3439
3486
|
return true;
|
|
3440
3487
|
}
|
|
@@ -3582,7 +3629,7 @@ function createAuthValidationPipe(options = {}) {
|
|
|
3582
3629
|
whitelist: true,
|
|
3583
3630
|
forbidNonWhitelisted: true,
|
|
3584
3631
|
...options,
|
|
3585
|
-
exceptionFactory: /* @__PURE__ */ __name((errors) => new AuthException(AUTH_ERROR_CODES.VALIDATION,
|
|
3632
|
+
exceptionFactory: /* @__PURE__ */ __name((errors) => new AuthException(AUTH_ERROR_CODES.VALIDATION, flattenValidationErrors(errors)), "exceptionFactory")
|
|
3586
3633
|
});
|
|
3587
3634
|
}
|
|
3588
3635
|
__name(createAuthValidationPipe, "createAuthValidationPipe");
|
|
@@ -4071,7 +4118,7 @@ var PasswordService = class _PasswordService {
|
|
|
4071
4118
|
*/
|
|
4072
4119
|
assertLongEnough(plain, field) {
|
|
4073
4120
|
if (plain.length >= this.minLength) return;
|
|
4074
|
-
throw new AuthException(AUTH_ERROR_CODES.VALIDATION,
|
|
4121
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
|
|
4075
4122
|
{
|
|
4076
4123
|
field,
|
|
4077
4124
|
message: `${field} must be at least ${String(this.minLength)} characters`
|
|
@@ -4111,7 +4158,7 @@ var PasswordService = class _PasswordService {
|
|
|
4111
4158
|
return;
|
|
4112
4159
|
}
|
|
4113
4160
|
if (breached) {
|
|
4114
|
-
throw new AuthException(AUTH_ERROR_CODES.PASSWORD_COMPROMISED
|
|
4161
|
+
throw new AuthException(AUTH_ERROR_CODES.PASSWORD_COMPROMISED);
|
|
4115
4162
|
}
|
|
4116
4163
|
}
|
|
4117
4164
|
async hash(plain) {
|
|
@@ -5657,12 +5704,14 @@ function normalizeEmail(email) {
|
|
|
5657
5704
|
return email.trim().toLowerCase();
|
|
5658
5705
|
}
|
|
5659
5706
|
__name(normalizeEmail, "normalizeEmail");
|
|
5707
|
+
|
|
5708
|
+
// src/server/utils/resolve-tenant-id.ts
|
|
5660
5709
|
async function resolveTenantId(dtoTenantId, req, resolver) {
|
|
5661
5710
|
if (resolver) {
|
|
5662
5711
|
return await resolver(req);
|
|
5663
5712
|
}
|
|
5664
5713
|
if (dtoTenantId === void 0 || dtoTenantId === null) {
|
|
5665
|
-
throw new AuthException(AUTH_ERROR_CODES.VALIDATION,
|
|
5714
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
|
|
5666
5715
|
{
|
|
5667
5716
|
field: "tenantId",
|
|
5668
5717
|
message: "tenantId is required unless the deployment configures tenantIdResolver"
|
|
@@ -5910,7 +5959,7 @@ var AuthService = class _AuthService {
|
|
|
5910
5959
|
tenantId,
|
|
5911
5960
|
reason: "locked_out"
|
|
5912
5961
|
}, context);
|
|
5913
|
-
throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED,
|
|
5962
|
+
throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED, {
|
|
5914
5963
|
retryAfterSeconds: remainingSeconds
|
|
5915
5964
|
});
|
|
5916
5965
|
}
|
|
@@ -6535,7 +6584,7 @@ var WsTicketService = class _WsTicketService {
|
|
|
6535
6584
|
}
|
|
6536
6585
|
if (payload.mfaEnabled && payload.mfaVerified !== true) {
|
|
6537
6586
|
this.logger.warn(`ws-ticket: refused, MFA not satisfied userId=${payload.sub}`);
|
|
6538
|
-
throw new AuthException(AUTH_ERROR_CODES.MFA_REQUIRED
|
|
6587
|
+
throw new AuthException(AUTH_ERROR_CODES.MFA_REQUIRED);
|
|
6539
6588
|
}
|
|
6540
6589
|
const user = await this.userRepo.findById(payload.sub);
|
|
6541
6590
|
if (!user) throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
@@ -7628,17 +7677,17 @@ var InvitationService = class _InvitationService {
|
|
|
7628
7677
|
const normalizedEmail = normalizeEmail(email);
|
|
7629
7678
|
const hierarchy = this.options.roles.hierarchy;
|
|
7630
7679
|
if (!Object.hasOwn(hierarchy, role)) {
|
|
7631
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7680
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7632
7681
|
}
|
|
7633
7682
|
const inviter = await this.userRepo.findById(inviterUserId);
|
|
7634
7683
|
if (!inviter) {
|
|
7635
7684
|
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
7636
7685
|
}
|
|
7637
7686
|
if (inviter.tenantId !== tenantId) {
|
|
7638
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7687
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7639
7688
|
}
|
|
7640
7689
|
if (!hasRole(inviter.role, role, hierarchy)) {
|
|
7641
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7690
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7642
7691
|
}
|
|
7643
7692
|
const rawToken = generateSecureToken(32);
|
|
7644
7693
|
const tokenHash = sha256(rawToken);
|
|
@@ -7767,7 +7816,7 @@ var InvitationService = class _InvitationService {
|
|
|
7767
7816
|
const pending = raw === null ? null : this.parseInvitation(raw);
|
|
7768
7817
|
if (pending !== null && !this.mayWithdraw(inviter, pending)) {
|
|
7769
7818
|
this.logger.warn(`create: refused email=${maskEmail(email)} tenantId=${logSafe(tenantId)} inviterRole=${logSafe(inviter.role)} \u2014 outranked by the pending invitation`);
|
|
7770
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7819
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7771
7820
|
}
|
|
7772
7821
|
return tokenHash;
|
|
7773
7822
|
}
|
|
@@ -7802,7 +7851,7 @@ var InvitationService = class _InvitationService {
|
|
|
7802
7851
|
if (claim.claimed) return approved;
|
|
7803
7852
|
}
|
|
7804
7853
|
this.logger.warn(`create: refused email=${maskEmail(email)} tenantId=${logSafe(tenantId)} \u2014 the pending invitation kept changing under the rank check`);
|
|
7805
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7854
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7806
7855
|
}
|
|
7807
7856
|
/**
|
|
7808
7857
|
* Atomically points the invitee index at `tokenHash`, answering with the hash it displaced.
|
|
@@ -7869,10 +7918,10 @@ var InvitationService = class _InvitationService {
|
|
|
7869
7918
|
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
7870
7919
|
}
|
|
7871
7920
|
if (revoker.tenantId !== tenantId) {
|
|
7872
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7921
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7873
7922
|
}
|
|
7874
7923
|
if (!this.inGoodStanding(revoker)) {
|
|
7875
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
7924
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
7876
7925
|
}
|
|
7877
7926
|
const indexKey = this.inviteeKey(normalizedEmail, tenantId);
|
|
7878
7927
|
const tokenHash = await this.redis.get(indexKey);
|
|
@@ -8648,7 +8697,7 @@ var MfaService = class _MfaService {
|
|
|
8648
8697
|
const acquireLegacy = legacyLockKey !== scopedLockKey;
|
|
8649
8698
|
const lockToken = randomBytes(16).toString("hex");
|
|
8650
8699
|
if (!await this.redis.setIfAbsent(scopedLockKey, lockToken, MFA_TRANSITION_LOCK_TTL_SECONDS)) {
|
|
8651
|
-
throw new AuthException(AUTH_ERROR_CODES.MFA_STATE_CONFLICT
|
|
8700
|
+
throw new AuthException(AUTH_ERROR_CODES.MFA_STATE_CONFLICT);
|
|
8652
8701
|
}
|
|
8653
8702
|
if (acquireLegacy && !await this.redis.setIfAbsent(legacyLockKey, lockToken, MFA_TRANSITION_LOCK_TTL_SECONDS)) {
|
|
8654
8703
|
await this.redis.eval(RELEASE_LOCK_LUA, [
|
|
@@ -8656,7 +8705,7 @@ var MfaService = class _MfaService {
|
|
|
8656
8705
|
], [
|
|
8657
8706
|
lockToken
|
|
8658
8707
|
]);
|
|
8659
|
-
throw new AuthException(AUTH_ERROR_CODES.MFA_STATE_CONFLICT
|
|
8708
|
+
throw new AuthException(AUTH_ERROR_CODES.MFA_STATE_CONFLICT);
|
|
8660
8709
|
}
|
|
8661
8710
|
try {
|
|
8662
8711
|
const current = await this.fetchUserForContext(context, userId, tenantId);
|
|
@@ -9441,7 +9490,7 @@ var MfaService = class _MfaService {
|
|
|
9441
9490
|
const recent = await this.redis.get(recentAuthKey(context, userId, this.options.hmacKey, tenantId));
|
|
9442
9491
|
if (recent === null) {
|
|
9443
9492
|
this.logger.warn(`reauthenticate: no recent authentication userId=${userId} context=${context}`);
|
|
9444
|
-
throw new AuthException(AUTH_ERROR_CODES.REAUTHENTICATION_REQUIRED
|
|
9493
|
+
throw new AuthException(AUTH_ERROR_CODES.REAUTHENTICATION_REQUIRED);
|
|
9445
9494
|
}
|
|
9446
9495
|
return;
|
|
9447
9496
|
}
|
|
@@ -9500,7 +9549,7 @@ var MfaService = class _MfaService {
|
|
|
9500
9549
|
*/
|
|
9501
9550
|
assertPlaneTenant(context, tenantId) {
|
|
9502
9551
|
if (context === "dashboard" && (tenantId === void 0 || tenantId === "") || context === "platform" && tenantId !== void 0) {
|
|
9503
|
-
throw new AuthException(AUTH_ERROR_CODES.VALIDATION,
|
|
9552
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
|
|
9504
9553
|
{
|
|
9505
9554
|
field: "tenantId",
|
|
9506
9555
|
message: "tenantId must be a non-empty value on the dashboard plane and absent on the platform plane"
|
|
@@ -11271,7 +11320,7 @@ var PlatformAuthService = class _PlatformAuthService {
|
|
|
11271
11320
|
if (locked) {
|
|
11272
11321
|
this.logger.warn(`login: account locked email=${maskEmail(dto.email)}`);
|
|
11273
11322
|
const retryAfterSeconds = await this.bruteForce.getRemainingLockoutSeconds(bfIdentifier);
|
|
11274
|
-
throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED,
|
|
11323
|
+
throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED, {
|
|
11275
11324
|
retryAfterSeconds
|
|
11276
11325
|
});
|
|
11277
11326
|
}
|
|
@@ -12128,7 +12177,7 @@ var MfaRequiredGuard = class {
|
|
|
12128
12177
|
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
12129
12178
|
}
|
|
12130
12179
|
if (user.mfaEnabled === true && user.mfaVerified !== true) {
|
|
12131
|
-
throw new AuthException(AUTH_ERROR_CODES.MFA_REQUIRED
|
|
12180
|
+
throw new AuthException(AUTH_ERROR_CODES.MFA_REQUIRED);
|
|
12132
12181
|
}
|
|
12133
12182
|
return true;
|
|
12134
12183
|
}
|
|
@@ -12195,11 +12244,11 @@ var PlatformRolesGuard = class {
|
|
|
12195
12244
|
const userRole = user.role;
|
|
12196
12245
|
const hierarchy = this.options.roles.platformHierarchy;
|
|
12197
12246
|
if (!hierarchy) {
|
|
12198
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
12247
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
12199
12248
|
}
|
|
12200
12249
|
const allowed = requiredRoles.some((required) => hasRole(userRole, required, hierarchy));
|
|
12201
12250
|
if (!allowed) {
|
|
12202
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
12251
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
12203
12252
|
}
|
|
12204
12253
|
return true;
|
|
12205
12254
|
}
|
|
@@ -12263,12 +12312,12 @@ var RolesGuard = class {
|
|
|
12263
12312
|
const request = context.switchToHttp().getRequest();
|
|
12264
12313
|
const userRole = request.user?.role;
|
|
12265
12314
|
if (!userRole) {
|
|
12266
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
12315
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
12267
12316
|
}
|
|
12268
12317
|
const hierarchy = this.options.roles.hierarchy;
|
|
12269
12318
|
const allowed = requiredRoles.some((required) => hasRole(userRole, required, hierarchy));
|
|
12270
12319
|
if (!allowed) {
|
|
12271
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
12320
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
12272
12321
|
}
|
|
12273
12322
|
return true;
|
|
12274
12323
|
}
|
|
@@ -12558,7 +12607,7 @@ var OAuthService = class _OAuthService {
|
|
|
12558
12607
|
const derivedName = profile.name ?? profile.email.split("@")[0] ?? profile.email;
|
|
12559
12608
|
if (await this.userRepo.findByEmail(profile.email, tenantId)) {
|
|
12560
12609
|
this.logger.warn(`oauth: create refused \u2014 ${maskEmail(profile.email)} already exists in tenant ${tenantId}`);
|
|
12561
|
-
throw new AuthException(AUTH_ERROR_CODES.OAUTH_EMAIL_MISMATCH
|
|
12610
|
+
throw new AuthException(AUTH_ERROR_CODES.OAUTH_EMAIL_MISMATCH);
|
|
12562
12611
|
}
|
|
12563
12612
|
authUser = await this.userRepo.createWithOAuth({
|
|
12564
12613
|
email: profile.email,
|
|
@@ -12593,7 +12642,7 @@ var OAuthService = class _OAuthService {
|
|
|
12593
12642
|
}
|
|
12594
12643
|
assertNotBlocked(authUser.status, this.options.blockedStatuses);
|
|
12595
12644
|
if (this.options.emailVerification.required && !authUser.emailVerified) {
|
|
12596
|
-
throw new AuthException(AUTH_ERROR_CODES.EMAIL_NOT_VERIFIED
|
|
12645
|
+
throw new AuthException(AUTH_ERROR_CODES.EMAIL_NOT_VERIFIED);
|
|
12597
12646
|
}
|
|
12598
12647
|
if (authUser.mfaEnabled) {
|
|
12599
12648
|
const mfaTempToken = await this.tokenManager.issueMfaTempToken(authUser.id, "dashboard", authUser.tenantId);
|
|
@@ -14467,22 +14516,22 @@ var SelfOrAdminGuard = class {
|
|
|
14467
14516
|
canActivate(context) {
|
|
14468
14517
|
const request = context.switchToHttp().getRequest();
|
|
14469
14518
|
if (request.user == null) {
|
|
14470
|
-
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID
|
|
14519
|
+
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
14471
14520
|
}
|
|
14472
14521
|
const rawParam = request.params["userId"] ?? request.params["id"];
|
|
14473
14522
|
if (rawParam === void 0) {
|
|
14474
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
14523
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
14475
14524
|
}
|
|
14476
14525
|
const paramValue = resolveParamString(rawParam);
|
|
14477
14526
|
if (paramValue === void 0) {
|
|
14478
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
14527
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
14479
14528
|
}
|
|
14480
14529
|
if (isHexLooking(paramValue) && !STRICT_SHA256_RE.test(paramValue)) {
|
|
14481
|
-
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID
|
|
14530
|
+
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
14482
14531
|
}
|
|
14483
14532
|
if (request.user.sub === paramValue) return true;
|
|
14484
14533
|
if (hasRole(request.user.role, "admin", this.options.roles.hierarchy)) return true;
|
|
14485
|
-
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE
|
|
14534
|
+
throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
|
|
14486
14535
|
}
|
|
14487
14536
|
};
|
|
14488
14537
|
SelfOrAdminGuard = _ts_decorate64([
|
|
@@ -14694,4 +14743,4 @@ AuthExceptionFilter = _ts_decorate66([
|
|
|
14694
14743
|
Catch()
|
|
14695
14744
|
], AuthExceptionFilter);
|
|
14696
14745
|
|
|
14697
|
-
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AllowAllBreachChecker, AuthException, AuthExceptionFilter, AuthRateLimit, AuthRateLimitGuard, AuthRevocationService, AuthService, Authenticated, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, BruteForceService, BymaxAuthModule, ChangePasswordDto, CommonPasswordChecker, CreateInvitationDto, CurrentUser, DefaultAuthEmailProvider, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, IS_PUBLIC_KEY, InvitationService, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformAuthService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|
|
14746
|
+
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AllowAllBreachChecker, AuthException, AuthExceptionFilter, AuthRateLimit, AuthRateLimitGuard, AuthRevocationService, AuthService, Authenticated, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, BruteForceService, BymaxAuthModule, ChangePasswordDto, CommonPasswordChecker, CreateInvitationDto, CurrentUser, DefaultAuthEmailProvider, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, IS_PUBLIC_KEY, InvitationService, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformAuthService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-auth",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|