@lenne.tech/nest-server 12.6.11 → 12.6.13
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/.claude/rules/package-management.md +7 -7
- package/.claude/rules/role-system.md +10 -0
- package/.claude/rules/testing.md +4 -4
- package/FRAMEWORK-API.md +1 -1
- package/dist/core/common/decorators/rest-user.decorator.js +4 -0
- package/dist/core/common/decorators/rest-user.decorator.js.map +1 -1
- package/dist/core/common/filters/http-exception-log.filter.js +4 -0
- package/dist/core/common/filters/http-exception-log.filter.js.map +1 -1
- package/dist/core/common/helpers/byte-range.helper.d.ts +8 -0
- package/dist/core/common/helpers/byte-range.helper.js +71 -0
- package/dist/core/common/helpers/byte-range.helper.js.map +1 -0
- package/dist/core/common/helpers/context.helper.js +9 -0
- package/dist/core/common/helpers/context.helper.js.map +1 -1
- package/dist/core/common/helpers/decorator.helper.js +4 -0
- package/dist/core/common/helpers/decorator.helper.js.map +1 -1
- package/dist/core/common/helpers/execution-context-request.helper.d.ts +9 -1
- package/dist/core/common/helpers/execution-context-request.helper.js +29 -0
- package/dist/core/common/helpers/execution-context-request.helper.js.map +1 -1
- package/dist/core/common/helpers/graphql-upload.helper.d.ts +10 -0
- package/dist/core/common/helpers/graphql-upload.helper.js +220 -0
- package/dist/core/common/helpers/graphql-upload.helper.js.map +1 -0
- package/dist/core/common/helpers/gridfs.helper.d.ts +7 -2
- package/dist/core/common/helpers/gridfs.helper.js +7 -4
- package/dist/core/common/helpers/gridfs.helper.js.map +1 -1
- package/dist/core/common/interceptors/translate-response.interceptor.js +4 -0
- package/dist/core/common/interceptors/translate-response.interceptor.js.map +1 -1
- package/dist/core/common/services/core-s3.service.d.ts +3 -0
- package/dist/core/common/services/core-s3.service.js +8 -1
- package/dist/core/common/services/core-s3.service.js.map +1 -1
- package/dist/core/modules/auth/guards/auth.guard.js +10 -2
- package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js +4 -1
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js +11 -1
- package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
- package/dist/core/modules/better-auth/better-auth-roles.guard.js +15 -1
- package/dist/core/modules/better-auth/better-auth-roles.guard.js.map +1 -1
- package/dist/core/modules/error-code/error-codes.d.ts +9 -0
- package/dist/core/modules/error-code/error-codes.js +8 -0
- package/dist/core/modules/error-code/error-codes.js.map +1 -1
- package/dist/core/modules/file/core-file.controller.d.ts +5 -0
- package/dist/core/modules/file/core-file.controller.js +66 -4
- package/dist/core/modules/file/core-file.controller.js.map +1 -1
- package/dist/core/modules/file/core-file.service.d.ts +2 -0
- package/dist/core/modules/file/core-file.service.js +17 -6
- package/dist/core/modules/file/core-file.service.js.map +1 -1
- package/dist/core/modules/file/filesystem-file.helper.d.ts +2 -1
- package/dist/core/modules/file/filesystem-file.helper.js +2 -2
- package/dist/core/modules/file/filesystem-file.helper.js.map +1 -1
- package/dist/core/modules/file/interfaces/file-service-options.interface.d.ts +2 -0
- package/dist/core/modules/file/s3-file.helper.d.ts +2 -0
- package/dist/core/modules/file/s3-file.helper.js.map +1 -1
- package/dist/core/modules/tenant/core-tenant.guard.js +9 -1
- package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
- package/dist/core.module.js +2 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/server/modules/error-code/error-codes.d.ts +1 -0
- package/dist/test/test.helper.d.ts +1 -0
- package/dist/test/test.helper.js +6 -0
- package/dist/test/test.helper.js.map +1 -1
- package/dist/types/graphql-upload.d.ts +34 -2
- package/docs/REQUEST-LIFECYCLE.md +31 -9
- package/docs/error-codes.md +14 -0
- package/docs/security-overrides.md +34 -6
- package/migration-guides/12.6.11-to-12.6.12.md +180 -0
- package/migration-guides/12.6.12-to-12.6.13.md +162 -0
- package/package.json +15 -8
- package/src/core/common/decorators/rest-user.decorator.ts +6 -0
- package/src/core/common/filters/http-exception-log.filter.ts +9 -0
- package/src/core/common/helpers/byte-range.helper.ts +144 -0
- package/src/core/common/helpers/context.helper.ts +14 -0
- package/src/core/common/helpers/decorator.helper.ts +5 -0
- package/src/core/common/helpers/execution-context-request.helper.ts +78 -1
- package/src/core/common/helpers/graphql-upload.helper.ts +482 -0
- package/src/core/common/helpers/gridfs.helper.ts +20 -6
- package/src/core/common/interceptors/translate-response.interceptor.ts +8 -0
- package/src/core/common/services/core-s3.service.ts +16 -2
- package/src/core/modules/auth/guards/auth.guard.ts +19 -2
- package/src/core/modules/auth/guards/legacy-auth-rate-limit.guard.ts +9 -2
- package/src/core/modules/auth/guards/roles.guard.ts +23 -1
- package/src/core/modules/better-auth/better-auth-roles.guard.ts +29 -1
- package/src/core/modules/error-code/error-codes.ts +13 -0
- package/src/core/modules/file/INTEGRATION-CHECKLIST.md +1 -0
- package/src/core/modules/file/README.md +74 -1
- package/src/core/modules/file/core-file.controller.ts +139 -3
- package/src/core/modules/file/core-file.service.ts +33 -13
- package/src/core/modules/file/filesystem-file.helper.ts +8 -3
- package/src/core/modules/file/interfaces/file-service-options.interface.ts +13 -0
- package/src/core/modules/file/s3-file.helper.ts +3 -2
- package/src/core/modules/tenant/core-tenant.guard.ts +13 -1
- package/src/core.module.ts +5 -1
- package/src/index.ts +2 -0
- package/src/test/README.md +8 -4
- package/src/test/test.helper.ts +12 -0
- package/src/types/graphql-upload.d.ts +34 -2
package/docs/error-codes.md
CHANGED
|
@@ -446,6 +446,20 @@ All error codes follow the format: `#PREFIX_XXXX: Description`
|
|
|
446
446
|
|
|
447
447
|
---
|
|
448
448
|
|
|
449
|
+
### LTNS_0503: fileRangeNotSatisfiable
|
|
450
|
+
|
|
451
|
+
**Message:** Requested range not satisfiable
|
|
452
|
+
|
|
453
|
+
**Description:** Answered with HTTP 416 by the file download routes (and by `resolveDownloadRange()` in a project's own route) when the `Range` header asks for bytes that start at or past the end of the file, or for a suffix of length 0. The response carries `Content-Range: bytes */<length>` with the real size, so the client can ask again. Since 12.6.12.
|
|
454
|
+
|
|
455
|
+
**Solution:** Request a range inside the file (`bytes=0-` is always satisfiable for a non-empty file). An empty file has no satisfiable range — request it without `Range`.
|
|
456
|
+
|
|
457
|
+
**Translations:**
|
|
458
|
+
- DE: Der angeforderte Bereich liegt außerhalb der Datei.
|
|
459
|
+
- EN: The requested range lies outside the file.
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
449
463
|
## Internal Errors (LTNS_0900-LTNS_0999)
|
|
450
464
|
|
|
451
465
|
### LTNS_0900: internalError
|
|
@@ -21,6 +21,17 @@ used to **exact-pin**, to a vulnerable version:
|
|
|
21
21
|
| `@graphql-tools/utils` | [GHSA-7mx3-vvmw-hjmv](https://github.com/advisories/GHSA-7mx3-vvmw-hjmv) — high: prototype pollution in `mergeDeep`, which runs while the GraphQL schema is assembled. Covers `<=12.0.0`, patched `>=12.0.1` (added 2026-10-06); [GHSA-c4qx-w738-7hr3](https://github.com/advisories/GHSA-c4qx-w738-7hr3) — high: prototype pollution in `mergeIncrementalResult` via non-primitive path segments. Covers `>=10.10.1 <=12.0.1`, patched `>=12.0.2` (published 2026-10-22) | `@nestjs/graphql` declares utils as an **exact pin**: 13.4.5 — the newest 13.x — `12.0.0`, and 14.0.3, the version this framework declares since 12.0.0, `12.0.1`. 12.0.1 clears the first advisory and is covered by the second, so **this entry is load-bearing on 13.x and on 14.0.x**. 14.1.0, the version this framework declares since 12.1.0, pins `12.1.0`, which clears both: there the entry is inert. `@apollo/server` reaches utils too, through `@graphql-tools/schema` / `merge` — and in a lockfile that still holds schema 10.0.x (resolved before 2026-08-12), as **utils 11.x**: vulnerable too, with no 11.x fix, and outside the override key. Lift it with `pnpm update --depth Infinity @graphql-tools/schema @graphql-tools/merge`; the current releases request utils `^12.1.0`, which needs Node >=22.15 — the framework's own floor since 11.42.10 |
|
|
22
22
|
| `multer` | [GHSA-wc9g-mqfw-jrwm](https://github.com/advisories/GHSA-wc9g-mqfw-jrwm), [GHSA-535w-7cp7-47q4](https://github.com/advisories/GHSA-535w-7cp7-47q4), [GHSA-qfvm-cv95-jqjf](https://github.com/advisories/GHSA-qfvm-cv95-jqjf) — high: DoS via crafted multipart input; [GHSA-qvfw-j98x-7q72](https://github.com/advisories/GHSA-qvfw-j98x-7q72) — low: file size limit bypass. Patched `>=2.3.0`; [GHSA-q7qp-rjg7-q26m](https://github.com/advisories/GHSA-q7qp-rjg7-q26m) — high: DoS via a pending asynchronous `fileFilter` after request teardown. Covers `>=2.0.0 <2.5.0`, patched `>=2.5.0` (published 2026-10-22) | `@nestjs/platform-express` declares multer as an **exact pin**: up to 11.2.5 `2.2.0`, 11.2.6 / 11.2.7 `2.4.0`, and so does 12.2.0, the version this framework declared in 12.0.x. 2.4.0 is covered by GHSA-q7qp-rjg7-q26m, so **this entry is load-bearing up to @nestjs/platform-express 12.2.0**. 12.3.2, the version this framework declares since 12.1.0, pins `2.5.0`: there the entry is inert. A direct `multer` dependency does not move the pin: you get both copies, and FileInterceptor uses the vulnerable one |
|
|
23
23
|
|
|
24
|
+
**Status since 12.6.12** (verified 2026-11-14): **`ws` needs a new entry.**
|
|
25
|
+
[GHSA-37g9-w4hg-h9qr](https://github.com/websockets/ws/security/advisories/GHSA-37g9-w4hg-h9qr) — high: a client
|
|
26
|
+
floods ping frames without reading the replies, the server buffers the automatic pongs, and the process runs out of
|
|
27
|
+
memory, before any authentication. Patched in `ws` 8.23.0 (and 7.5.14). `@nestjs/graphql` 14.1.2, the version this line declares, exact-pins `8.22.0`, and the GraphQL WebSocket server
|
|
28
|
+
runs on that copy, so the `ws` dependency nest-server declares (`8.23.0` since 12.6.12) does not lift it. Use the
|
|
29
|
+
`ws` entry from "The fix" — and **replace** an existing `ws` 8.x entry rather than raising only its target: pnpm
|
|
30
|
+
matches the key against the requested exact version, so a key whose upper bound stays below it leaves the vulnerable
|
|
31
|
+
copy in the tree. Until GitHub's global advisory database lists the advisory, `pnpm audit` does not report it.
|
|
32
|
+
`@nestjs/common`, `core` and `platform-express` 12.5.0 (declared since 12.6.12) also close GHSA-jgpx-8x6j-fcpf and
|
|
33
|
+
GHSA-c8fr-c7pf-58pf (high, process crashes): raise your own `@nestjs/*` pins to them.
|
|
34
|
+
|
|
24
35
|
**Status since 12.1.0** (verified 2026-10-29): with the `@nestjs/*` versions this framework declares, **no
|
|
25
36
|
entry is needed**. `@nestjs/platform-express` 12.3.2 pins `multer` 2.5.0 and `@nestjs/graphql` 14.1.0 pins
|
|
26
37
|
`@graphql-tools/utils` 12.1.0, both past their advisories, and nest-server's own `overrides:` block is empty:
|
|
@@ -62,7 +73,19 @@ entries. None of them is optional in practice.
|
|
|
62
73
|
## The fix
|
|
63
74
|
|
|
64
75
|
Add this to your project's `pnpm-workspace.yaml` (pnpm 11+; in pnpm 10 and earlier it lives under
|
|
65
|
-
`pnpm.overrides` in `package.json`).
|
|
76
|
+
`pnpm.overrides` in `package.json`).
|
|
77
|
+
|
|
78
|
+
**On nest-server 12.6.12 and later** this entry is needed (see "Status since 12.6.12"):
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
overrides:
|
|
82
|
+
# GHSA-37g9-w4hg-h9qr (high): @nestjs/graphql exact-pins ws (14.1.2: 8.22.0), and the GraphQL WebSocket server
|
|
83
|
+
# runs on that copy. Keep key and target in LOCKSTEP with the ws version @lenne.tech/nest-server declares
|
|
84
|
+
# (8.23.0 since 12.6.12). Remove once @nestjs/graphql pins ws >= 8.23.0.
|
|
85
|
+
'ws@>=8.0.0 <8.23.0': '8.23.0'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
On nest-server **12.0.x** these two entries are all it takes — a fresh
|
|
66
89
|
resolve of nest-server 12.0.0's own tree with and without every other former entry audits identically. On
|
|
67
90
|
**12.1.x** neither is needed once your `@nestjs/*` pins match the framework's (see "Status since 12.1.0"):
|
|
68
91
|
|
|
@@ -96,8 +119,9 @@ through globparts amplification) and [GHSA-3g3m-2fjr-6pw4](https://github.com/ad
|
|
|
96
119
|
(glob `<= 14.0.1`, moderate) are fixed only in new majors that no consumer can take yet: `@nestjs/cli` 12.0.11
|
|
97
120
|
pins minimatch 10.2.6 exactly, ts-morph 28 (`@ts-morph/common` 0.29), nodemon, `@swc/cli` and glob 13 need the 9.x /
|
|
98
121
|
10.x lines, rimraf 6.1.3 needs glob 13 — all on their newest release. An override across the major is no way out
|
|
99
|
-
(minimatch 11 removed `makeRe()` and `Minimatch#regexp`). nest-server suppresses
|
|
100
|
-
`auditConfig.unusableFixConsumers`, which `check:overrides` re-tests on every run
|
|
122
|
+
(minimatch 11 removed `makeRe()` and `Minimatch#regexp`). nest-server suppresses minimatch in its own repository with
|
|
123
|
+
`auditConfig.unusableFixConsumers`, which `check:overrides` re-tests on every run (glob until 12.6.12; rimraf 6.1.4 moved
|
|
124
|
+
to glob 14 — raise rimraf to 6.1.4 and the glob entry can go). What it found for its own tree:
|
|
101
125
|
the only production path is `@lenne.tech/nest-server > ts-morph > @ts-morph/common > minimatch`, used by the
|
|
102
126
|
Permissions module's scanner with globs the developer writes; every other path is dev tooling. Your project's tree
|
|
103
127
|
may have other paths, so check `pnpm why minimatch --prod` and `pnpm why glob --prod` before you suppress the same
|
|
@@ -108,7 +132,8 @@ way, and remove the entries once your consumers move to minimatch 11 / glob 14.
|
|
|
108
132
|
`@nestjs/graphql` 13 and `@nestjs/swagger` 11 exact-pin vulnerable versions of these two; their 12.x
|
|
109
133
|
successors pin patched ones (`ws` 8.22.0, `js-yaml` 5.5.0). On nest-server 12 remove both entries — an
|
|
110
134
|
inert `ws` entry is not harmless there: pnpm rewrites `graphql-ws`'s `ws` peer range to the override
|
|
111
|
-
target, so a target below 8.22.0 makes `pnpm peers check` report `unmet peer ws`.
|
|
135
|
+
target, so a target below 8.22.0 makes `pnpm peers check` report `unmet peer ws`. Since 12.6.12 nest-server 12
|
|
136
|
+
needs its own `ws` entry again, for GHSA-37g9-w4hg-h9qr: replace the 11.x entry with the one from "The fix".
|
|
112
137
|
|
|
113
138
|
```yaml
|
|
114
139
|
# nest-server 11.x only (@nestjs/graphql 13 exact-pins ws; GHSA-96hv-2xvq-fx4p, patched >=8.21.0)
|
|
@@ -133,7 +158,8 @@ tree to `2.0.11` even though nothing needed help any more.
|
|
|
133
158
|
|
|
134
159
|
### The `ws` target must stay in lockstep with the declared `ws` version
|
|
135
160
|
|
|
136
|
-
This applies while a project carries a `ws` entry at all
|
|
161
|
+
This applies while a project carries a `ws` entry at all: on nest-server 11.x, and on 12.6.12 and later. `8.23.0`
|
|
162
|
+
(since 12.6.12; `8.22.0` since 12.0.0,
|
|
137
163
|
`8.21.3` before) is not an arbitrary "latest patch" — it is the version
|
|
138
164
|
`@lenne.tech/nest-server` declares as an ordinary **dependency**, so it is already in your tree whether
|
|
139
165
|
or not you list `ws` yourself. The override target has to equal it.
|
|
@@ -146,7 +172,9 @@ when you read a manifest. The target was raised `8.21.1` → `8.21.3` on 2026-08
|
|
|
146
172
|
reason, and to `8.22.0` with nest-server 12.0.0.
|
|
147
173
|
|
|
148
174
|
**Rule:** whenever the `ws` version declared by `@lenne.tech/nest-server` (or by your own
|
|
149
|
-
`package.json`, if you list it) moves, move this override target with it in the
|
|
175
|
+
`package.json`, if you list it) moves, move this override's target **and the upper bound of its key** with it in the
|
|
176
|
+
same commit — pnpm matches the key against the requested range, so a key that stays below an exact pin no longer
|
|
177
|
+
reaches it. The
|
|
150
178
|
same applies to any other override whose package also appears as a declared dependency.
|
|
151
179
|
|
|
152
180
|
Then:
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Migration Guide: 12.6.11 → 12.6.12
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | None in nest-server. NestJS 12.5.0, which `pnpm run update` installs, adds startup errors for configurations it used to ignore (§5) |
|
|
8
|
+
| **New Features** | Byte ranges from every file store: `getFileStream(id, { range })`, `CoreS3Service.getObject(key, { range })`, `resolveDownloadRange()`, `setDownloadRangeHeaders()`, `parseRangeHeader()`; `TestDownloadOptions.headers` |
|
|
9
|
+
| **Bugfixes** | `GET /files/id/:id` and `GET /files/:filename` answered every `Range` request with `200` and the whole file — Safari does not play a video from such a server (§1) |
|
|
10
|
+
| **Security** | NestJS 12.5.0 closes GHSA-c8fr-c7pf-58pf and GHSA-jgpx-8x6j-fcpf (high, process crashes; §5). `ws` GHSA-37g9-w4hg-h9qr (high, unauthenticated memory-exhaustion DoS through the GraphQL WebSocket) — one override in your `pnpm-workspace.yaml` (§6) |
|
|
11
|
+
| **Also fixed** | Every S3 download the client aborted logged `ERROR File download failed: aborted` (§4) |
|
|
12
|
+
| **Migration Effort** | Projects with their OWN route for video, audio or large downloads: answer `Range` (§2). Everyone: `pnpm run update` and the `ws` override (§6) |
|
|
13
|
+
|
|
14
|
+
## Quick Migration
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @lenne.tech/nest-server@12.6.12
|
|
18
|
+
pnpm run update # nest-server-starter based projects
|
|
19
|
+
# replace the ws 8.x override in pnpm-workspace.yaml with the one from §6, then: pnpm install
|
|
20
|
+
grep -rn "pipeFileToResponse(" src/ # own download routes: serve ranges where media is delivered (§2)
|
|
21
|
+
pnpm run build
|
|
22
|
+
pnpm test
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual.
|
|
26
|
+
|
|
27
|
+
## 1. The framework's download routes answer ranges
|
|
28
|
+
|
|
29
|
+
Safari refuses to play a video, and stalls audio, from a server that answers a `Range` request with `200` and the
|
|
30
|
+
whole file. Chrome plays it anyway, so the problem showed neither locally nor in a Chromium-based Playwright run — it
|
|
31
|
+
showed on the first iPhone. Until 12.6.11 the core could not read a byte range at all: `CoreS3Service.getObject()` sent
|
|
32
|
+
no `Range`, and `getFileStream()` always opened the whole file. A project could serve ranges from GridFS and the
|
|
33
|
+
filesystem with its own code, but not from S3, which every deployed stage with `s3` configured uses.
|
|
34
|
+
|
|
35
|
+
Since 12.6.12 both download routes answer ranges on every store, without any change in the project:
|
|
36
|
+
|
|
37
|
+
| Request | Answer |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `Range: bytes=0-1` (one range inside the file) | `206`, `Content-Range: bytes 0-1/<length>`, `Content-Length: 2`, only those bytes |
|
|
40
|
+
| `Range: bytes=1000-` / `bytes=-500` | `206` with the rest of the file / its last 500 bytes |
|
|
41
|
+
| A range starting at or past the end of the file | `416`, `Content-Range: bytes */<length>`, `#LTNS_0503` |
|
|
42
|
+
| Several ranges, an invalid header, `If-Range` | `200` with the whole file, as before |
|
|
43
|
+
| No `Range` | `200` as before, now with `Accept-Ranges: bytes` |
|
|
44
|
+
|
|
45
|
+
The rights check runs first, as before: a refused or unknown file is `404` whatever the `Range` says. A `206` carries
|
|
46
|
+
`no-transform` in `Cache-Control` (`private, no-store, no-transform` by default), which keeps a `compression`
|
|
47
|
+
middleware from gzipping the partial body.
|
|
48
|
+
|
|
49
|
+
## 2. Own download routes
|
|
50
|
+
|
|
51
|
+
A route of your own that delivers media (or large files a client may resume) answers ranges with three calls:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import {
|
|
55
|
+
downloadAbortSignal,
|
|
56
|
+
openDownloadStream,
|
|
57
|
+
pipeFileToResponse,
|
|
58
|
+
resolveDownloadRange,
|
|
59
|
+
RESPONSE_GONE,
|
|
60
|
+
setDownloadRangeHeaders,
|
|
61
|
+
} from '@lenne.tech/nest-server';
|
|
62
|
+
|
|
63
|
+
@Get('video/:id')
|
|
64
|
+
async video(@Param('id') id: string, @Res() res: Response, @CurrentUser() currentUser) {
|
|
65
|
+
const serviceOptions = { abortSignal: downloadAbortSignal(res), currentUser };
|
|
66
|
+
const resolved = await this.fileService.resolveFile(id, serviceOptions); // rights check, length, store
|
|
67
|
+
if (!resolved) {
|
|
68
|
+
throw new NotFoundException();
|
|
69
|
+
}
|
|
70
|
+
const range = resolveDownloadRange(res, resolved.info.length); // throws 416 past the end
|
|
71
|
+
const stream = await openDownloadStream(res, () =>
|
|
72
|
+
this.fileService.getFileStream(id, { ...serviceOptions, range }, resolved.store),
|
|
73
|
+
);
|
|
74
|
+
if (stream === RESPONSE_GONE) {
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
if (!stream) {
|
|
78
|
+
throw new NotFoundException();
|
|
79
|
+
}
|
|
80
|
+
res.header('Content-Type', resolved.info.contentType || 'video/mp4');
|
|
81
|
+
res.header('Cache-Control', 'private, no-store');
|
|
82
|
+
setDownloadRangeHeaders(res, range, resolved.info.length); // 206 + Content-Range, or Accept-Ranges only
|
|
83
|
+
return pipeFileToResponse(stream, res);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- `resolveDownloadRange()` must run AFTER the rights check: a `416` confirms that the file exists.
|
|
88
|
+
- `setDownloadRangeHeaders()` goes after your own headers — it replaces `Content-Length` with the length of the range
|
|
89
|
+
and appends `no-transform` to `Cache-Control`.
|
|
90
|
+
- The range reaches every store: S3 with a ranged `GetObject`, GridFS from the chunk holding the first byte, the
|
|
91
|
+
filesystem from that offset — with the same idle guard and abort signal as a whole file, so an aborted range
|
|
92
|
+
releases its S3 socket at once.
|
|
93
|
+
|
|
94
|
+
**A project that reads ranges itself** (GridFS `openDownloadStream(id, { start, end })`, `createReadStream({ start,
|
|
95
|
+
end })`, a hand-written Range parser) can switch to these functions and drop its own code — and gets S3, which such
|
|
96
|
+
code could not reach. Mind the end: `range.end` is INCLUSIVE, like HTTP and `createReadStream()`; GridFS counts it
|
|
97
|
+
exclusive, which `getFileStream()` translates.
|
|
98
|
+
|
|
99
|
+
Lower-level pieces, for code that does not go through `CoreFileService`:
|
|
100
|
+
|
|
101
|
+
- `CoreS3Service.getObject(key, { range: { start, end } })` — the result carries `contentRange` (S3's
|
|
102
|
+
`bytes <start>-<end>/<total>`) and the range's `contentLength`.
|
|
103
|
+
- `parseRangeHeader(header, length)` — the pure parser (`{ start, end }`, `'unsatisfiable'` or `undefined`), for a
|
|
104
|
+
route that decides `If-Range` with a strong validator of its own.
|
|
105
|
+
- A malformed range (`start > end`, negative, not an integer) throws a `RangeError` before any store is asked.
|
|
106
|
+
|
|
107
|
+
## 3. Tests
|
|
108
|
+
|
|
109
|
+
`testHelper.download()` / `downloadBuffer()` take request headers:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const res = await testHelper.download(`/files/id/${id}`, { headers: { Range: 'bytes=0-1' }, token });
|
|
113
|
+
expect(res.statusCode).toBe(206);
|
|
114
|
+
expect(res.headers['content-range']).toBe(`bytes 0-1/${length}`);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 4. No ERROR for downloads the client aborts
|
|
118
|
+
|
|
119
|
+
A client that leaves while an S3 download is still streaming is normal traffic — a video player aborts the running
|
|
120
|
+
range on every seek. Each of them logged `ERROR [CoreFileController] File download failed: aborted` with a stack trace,
|
|
121
|
+
through the framework's download routes and every project route that delivers with `pipeFileToResponse()`.
|
|
122
|
+
`downloadAbortSignal(res)` registers its listeners first, aborts the S3 request when the client goes, and the SDK fails
|
|
123
|
+
the body inside that same dispatch — before `pipeFileToResponse()` saw the client leave.
|
|
124
|
+
|
|
125
|
+
Since 12.6.12 `pipeFileToResponse()` reads a stream error while the client is gone as the end of an aborted download:
|
|
126
|
+
nothing is sent, one debug line is logged. A store error while the client is still connected is an ERROR as before.
|
|
127
|
+
Nothing to change in a project.
|
|
128
|
+
|
|
129
|
+
## 5. Security: NestJS 12.5.0
|
|
130
|
+
|
|
131
|
+
12.6.12 declares NestJS 12.5.0 (`@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express`, `@nestjs/testing` (dev); from 12.3.2) — two NestJS minors. 12.4.0 is fixes only. 12.5.0 adds startup errors for configurations it used to ignore: a guard, interceptor or pipe that cannot run (an abstract class as token, a class given as the `useValue` of `APP_GUARD`) and an invalid `forRoutes()` / `exclude()` entry stop the application at startup — they never took effect, so correct or remove them. It also mounts `forRoutes()` middleware on routes excluded from the global prefix, caps multipart requests at 1000 parts (`limits.parts` raises it), answers a status-less `SyntaxError` / `URIError` from an `app.use()` middleware with 500 instead of 400, fails the consumer of an `@Optional()` dependency that exists but cannot be built, and gives a limit set to `NaN` its default ([release notes](https://github.com/nestjs/nest/releases/tag/v12.5.0)). Boot the application once after the update. `pnpm run update` raises your pins to it.
|
|
132
|
+
NestJS's advisories of 2026-11-12 include two high ones for an application on Express that this release closes:
|
|
133
|
+
|
|
134
|
+
| Advisory | Package | What |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| [GHSA-c8fr-c7pf-58pf](https://github.com/nestjs/nest/security/advisories/GHSA-c8fr-c7pf-58pf) | `@nestjs/platform-express` | Process crash via a multipart request with many fields |
|
|
137
|
+
| [GHSA-jgpx-8x6j-fcpf](https://github.com/nestjs/nest/security/advisories/GHSA-jgpx-8x6j-fcpf) | `@nestjs/common` | Process crash via many files validated at once by `ParseFilePipe` |
|
|
138
|
+
|
|
139
|
+
They were not in GitHub's global advisory database on 2026-11-14, so `pnpm audit` does not report them yet. A project
|
|
140
|
+
that pins `@nestjs/*` itself below 12.5.0 stays affected whatever nest-server version it runs.
|
|
141
|
+
|
|
142
|
+
## 6. Security: one override for `ws`
|
|
143
|
+
|
|
144
|
+
[GHSA-37g9-w4hg-h9qr](https://github.com/websockets/ws/security/advisories/GHSA-37g9-w4hg-h9qr) (high): a client floods
|
|
145
|
+
ping frames without reading the replies, the server buffers the automatic pongs, and the process runs out of memory —
|
|
146
|
+
before any authentication, through the WebSocket every application with GraphQL subscriptions accepts. Patched in `ws`
|
|
147
|
+
8.23.0 (and 7.5.14). The GraphQL WebSocket server runs on `@nestjs/graphql`'s own `ws`, which 14.1.2 exact-pins at
|
|
148
|
+
8.22.0. nest-server's own `overrides:` do not reach your install (`docs/security-overrides.md`), so put the entry into
|
|
149
|
+
your project's `pnpm-workspace.yaml` and run `pnpm install`. A nest-server-starter based project already has a `ws` 8.x
|
|
150
|
+
entry: **replace** it, do not only raise its target — pnpm matches the key against the requested exact version, and a
|
|
151
|
+
key whose upper bound stays below it leaves the vulnerable copy in the tree.
|
|
152
|
+
|
|
153
|
+
```yaml
|
|
154
|
+
overrides:
|
|
155
|
+
# GHSA-37g9-w4hg-h9qr (high): @nestjs/graphql 14.1.2 exact-pins ws 8.22.0. Keep key and target in lockstep
|
|
156
|
+
# with the ws version @lenne.tech/nest-server declares (8.23.0 since 12.6.12). Remove once @nestjs/graphql pins ws >= 8.23.0.
|
|
157
|
+
'ws@>=8.0.0 <8.23.0': '8.23.0'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`pnpm why ws` must then show a single `ws@8.23.0`. Until GitHub's global advisory database lists the
|
|
161
|
+
advisory, `pnpm audit` does not report the vulnerable version. A vendor-mode project adds the same entry.
|
|
162
|
+
|
|
163
|
+
## Troubleshooting
|
|
164
|
+
|
|
165
|
+
| Symptom | Cause | Fix |
|
|
166
|
+
|---|---|---|
|
|
167
|
+
| `ERROR [CoreFileController] File download failed: aborted` with `socketCloseListener` in the stack, one per aborted download | 12.6.10 – 12.6.11 on S3 | Update to 12.6.12 (§4) |
|
|
168
|
+
| `pnpm why ws` lists `ws@8.22.0` under `@nestjs/graphql` | The override from §6 is missing, or an older `ws` 8.x key was kept with only its target raised | Use exactly `'ws@>=8.0.0 <8.23.0': '8.23.0'`, `pnpm install` |
|
|
169
|
+
| A video plays in Chrome but not in Safari (iPhone, macOS) | The route answers `Range` with `200` and the whole file | Framework routes: update. Own route: §2 |
|
|
170
|
+
| `416` with `#LTNS_0503` | The client asked for bytes past the end of the file; `Content-Range: bytes */<length>` names the real size | Usually a player with a cached, outdated length — reload |
|
|
171
|
+
| `RangeError: Invalid byte range` | A `range` with `start > end`, a negative or fractional value reached `getFileStream()` / `getObject()` | Produce it with `resolveDownloadRange()` |
|
|
172
|
+
| `InvalidRange` from S3, or a GridFS stream error `Stream end (…) must not be more than the length of the file` | A `range` past the end of the file reached the store | Resolve it against the file's `length` with `resolveDownloadRange()`, which cuts it at the last byte |
|
|
173
|
+
|
|
174
|
+
## Module Documentation
|
|
175
|
+
|
|
176
|
+
- `docs/security-overrides.md` — the `ws` entry and its lockstep rule
|
|
177
|
+
|
|
178
|
+
- `src/core/modules/file/README.md` — "Byte ranges: video, audio, resumed downloads (12.6.12)"
|
|
179
|
+
- `src/core/modules/file/INTEGRATION-CHECKLIST.md` — Common Mistakes
|
|
180
|
+
- `docs/error-codes.md` — `LTNS_0503`
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Migration Guide: 12.6.12 → 12.6.13
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | None |
|
|
8
|
+
| **New Features** | None. New exports for the fixes below: `processGraphQlUploadRequest`, `GRAPHQL_UPLOAD_MAX_PATH_KEYS`, `GRAPHQL_UPLOAD_MAX_MAP_KEYS`, `isAgentCallContext()`, `resolveAgentCallRequest()` |
|
|
9
|
+
| **Bugfixes** | `HttpExceptionLogFilter` threw on `@nestjs/ai` / `@nestjs/mcp` calls, so the model read "Internal server error" for every refusal (§2) |
|
|
10
|
+
| **Security** | GraphQL multipart uploads (§1): graphql-upload GHSA-5vm7-vc2x-p3w2 (high, one anonymous request crashed the process), GHSA-qwwm-252j-9whw (medium, duplicate file fields leaked temporary files), and an unbounded `map` (one anonymous request with a deep path exhausted the heap, one with many entries blocked the event loop and took hundreds of MB). With `@nestjs/ai` or `@nestjs/mcp` installed, the global guards decided agent function and MCP tool calls on the tool ARGUMENTS (§2) |
|
|
11
|
+
| **Migration Effort** | `pnpm run update`. Projects that register `graphqlUploadExpress()` themselves pass the framework's parser (§1); vendor-mode projects add four dependencies (§3) |
|
|
12
|
+
|
|
13
|
+
## Quick Migration
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @lenne.tech/nest-server@12.6.13
|
|
17
|
+
pnpm run update # nest-server-starter based projects
|
|
18
|
+
grep -rn "graphqlUploadExpress(" src/ # own registrations: pass processGraphQlUploadRequest (§1)
|
|
19
|
+
pnpm run build
|
|
20
|
+
pnpm test
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual, then add the dependencies from §3.
|
|
24
|
+
|
|
25
|
+
## 1. Security: GraphQL multipart uploads
|
|
26
|
+
|
|
27
|
+
**No action needed** unless the project registers `graphqlUploadExpress()` itself (below).
|
|
28
|
+
|
|
29
|
+
`CoreModule` registers graphql-upload's `graphqlUploadExpress()` for `/graphql`, in front of every guard. Up to 12.6.12
|
|
30
|
+
it ran graphql-upload's own `processRequest`, which accepted any object path and any number of entries in the
|
|
31
|
+
multipart `map` field:
|
|
32
|
+
|
|
33
|
+
- **GHSA-5vm7-vc2x-p3w2 (high):** a path into an upload placed by an earlier entry replaced one of its methods. A
|
|
34
|
+
request with `map={"1":["variables.file"],"2":["variables.file.reject"]}` and no file fields made the parser throw
|
|
35
|
+
`TypeError: upload.reject is not a function` outside any request — an uncaught exception, on which the process
|
|
36
|
+
exits (`installProcessDiagnostics()` exits 1, as Node does without it). **One anonymous request took the server
|
|
37
|
+
down.** A path with a `__proto__` key let a client-supplied object pass the `GraphQLUpload` scalar's check.
|
|
38
|
+
- **GHSA-qwwm-252j-9whw (medium):** a second file field with the name of an already resolved upload created another
|
|
39
|
+
temporary file and dropped the reference to the first, which was never deleted — temporary files and file
|
|
40
|
+
descriptors leaked per request.
|
|
41
|
+
- **Unbounded path depth (no advisory; graphql-upload 18.0.2 has the same flaw):** the parser places each upload with
|
|
42
|
+
object-path's `set()`, which recurses once per key and copies the remaining keys each time — O(n²) memory and time
|
|
43
|
+
for a path of n keys, in one synchronous call. Measured on Node 24 with `map={"1":["variables.a.a.a…"]}`: 8,000 keys
|
|
44
|
+
(16 KB) took 310 MB and blocked the event loop for half a second; 40,000 keys (80 KB) exhausted a 1 GB heap and
|
|
45
|
+
ended the process. The default `maxFieldSize` of 1 MB leaves room for 400,000 keys.
|
|
46
|
+
- **Unbounded number of entries (no advisory; graphql-upload 18.0.2 has the same flaw):** every `map` entry becomes an
|
|
47
|
+
upload, and one whose file never arrives is rejected at the end of the request with an error of its own, stack trace
|
|
48
|
+
included. 1 MB of entries without any path (83,000 of them) took 230 MB and blocked the event loop for 410 ms.
|
|
49
|
+
|
|
50
|
+
graphql-upload fixed the two advisories in 18.0.2, which requires graphql 17; this framework runs graphql 16. 12.6.13
|
|
51
|
+
therefore ships `processGraphQlUploadRequest` (`common/helpers/graphql-upload.helper.ts`): graphql-upload 17.1.0's
|
|
52
|
+
parser with both upstream fixes and two bounds of its own, and `CoreModule` passes it to `graphqlUploadExpress()`. It
|
|
53
|
+
answers with 400:
|
|
54
|
+
|
|
55
|
+
- a path into another upload or with a `__proto__` key — "Invalid object path",
|
|
56
|
+
- a path with more than `GRAPHQL_UPLOAD_MAX_PATH_KEYS` (64) keys — "Invalid object path",
|
|
57
|
+
- a `map` with more than `GRAPHQL_UPLOAD_MAX_MAP_KEYS` (10,000) entries and path keys together. Every entry counts one,
|
|
58
|
+
every key of its paths one more, so `{"1":["variables.file"]}` counts 3. The path that goes over the bound is
|
|
59
|
+
answered with "Invalid object path", an entry with "Invalid ‘map’ multipart field entry key …" before its upload is
|
|
60
|
+
created.
|
|
61
|
+
|
|
62
|
+
A duplicate file field is ignored. Each of these requests is now answered within about 40 ms, most of it parsing the
|
|
63
|
+
field's JSON (the 83,000 entries: ~35 ms, +50 MB). A path a client library builds has a handful of keys
|
|
64
|
+
(`variables.file` 2, `variables.input.files.3` 4, batched `0.variables.file` 3); 10,000 is some 2,000 files at
|
|
65
|
+
`variables.input.files.N`. The most expensive request the bounds still accept — 10,000 entries without a path — blocks
|
|
66
|
+
the event loop for about 60 ms with +45 MB. graphql-upload stays at 17.1.0 for its scalar and middleware.
|
|
67
|
+
|
|
68
|
+
**A project that registers `graphqlUploadExpress()` itself** (its own route, its own limits) passes the framework's
|
|
69
|
+
parser — graphql-upload's default is the vulnerable one:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { processGraphQlUploadRequest } from '@lenne.tech/nest-server';
|
|
73
|
+
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
|
74
|
+
|
|
75
|
+
consumer
|
|
76
|
+
.apply(graphqlUploadExpress({ maxFiles: 10, maxFileSize: 10_000_000, processRequest: processGraphQlUploadRequest }))
|
|
77
|
+
.forRoutes('graphql');
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Find such registrations with `grep -rn "graphqlUploadExpress(" src/`. A project that calls graphql-upload's
|
|
81
|
+
`processRequest` directly switches to `processGraphQlUploadRequest` (same signature and options).
|
|
82
|
+
|
|
83
|
+
**Behaviour change:** a GraphQL variable literally named `__proto__` that receives a file is refused with 400 (input
|
|
84
|
+
object fields cannot use that name; names starting with `__` are reserved).
|
|
85
|
+
|
|
86
|
+
## 2. Guards on `@nestjs/ai` and `@nestjs/mcp` calls
|
|
87
|
+
|
|
88
|
+
Only relevant to a project that installs `@nestjs/ai` (`@AgentFunction()`) or `@nestjs/mcp` (`@Tool()`, `@Resource()`,
|
|
89
|
+
`@Prompt()`). Both run every global guard, interceptor and filter of the application around their methods, with the
|
|
90
|
+
context types `'ai'` / `'mcp'` and the arguments `[input, call]`. Index 0 is what the model or the MCP client wrote.
|
|
91
|
+
Up to 12.6.12 the framework's guards fell back to `switchToHttp().getRequest()` there — index 0. Tool arguments
|
|
92
|
+
`{ "user": { "roles": ["admin"] } }` were the caller a guard decided on.
|
|
93
|
+
|
|
94
|
+
Since 12.6.13 the framework resolves the request of such a call from the call object (`caller.request`,
|
|
95
|
+
`McpContext.request`):
|
|
96
|
+
|
|
97
|
+
- `@Roles()` on an agent function or MCP tool is decided against the request's user exactly as over HTTP, tenant
|
|
98
|
+
header included — in `RolesGuard`, `BetterAuthRolesGuard`, `CoreTenantGuard`, the auth guard and the legacy
|
|
99
|
+
rate-limit guard.
|
|
100
|
+
- A **request-less** caller — `caller: { user, scopes }` (a queue job), a durable run, MCP over stdio — is
|
|
101
|
+
**anonymous**: public methods run, every other one is refused with 401. To run a role-gated agent function from a job,
|
|
102
|
+
authenticate there and pass a request (`caller: { request }`).
|
|
103
|
+
- `@CurrentUser()` / `@RESTUser()` and the response interceptors (`@Restricted`, secret fields) use the request's user.
|
|
104
|
+
- `HttpExceptionLogFilter` hands the exception back to the package instead of writing an HTTP response, so the model
|
|
105
|
+
or MCP client reads the refusal's message instead of "Internal server error".
|
|
106
|
+
|
|
107
|
+
**Not in 12.6.13** — these parts of the 12.10.x work stay on the 12.10 line: the `MCP_VERIFIED_USER` token,
|
|
108
|
+
`CoreAiMcpOAuthService.createMcpTokenVerifier()` for a `@nestjs/mcp` endpoint, the AI SDK transport
|
|
109
|
+
(`providerType: 'nestjs-ai'`), agent functions as AI tools, and the removal of secret fields from AI tool results.
|
|
110
|
+
Update to 12.10.x for them.
|
|
111
|
+
|
|
112
|
+
**A guard of your own** that reads the request with `switchToHttp().getRequest()` (or `GqlExecutionContext`'s `req`
|
|
113
|
+
with that fallback) has the same flaw on these calls. Resolve the request through the framework:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { resolveGuardRequest } from '@lenne.tech/nest-server';
|
|
117
|
+
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
118
|
+
|
|
119
|
+
canActivate(context: ExecutionContext): boolean {
|
|
120
|
+
// undefined for a request-less agent / MCP call: treat it as anonymous
|
|
121
|
+
const request = resolveGuardRequest(context, (ctx) => GqlExecutionContext.create(ctx).getContext());
|
|
122
|
+
// …
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Nothing to do otherwise, unless the project relied on the old behaviour.
|
|
127
|
+
|
|
128
|
+
## 3. Dependencies
|
|
129
|
+
|
|
130
|
+
New direct `dependencies` for the multipart parser (§1): `busboy` 1.6.0, `fs-capacitor` 8.0.0, `http-errors` 2.0.1 and
|
|
131
|
+
`object-path` 0.11.8 — the versions graphql-upload 17.1.0 already installs, so an npm-mode project gets no new package.
|
|
132
|
+
|
|
133
|
+
A **vendor-mode** project declares them in `dependencies`: the core imports them directly, and a pnpm project does not
|
|
134
|
+
see graphql-upload's own copies. A project that compiles with `noImplicitAny` (part of `strict`) also adds
|
|
135
|
+
`@types/busboy` 1.5.5, `@types/http-errors` 2.0.5 and `@types/object-path` 0.11.4 to `devDependencies`.
|
|
136
|
+
|
|
137
|
+
## Compatibility Notes
|
|
138
|
+
|
|
139
|
+
| Pattern | Status |
|
|
140
|
+
|---|---|
|
|
141
|
+
| Uploads through `CoreModule`'s `/graphql` registration | Protected with the update |
|
|
142
|
+
| `graphqlUploadExpress()` registered by the project | Pass `processRequest: processGraphQlUploadRequest` (§1) |
|
|
143
|
+
| Vendor mode, GraphQL uploads | Add the four dependencies (and the `@types/*` under `noImplicitAny`) from §3 |
|
|
144
|
+
| Projects without `@nestjs/ai` / `@nestjs/mcp` | Unchanged — the guards take the new branch only for the context types `'ai'` / `'mcp'` |
|
|
145
|
+
| A guard of the project's own on agent / MCP calls | Resolve the request with `resolveGuardRequest()` (§2) |
|
|
146
|
+
|
|
147
|
+
## Troubleshooting
|
|
148
|
+
|
|
149
|
+
| Symptom | Cause | Fix |
|
|
150
|
+
|---|---|---|
|
|
151
|
+
| Vendor mode: `Cannot find package 'busboy'` (or `fs-capacitor`, `http-errors`, `object-path`) at start | The core imports them since 12.6.13 | Add them to `dependencies` (§3) |
|
|
152
|
+
| Vendor mode: `TS7016: Could not find a declaration file for module 'busboy'` (or `http-errors`, `object-path`) | `noImplicitAny` without the type packages | Add the `@types/*` packages from §3 |
|
|
153
|
+
| A file upload answers 400 `Invalid object path for the ‘map’ multipart field …` | The `map` names a path into another upload, with a `__proto__` key or with more than 64 keys | Send each file at its own flat variable path (`variables.files.0`, `variables.input.files.3`) |
|
|
154
|
+
| An upload of very many files answers 400 `Invalid object path …` or `Invalid ‘map’ multipart field entry key …` | The `map` has more than 10,000 entries and path keys together | Split the upload into several requests |
|
|
155
|
+
| A role-gated agent function answers 401 from a queue job | Request-less callers are anonymous | Authenticate in the job and pass `caller: { request }` |
|
|
156
|
+
|
|
157
|
+
## Module Documentation
|
|
158
|
+
|
|
159
|
+
- `docs/REQUEST-LIFECYCLE.md` — "3. graphqlUploadExpress" and the guard table row for `ai` / `mcp`
|
|
160
|
+
- `src/core/common/helpers/graphql-upload.helper.ts` — the parser, its fixes and bounds
|
|
161
|
+
- `src/core/common/helpers/execution-context-request.helper.ts` — `resolveGuardRequest()`, `resolveAgentCallRequest()`
|
|
162
|
+
- `.claude/rules/role-system.md` — "Agent function and MCP calls"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "12.6.
|
|
3
|
+
"version": "12.6.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Server framework in TypeScript on top of NestJS: GraphQL and REST APIs on MongoDB, PostgreSQL, MySQL or MariaDB, with authentication, field-level permissions, multi-tenancy, offline sync and an AI assistant.",
|
|
6
6
|
"keywords": [
|
|
@@ -106,12 +106,12 @@
|
|
|
106
106
|
"@getbrevo/brevo": "6.2.0",
|
|
107
107
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
108
108
|
"@nestjs/apollo": "14.1.2",
|
|
109
|
-
"@nestjs/common": "12.
|
|
110
|
-
"@nestjs/core": "12.
|
|
109
|
+
"@nestjs/common": "12.5.0",
|
|
110
|
+
"@nestjs/core": "12.5.0",
|
|
111
111
|
"@nestjs/graphql": "14.1.2",
|
|
112
112
|
"@nestjs/jwt": "12.0.3",
|
|
113
113
|
"@nestjs/passport": "12.0.0",
|
|
114
|
-
"@nestjs/platform-express": "12.
|
|
114
|
+
"@nestjs/platform-express": "12.5.0",
|
|
115
115
|
"@nestjs/schedule": "12.0.2",
|
|
116
116
|
"@nestjs/swagger": "12.1.0",
|
|
117
117
|
"@nestjs/terminus": "12.1.0",
|
|
@@ -119,6 +119,7 @@
|
|
|
119
119
|
"@tus/server": "2.4.7",
|
|
120
120
|
"@types/supertest": "7.2.1",
|
|
121
121
|
"bcrypt": "6.0.0",
|
|
122
|
+
"busboy": "1.6.0",
|
|
122
123
|
"class-transformer": "0.5.1",
|
|
123
124
|
"class-validator": "0.15.1",
|
|
124
125
|
"compression": "1.8.2",
|
|
@@ -127,11 +128,13 @@
|
|
|
127
128
|
"dotenv": "18.0.9",
|
|
128
129
|
"ejs": "7.0.2",
|
|
129
130
|
"express": "5.3.0",
|
|
131
|
+
"fs-capacitor": "8.0.0",
|
|
130
132
|
"graphql": "16.14.2",
|
|
131
133
|
"graphql-query-complexity": "2.0.0",
|
|
132
134
|
"graphql-subscriptions": "3.0.0",
|
|
133
135
|
"graphql-upload": "17.1.0",
|
|
134
136
|
"graphql-ws": "6.3.0",
|
|
137
|
+
"http-errors": "2.0.1",
|
|
135
138
|
"jose": "6.2.15",
|
|
136
139
|
"js-sha256": "1.0.0",
|
|
137
140
|
"json-to-graphql-query": "2.3.0",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"multer": "2.5.0",
|
|
140
143
|
"node-mailjet": "6.0.11",
|
|
141
144
|
"nodemailer": "10.4.1",
|
|
145
|
+
"object-path": "0.11.8",
|
|
142
146
|
"passport": "0.7.0",
|
|
143
147
|
"passport-jwt": "4.0.1",
|
|
144
148
|
"reflect-metadata": "0.2.2",
|
|
@@ -147,7 +151,7 @@
|
|
|
147
151
|
"supertest": "7.3.1",
|
|
148
152
|
"ts-morph": "28.0.0",
|
|
149
153
|
"undici": "7.30.2",
|
|
150
|
-
"ws": "8.
|
|
154
|
+
"ws": "8.23.0",
|
|
151
155
|
"yuml-diagram": "1.2.0"
|
|
152
156
|
},
|
|
153
157
|
"peerDependencies": {
|
|
@@ -236,17 +240,20 @@
|
|
|
236
240
|
"@nestjs/cli": "12.0.11",
|
|
237
241
|
"@nestjs/mongoose": "12.0.0",
|
|
238
242
|
"@nestjs/schematics": "12.0.12",
|
|
239
|
-
"@nestjs/testing": "12.
|
|
243
|
+
"@nestjs/testing": "12.5.0",
|
|
240
244
|
"@swc/cli": "0.8.2",
|
|
241
245
|
"@swc/core": "1.16.21",
|
|
242
246
|
"@tus/s3-store": "2.1.0",
|
|
247
|
+
"@types/busboy": "1.5.5",
|
|
243
248
|
"@types/compression": "1.8.1",
|
|
244
249
|
"@types/cookie-parser": "1.4.10",
|
|
245
250
|
"@types/ejs": "3.1.5",
|
|
246
251
|
"@types/express": "5.0.6",
|
|
252
|
+
"@types/http-errors": "2.0.5",
|
|
247
253
|
"@types/lodash": "4.17.27",
|
|
248
254
|
"@types/multer": "2.3.0",
|
|
249
255
|
"@types/node": "26.6.6",
|
|
256
|
+
"@types/object-path": "0.11.4",
|
|
250
257
|
"@types/passport": "1.0.17",
|
|
251
258
|
"@types/pg": "8.23.1",
|
|
252
259
|
"@vitest/coverage-v8": "5.1.0",
|
|
@@ -266,14 +273,14 @@
|
|
|
266
273
|
"oxlint-tsgolint": "7.0.2005",
|
|
267
274
|
"pg": "8.23.1",
|
|
268
275
|
"playwright-core": "1.64.1",
|
|
269
|
-
"rimraf": "6.1.
|
|
276
|
+
"rimraf": "6.1.4",
|
|
270
277
|
"smtp-server": "3.21.3",
|
|
271
278
|
"tsx": "4.23.15",
|
|
272
279
|
"tus-js-client": "4.3.1",
|
|
273
280
|
"typeorm": "1.1.2",
|
|
274
281
|
"typescript": "6.0.3",
|
|
275
282
|
"unplugin-swc": "2.0.0",
|
|
276
|
-
"vite": "8.3.
|
|
283
|
+
"vite": "8.3.8",
|
|
277
284
|
"vitest": "5.1.0"
|
|
278
285
|
},
|
|
279
286
|
"main": "dist/index.js",
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
2
2
|
|
|
3
|
+
import { isAgentCallContext, resolveAgentCallRequest } from '../helpers/execution-context-request.helper.js';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* User decorator for REST request
|
|
5
7
|
*/
|
|
6
8
|
export const RESTUser = createParamDecorator((data: unknown, ctx: ExecutionContext) => {
|
|
9
|
+
// An agent function / MCP call: the request's user, never one in the call's arguments (nestjs-ai plan §1)
|
|
10
|
+
if (isAgentCallContext(ctx)) {
|
|
11
|
+
return resolveAgentCallRequest(ctx)?.user;
|
|
12
|
+
}
|
|
7
13
|
const request = ctx.switchToHttp().getRequest();
|
|
8
14
|
return request.user;
|
|
9
15
|
});
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@nestjs/common';
|
|
9
9
|
import { GqlContextType } from '@nestjs/graphql';
|
|
10
10
|
import { Response } from 'express';
|
|
11
|
+
import { isAgentCallContext } from '../helpers/execution-context-request.helper.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Nest's logger rather than `console.debug` (12.0.0): the stack carries the filter as its context, honours the
|
|
@@ -31,6 +32,14 @@ export class HttpExceptionLogFilter implements ExceptionFilter {
|
|
|
31
32
|
return exception;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
// An agent function call (`@nestjs/ai`, `'ai'`) or an MCP call (`@nestjs/mcp`, `'mcp'`): the second argument is
|
|
36
|
+
// the CALL, not a response (nestjs-ai plan §1). Returning nothing hands the exception back to the package, which
|
|
37
|
+
// tells the model or MCP client its message. Writing to `switchToHttp()` there threw a TypeError instead, and the
|
|
38
|
+
// model read "Internal server error" for every 401 / 403 / 404. Every other transport is unchanged.
|
|
39
|
+
if (isAgentCallContext(host)) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
34
43
|
// REST
|
|
35
44
|
const ctx = host.switchToHttp();
|
|
36
45
|
const res = ctx.getResponse<Response>();
|