@lenne.tech/nest-server 11.46.4 → 11.46.6
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 +4 -3
- package/.claude/rules/testing.md +4 -4
- package/FRAMEWORK-API.md +1 -1
- package/dist/core/common/helpers/byte-range.helper.d.ts +8 -0
- package/dist/core/common/helpers/byte-range.helper.js +76 -0
- package/dist/core/common/helpers/byte-range.helper.js.map +1 -0
- package/dist/core/common/helpers/graphql-upload.helper.d.ts +10 -0
- package/dist/core/common/helpers/graphql-upload.helper.js +240 -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/plugins/complexity.plugin.js +71 -7
- package/dist/core/common/plugins/complexity.plugin.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/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 +67 -3
- 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/hub/helpers/hub-mask.helper.js +5 -1
- package/dist/core/modules/hub/helpers/hub-mask.helper.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/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/graphql-upload.d.ts +35 -1
- package/docs/REQUEST-LIFECYCLE.md +27 -4
- package/docs/error-codes.md +14 -0
- package/docs/security-overrides.md +21 -6
- package/migration-guides/11.46.4-to-11.46.5.md +183 -0
- package/migration-guides/11.46.5-to-11.46.6.md +203 -0
- package/package.json +14 -7
- package/src/core/common/helpers/byte-range.helper.ts +144 -0
- package/src/core/common/helpers/graphql-upload.helper.ts +522 -0
- package/src/core/common/helpers/gridfs.helper.ts +20 -6
- package/src/core/common/plugins/complexity.plugin.ts +150 -9
- package/src/core/common/services/core-s3.service.ts +16 -2
- 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/hub/helpers/hub-mask.helper.ts +16 -3
- package/src/core/modules/system-setup/INTEGRATION-CHECKLIST.md +8 -8
- package/src/core/modules/system-setup/README.md +6 -6
- 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 +35 -1
|
@@ -5,17 +5,51 @@
|
|
|
5
5
|
|
|
6
6
|
declare module 'graphql-upload/graphqlUploadExpress.js' {
|
|
7
7
|
import { RequestHandler } from 'express';
|
|
8
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
8
9
|
|
|
9
|
-
interface
|
|
10
|
+
interface GraphQLUploadProcessRequestOptions {
|
|
11
|
+
maxFieldSize?: number;
|
|
10
12
|
maxFiles?: number;
|
|
11
13
|
maxFileSize?: number;
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
interface GraphQLUploadOptions extends GraphQLUploadProcessRequestOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The function that parses the multipart request. graphql-upload's default is its own `processRequest`, which is
|
|
19
|
+
* vulnerable to GHSA-5vm7-vc2x-p3w2 and GHSA-qwwm-252j-9whw below 18.0.2 — pass the framework's
|
|
20
|
+
* `processGraphQlUploadRequest`.
|
|
21
|
+
*/
|
|
22
|
+
processRequest?: (
|
|
23
|
+
request: IncomingMessage,
|
|
24
|
+
response: ServerResponse,
|
|
25
|
+
options?: GraphQLUploadProcessRequestOptions,
|
|
26
|
+
) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
function graphqlUploadExpress(options?: GraphQLUploadOptions): RequestHandler;
|
|
15
30
|
|
|
16
31
|
export = graphqlUploadExpress;
|
|
17
32
|
}
|
|
18
33
|
|
|
34
|
+
declare module 'graphql-upload/Upload.js' {
|
|
35
|
+
/**
|
|
36
|
+
* A file expected in a GraphQL multipart request, placed in the operations wherever the `map` names it. The
|
|
37
|
+
* `GraphQLUpload` scalar accepts a value only if it is `instanceof` this class, of the same graphql-upload copy.
|
|
38
|
+
*/
|
|
39
|
+
class Upload {
|
|
40
|
+
/** The file's details once it streamed in (set by `resolve`). */
|
|
41
|
+
file?: unknown;
|
|
42
|
+
/** Resolves with the file's details; the scalar hands it to the resolver. */
|
|
43
|
+
promise: Promise<unknown>;
|
|
44
|
+
/** Rejects the upload (missing file, aborted request). */
|
|
45
|
+
reject: (error: Error) => void;
|
|
46
|
+
/** Resolves the upload with the file's details. */
|
|
47
|
+
resolve: (file: unknown) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export = Upload;
|
|
51
|
+
}
|
|
52
|
+
|
|
19
53
|
declare module 'graphql-upload/GraphQLUpload.js' {
|
|
20
54
|
import { GraphQLScalarType } from 'graphql';
|
|
21
55
|
|
|
@@ -168,7 +168,7 @@ JWT-based authentication for existing projects:
|
|
|
168
168
|
| Feature | Description |
|
|
169
169
|
|---------|-------------|
|
|
170
170
|
| **File Module** | Upload/download with MongoDB GridFS storage |
|
|
171
|
-
| **REST Endpoints** | `GET /files/id/:id`, `GET /files/:filename` (core, gated by `file.downloadRoles`, default ADMIN); `POST /files/upload`, `DELETE /files/:id` (project-specific). Since 11.46.3 the download routes answer after the rights check: weak `ETag` + `If-None-Match` → `304` without a store read, `Cache-Control` per `file.downloadCaching`, `Content-Length`; the store request carries an abort signal (`downloadAbortSignal()`) and is opened through `openDownloadStream()` (exported since 11.46.4: a gone client is `RESPONSE_GONE`, never an error), delivery goes through `pipeFileToResponse()` (releases the source when the client goes), every stream is idle-guarded (`file.downloadIdleTimeoutMs`), and a store that gives no connection in time answers `503` + `Retry-After` |
|
|
171
|
+
| **REST Endpoints** | `GET /files/id/:id`, `GET /files/:filename` (core, gated by `file.downloadRoles`, default ADMIN); `POST /files/upload`, `DELETE /files/:id` (project-specific). Since 11.46.3 the download routes answer after the rights check: weak `ETag` + `If-None-Match` → `304` without a store read, `Cache-Control` per `file.downloadCaching`, `Content-Length`; the store request carries an abort signal (`downloadAbortSignal()`) and is opened through `openDownloadStream()` (exported since 11.46.4: a gone client is `RESPONSE_GONE`, never an error), delivery goes through `pipeFileToResponse()` (releases the source when the client goes), every stream is idle-guarded (`file.downloadIdleTimeoutMs`), and a store that gives no connection in time answers `503` + `Retry-After`. Since 11.46.5 a `Range` request is answered from every store with `206` + `Content-Range` (one range; `416` + `Content-Range: bytes */<length>` past the end; several ranges or `If-Range` get the whole file), through `resolveDownloadRange()` → `getFileStream(id, { range })` → `setDownloadRangeHeaders()`, which a project's own route uses the same way |
|
|
172
172
|
| **GraphQL Endpoints** | `getFileInfo` (`file.downloadRoles`), `uploadFile` / `uploadFiles` (`file.uploadRoles`), `deleteFile` (`file.deleteRoles`) — all default ADMIN |
|
|
173
173
|
| **File access control** | Roles are the coarse filter; per-file rules go in `CoreFileService.checkRights()` using metadata written at upload time. Cover BOTH the `id` and the `filename` branch — the filename route authorizes on the by-name lookup alone when presigned S3 downloads are on, and `deleteFileByName()` always does. Working reference: `src/server/modules/file/file.service.ts` (with `file.downloadRoles: [S_USER]` in `src/config.env.ts`, so the rule is actually reached). Both file classes carry `@SkipTenantCheck()` — GridFS is not tenant-scoped |
|
|
174
174
|
| **TUS Module** | Resumable uploads via tus.io protocol (creation, termination, expiration), gated by `tus.roles` (default `S_USER`); `OPTIONS` stays public for the CORS preflight. Records owner and, with `multiTenancy` only, the validated tenant at upload creation; a custom service plugs in via `TusModule.forRoot({ service })`. Configured by `TusModule.forRoot({ config })`, else the server config's `tus` key (11.42.9+). Switched-off `creation` / `termination` answer 501 (enforced by `CoreTusService`, not `@tus/server`); upload URLs follow the path the upload was created at. The response that completes an upload carries the stored file's ID as `X-File-Id` (11.42.13+, listed in `Access-Control-Expose-Headers`) — the last segment of the TUS URL is the upload id, not the file id |
|
|
@@ -215,9 +215,9 @@ JWT-based authentication for existing projects:
|
|
|
215
215
|
| **Subscriptions** | WebSocket support via `graphql-ws` with auth. The `PUB_SUB` provider is built from a factory: `CoreRedisPubSub` when `redis` is configured (delivery is then cluster-wide), the in-memory `PubSub` otherwise (delivery only to clients connected to the publishing replica). **Constraint once Redis is in play: every published payload must be JSON-serializable** — it crosses the wire as JSON, so `Date`, class instances, `Map`/`Set` and `undefined` do not survive the round trip. An in-process `PubSub` never had this constraint, so a payload that worked on one replica can silently lose fields on a cluster. Publish plain objects and ISO strings |
|
|
216
216
|
| **Subscription request context** | Since 11.35.0 `CoreModule` installs a context-aware `execute` / `subscribe` pair (inside `subscriptions`, where `ApolloDriver` forwards it) on all three GraphQL driver builders, so every WebSocket operation runs inside a `RequestContext`. Before that a WS operation had **none** — no Express middleware runs on an upgrade, and `CoreTenantGuard.getRequest()` finds no `req` on a subscription context — and `mongooseTenantPlugin` reads "no context" as "system operation, no filter", so a tenant-scoped read while delivering a subscription message returned EVERY tenant's rows. The tenant comes from the handshake's tenant header **validated against an active membership**, else from the subscriber's memberships; an unresolvable tenant leaves the safety net to refuse the read. The async iterator is wrapped too, not only the subscribe call: graphql-js runs `resolve` / `filter` / field resolvers inside its `next()`. See `.claude/rules/role-system.md` → "Tenant context on non-HTTP transports" |
|
|
217
217
|
| **Subscription re-check** | Since 11.42.3 that context is not trusted for the life of the socket. Every connection a `CoreModule` `onConnect` accepts is registered (`registerWsConnection()`) and checked again — at once on an invalidation (tenant guard, role change, password reset, Better-Auth deleting the session), otherwise before the next operation or event once `graphQl.subscriptionRevalidationMs` (30 s) has passed. The check re-runs the handshake's authentication and the tenant resolution; a connection whose rights changed is closed with 4403 (retried by the graphql-ws client, which then reconnects with its current rights) and the event that triggered the check is dropped. Before, a removed membership, a deactivated tenant, a withdrawn role or a revoked session kept receiving events on an open socket until the client reconnected. See `.claude/rules/role-system.md` → "Open WebSockets" |
|
|
218
|
-
| **Complexity Analysis** | Query cost calculation to prevent DoS attacks |
|
|
218
|
+
| **Complexity Analysis** | Query cost calculation to prevent DoS attacks. Since 11.46.6 `ComplexityPlugin` analyses only the operation Apollo resolved (none resolved: left to execution, which refuses it before coercing a variable), first checks whether its variables coerce (stopping at the first error) and leaves invalid ones to execution, which refuses them with graphql's cap (50), refuses an operation whose fields × declared variables exceed 250,000, computes graphql-query-complexity's number with each fragment evaluated once, and stops at its first error. Before, a document of many operations, a list of invalid items, a fragment spread thousands of times, tens of thousands of variables or thousands of failing arguments each blocked the event loop for seconds from one anonymous request |
|
|
219
219
|
| **Enum Registration** | `registerEnum()` helper for GraphQL enum types |
|
|
220
|
-
| **Upload Support** | `graphqlUploadExpress()` for multipart file uploads |
|
|
220
|
+
| **Upload Support** | `graphqlUploadExpress()` for multipart file uploads, with the framework's `processGraphQlUploadRequest` (graphql-upload's parser with the GHSA-5vm7-vc2x-p3w2 and GHSA-qwwm-252j-9whw fixes; `map` bounded to 64 keys per path and 10,000 entries, path keys and array elements together) |
|
|
221
221
|
|
|
222
222
|
### Development & Operations
|
|
223
223
|
|
|
@@ -367,6 +367,8 @@ The following diagram shows the exact order of execution from HTTP request to re
|
|
|
367
367
|
| |
|
|
368
368
|
| 3. graphqlUploadExpress() [GraphQL only] |
|
|
369
369
|
| - Handles multipart file uploads |
|
|
370
|
+
| - processGraphQlUploadRequest: bad map path -> 400 |
|
|
371
|
+
| - map: 64 keys/path, 10,000 units in total |
|
|
370
372
|
+----------------------------+----------------------------+
|
|
371
373
|
|
|
|
372
374
|
+----------------------------v----------------------------+
|
|
@@ -597,7 +599,7 @@ configure(consumer: MiddlewareConsumer) {
|
|
|
597
599
|
consumer.apply(RequestContextMiddleware).forRoutes('*');
|
|
598
600
|
consumer.apply(StringCookiesMiddleware).forRoutes('*');
|
|
599
601
|
consumer.apply(SecurityHeadersMiddleware).forRoutes('*');
|
|
600
|
-
consumer.apply(graphqlUploadExpress()).forRoutes('graphql');
|
|
602
|
+
consumer.apply(graphqlUploadExpress({ processRequest: processGraphQlUploadRequest })).forRoutes('graphql');
|
|
601
603
|
}
|
|
602
604
|
```
|
|
603
605
|
|
|
@@ -742,6 +744,27 @@ session cookie riding along can never turn a token request into a session reques
|
|
|
742
744
|
|
|
743
745
|
Only for GraphQL routes. Handles multipart file upload requests according to the [GraphQL multipart request specification](https://github.com/jaydenseric/graphql-multipart-request-spec).
|
|
744
746
|
|
|
747
|
+
It runs before every guard, so whatever it parses comes from an anonymous client. `CoreModule` passes
|
|
748
|
+
the framework's `processGraphQlUploadRequest` (`common/helpers/graphql-upload.helper.ts`) instead of graphql-upload's
|
|
749
|
+
own `processRequest`: graphql-upload 15.0.2's parser with both hunks of the fix in graphql-upload 18.0.2 (an ESM-only
|
|
750
|
+
release that needs graphql 17). A `map` path with a `__proto__` key, or one that goes through an already placed
|
|
751
|
+
upload, is answered with 400 "Invalid object path" (GHSA-5vm7-vc2x-p3w2 — before,
|
|
752
|
+
`{"1":["variables.file"],"2":["variables.file.reject"]}` without file fields made the parser throw an uncaught
|
|
753
|
+
`TypeError` and the process exit), and a second file field with the name of an already resolved upload is ignored
|
|
754
|
+
(GHSA-qwwm-252j-9whw — before, its temporary file leaked). A project that registers `graphqlUploadExpress()` itself
|
|
755
|
+
passes `{ processRequest: processGraphQlUploadRequest }` too.
|
|
756
|
+
|
|
757
|
+
It also bounds the `map`: at most `GRAPHQL_UPLOAD_MAX_PATH_KEYS` (64) keys per path, and at most
|
|
758
|
+
`GRAPHQL_UPLOAD_MAX_MAP_KEYS` (10,000) units in the whole `map` — one per entry, one per path key and one per array
|
|
759
|
+
element a numeric path key creates, holes included. A path over a bound is answered with 400 "Invalid object path",
|
|
760
|
+
an entry over the map bound with 400 "Invalid ‘map’ multipart field entry key …" before its upload is created. The
|
|
761
|
+
parser places each upload with object-path's `set()`, which costs O(n²) for a path of n keys and reads a key like
|
|
762
|
+
`4294967294` as a number, setting that index of an array it creates; and it creates an upload per entry that it rejects
|
|
763
|
+
with an error of its own when the file never arrives. Before, one anonymous request with an 80 KB path exhausted a
|
|
764
|
+
1 GB heap and ended the process, 1 MB of paths just under a per-path bound blocked the event loop for up to 640 ms,
|
|
765
|
+
1 MB of entries without a path for 410 ms with 230 MB, and the 258-byte `variables.f.4294967294` handed GraphQL an
|
|
766
|
+
array of 2^32 − 1 elements whose coercion exhausted a 1 GB heap. graphql-upload 15.0.2 and 18.0.2 have the same flaws.
|
|
767
|
+
|
|
745
768
|
> **NestJS docs:** [Middleware](https://docs.nestjs.com/middleware)
|
|
746
769
|
|
|
747
770
|
---
|
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 11.46.5.
|
|
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) | `@nestjs/graphql` 13.4.5 — the version this framework declares, and the newest 13.x — declares `"@graphql-tools/utils": "12.0.0"`, an **exact pin**. Only `@nestjs/graphql` 14.x moves it, so **this entry is load-bearing**. `@apollo/server` reaches it 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.0.3`, which needs Node >=22.15 — the framework's own floor since 11.42.10, which is why the snippet below targets 12.0.3 |
|
|
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.4.0, patched `>=2.5.0` (published 2026-10-23) | `@nestjs/platform-express` up to 11.2.5 declares `"multer": "2.2.0"` — an **exact pin**. A direct `multer` dependency does not move it: you get both copies, and FileInterceptor uses the vulnerable one. 11.2.6 to 11.2.8, the newest 11.x, pin `2.4.0`, which GHSA-q7qp-rjg7-q26m covers. No 11.x update reaches the fix, so **this entry is load-bearing again since 11.43.4** |
|
|
23
23
|
|
|
24
|
+
**Status since 11.46.5** (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` 13.4.5 (newest 13.x) exact-pins `8.21.3`, and the GraphQL WebSocket server
|
|
28
|
+
runs on that copy, so the `ws` dependency nest-server declares (`8.23.0` since 11.46.5) 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` and `@nestjs/platform-express` 11.2.10 (declared since 11.46.5) 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 11.42.4:** `@graphql-tools/utils` joins `js-yaml` as load-bearing — no `@nestjs/graphql`
|
|
25
36
|
13.x resolves past the exact pin. The 11.42.4 release also covers `proxy-addr` (GHSA-jqcg-44mw-7w3h,
|
|
26
37
|
critical: IP spoofing through an IPv4-mapped IPv6 address in a trusted subnet — it is what
|
|
@@ -46,11 +57,13 @@ Add this to your project's `pnpm-workspace.yaml` (pnpm 11+; in pnpm 10 and earli
|
|
|
46
57
|
|
|
47
58
|
```yaml
|
|
48
59
|
overrides:
|
|
49
|
-
# @nestjs/graphql exact-pins ws
|
|
60
|
+
# @nestjs/graphql 13 exact-pins ws (13.4.5: 8.21.3) — GHSA-37g9-w4hg-h9qr (high, patched 8.23.0 / 7.5.14).
|
|
50
61
|
# An exact pin cannot resolve forward — the override is the only fix.
|
|
51
|
-
# Keep the target in LOCKSTEP with
|
|
52
|
-
# Remove once @nestjs/graphql stops pinning it.
|
|
53
|
-
'ws@>=8.0.0 <8.
|
|
62
|
+
# Keep the target in LOCKSTEP with the ws version @lenne.tech/nest-server declares (8.23.0 since 11.46.5);
|
|
63
|
+
# key and target move together (see the note below). Remove once @nestjs/graphql stops pinning it.
|
|
64
|
+
'ws@>=8.0.0 <8.23.0': '8.23.0'
|
|
65
|
+
# The 7.x copy comes from @nestjs/graphql 13 > subscriptions-transport-ws.
|
|
66
|
+
'ws@>=7.0.0 <7.5.14': '7.5.14'
|
|
54
67
|
|
|
55
68
|
# @nestjs/swagger exact-pins js-yaml (11.4.7: 5.3.0) — GHSA-r3ph-w7gj-g6xm (moderate, patched >=5.4.1)
|
|
56
69
|
# and, for older swagger releases, GHSA-pm4m-ph32-ghv5 (high, patched >=5.2.2).
|
|
@@ -105,7 +118,7 @@ tree to `2.0.11` even though nothing needed help any more.
|
|
|
105
118
|
|
|
106
119
|
### The `ws` target must stay in lockstep with the declared `ws` version
|
|
107
120
|
|
|
108
|
-
`8.21.3` is not an arbitrary "latest patch" — it is the version `@lenne.tech/nest-server` declares as
|
|
121
|
+
`8.23.0` (since 11.46.5; `8.21.3` before) is not an arbitrary "latest patch" — it is the version `@lenne.tech/nest-server` declares as
|
|
109
122
|
an ordinary **dependency**, so it is already in your tree whether or not you list `ws` yourself.
|
|
110
123
|
The override target has to equal it.
|
|
111
124
|
|
|
@@ -117,7 +130,9 @@ when you read a manifest. The target was raised `8.21.1` → `8.21.3` on 2026-08
|
|
|
117
130
|
reason.
|
|
118
131
|
|
|
119
132
|
**Rule:** whenever the `ws` version declared by `@lenne.tech/nest-server` (or by your own
|
|
120
|
-
`package.json`, if you list it) moves, move this override target with it in the
|
|
133
|
+
`package.json`, if you list it) moves, move this override's target **and the upper bound of its key** with it in the
|
|
134
|
+
same commit — pnpm matches the key against the requested range, so a key that stays below an exact pin no longer
|
|
135
|
+
reaches it. The
|
|
121
136
|
same applies to any other override whose package also appears as a declared dependency.
|
|
122
137
|
|
|
123
138
|
Then:
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Migration Guide: 11.46.4 → 11.46.5
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | None in nest-server. NestJS 11.2.10, which `pnpm run update` installs, adds startup errors for configurations 11.2.7 ignored (§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 11.2.10 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@11.46.5
|
|
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 11.46.4 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 11.46.5 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 11.46.5 `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 11.2.10
|
|
130
|
+
|
|
131
|
+
11.46.5 declares NestJS 11.2.10 (`@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express`, `@nestjs/testing` (dev); from 11.2.7) — three patch releases of the 11.2 line (11.2.8 – 11.2.10). Besides the two advisories below they bring behaviour a REST / GraphQL application on Express can meet: a global guard, interceptor or pipe that cannot run (a class given as the `useValue` of `APP_GUARD`, one without `canActivate` / `intercept` / `transform`, or a class enhancer whose dependencies are request-scoped) and an invalid `forRoutes()` / `exclude()` entry now stop the application at startup — 11.2.7 dropped them silently, so they never took effect: correct or remove them. Middleware given to `forRoutes()` is also mounted on routes excluded from the global prefix, and multipart requests are capped at 1000 parts by default (`limits.parts` raises it). 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 11.2.10 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 13.4.5 exact-pins at
|
|
148
|
+
8.21.3. 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 two `ws`
|
|
150
|
+
entries, `'ws@>=8.0.0 <8.21.3': 8.21.3` and `'ws@>=7.0.0 <7.5.13': 7.5.13`: **replace both** with the two below. Do not
|
|
151
|
+
only raise their targets — pnpm matches the key against the requested exact version, and a key whose upper bound stays
|
|
152
|
+
below it leaves the vulnerable copy in the tree. 7.5.13 is itself covered by the advisory (patched 7.5.14).
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
overrides:
|
|
156
|
+
# GHSA-37g9-w4hg-h9qr (high): @nestjs/graphql 13.4.5 exact-pins ws 8.21.3. Keep key and target in lockstep
|
|
157
|
+
# with the ws version @lenne.tech/nest-server declares (8.23.0 since 11.46.5). Remove once @nestjs/graphql pins ws >= 8.23.0.
|
|
158
|
+
'ws@>=8.0.0 <8.23.0': '8.23.0'
|
|
159
|
+
# The 7.x copy comes from @nestjs/graphql 13 > subscriptions-transport-ws, same advisory.
|
|
160
|
+
'ws@>=7.0.0 <7.5.14': '7.5.14'
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`pnpm why ws` must then show a single `ws@8.23.0` (and `ws@7.5.14` for the legacy transport). Until GitHub's global advisory database lists the
|
|
164
|
+
advisory, `pnpm audit` does not report the vulnerable version. A vendor-mode project adds the same entry.
|
|
165
|
+
|
|
166
|
+
## Troubleshooting
|
|
167
|
+
|
|
168
|
+
| Symptom | Cause | Fix |
|
|
169
|
+
|---|---|---|
|
|
170
|
+
| `ERROR [CoreFileController] File download failed: aborted` with `socketCloseListener` in the stack, one per aborted download | 11.46.3 – 11.46.4 on S3 | Update to 11.46.5 (§4) |
|
|
171
|
+
| `pnpm why ws` lists `ws@8.21.3` 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` |
|
|
172
|
+
| 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 |
|
|
173
|
+
| `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 |
|
|
174
|
+
| `RangeError: Invalid byte range` | A `range` with `start > end`, a negative or fractional value reached `getFileStream()` / `getObject()` | Produce it with `resolveDownloadRange()` |
|
|
175
|
+
| `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 |
|
|
176
|
+
|
|
177
|
+
## Module Documentation
|
|
178
|
+
|
|
179
|
+
- `docs/security-overrides.md` — the `ws` entry and its lockstep rule
|
|
180
|
+
|
|
181
|
+
- `src/core/modules/file/README.md` — "Byte ranges: video, audio, resumed downloads (11.46.5)"
|
|
182
|
+
- `src/core/modules/file/INTEGRATION-CHECKLIST.md` — Common Mistakes
|
|
183
|
+
- `docs/error-codes.md` — `LTNS_0503`
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# Migration Guide: 11.46.5 → 11.46.6
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | None |
|
|
8
|
+
| **New Features** | None. New exports for the fix below: `processGraphQlUploadRequest`, `GRAPHQL_UPLOAD_MAX_PATH_KEYS`, `GRAPHQL_UPLOAD_MAX_MAP_KEYS` |
|
|
9
|
+
| **Bugfixes** | None |
|
|
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, one with a numeric key like `4294967294` handed GraphQL an array of 2^32 − 1 elements). Invalid variables, documents of many operations, fragments spread thousands of times and tens of thousands of variables, a plain JSON POST included, blocked the event loop in the complexity check (§3). A PEM private key under a key such as `certificate` is masked in the Hub config panel (§4) |
|
|
11
|
+
| **Migration Effort** | `pnpm run update`. Projects that register `graphqlUploadExpress()` themselves pass the framework's parser (§1); vendor-mode projects add four dependencies (§2) |
|
|
12
|
+
|
|
13
|
+
## Quick Migration
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @lenne.tech/nest-server@11.46.6
|
|
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 §2.
|
|
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 11.46.5
|
|
30
|
+
it ran graphql-upload 15.0.2'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 15.0.2 and 18.0.2 have the same flaw):** the parser places each
|
|
42
|
+
upload with object-path's `set()`, which recurses once per key and copies the remaining keys each time — O(n²) memory
|
|
43
|
+
and time for a path of n keys, in one synchronous call. Measured on this line (Node 24) with
|
|
44
|
+
`map={"1":["variables.a.a.a…"]}`: 8,000 keys (16 KB) took 330 MB; 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 15.0.2 and 18.0.2 have the same flaw):** every `map` entry
|
|
47
|
+
becomes an upload, and one whose file never arrives is rejected at the end of the request with an error of its own,
|
|
48
|
+
stack trace included. 1 MB of entries without any path (83,000 of them) took 230 MB and blocked the event loop for
|
|
49
|
+
410 to 770 ms.
|
|
50
|
+
- **Numeric keys (no advisory; graphql-upload 15.0.2 and 18.0.2 have the same flaw):** object-path reads a key like
|
|
51
|
+
`4294967294` as a NUMBER and sets that index of an array it creates. The 258-byte request
|
|
52
|
+
`map={"1":["variables.f.4294967294"]}` handed GraphQL an array of 4,294,967,295 elements, and GraphQL's list coercion
|
|
53
|
+
walks every hole: the complexity plugin did, before any guard, until a 1 GB heap ran out (10 s). With a nullable list
|
|
54
|
+
item (`[Upload]`) every hole is a valid `null`, so execution would walk them too.
|
|
55
|
+
|
|
56
|
+
graphql-upload fixed the two advisories in 18.0.2, an ESM-only release that requires graphql 17; this line runs
|
|
57
|
+
graphql 16 with graphql-upload 15.0.2. 11.46.6 therefore ships `processGraphQlUploadRequest`
|
|
58
|
+
(`common/helpers/graphql-upload.helper.ts`): graphql-upload 15.0.2's parser with both upstream fixes and two bounds of
|
|
59
|
+
its own, and `CoreModule` passes it to `graphqlUploadExpress()`. It answers with 400:
|
|
60
|
+
|
|
61
|
+
- a path into another upload or with a `__proto__` key — "Invalid object path",
|
|
62
|
+
- a path with more than `GRAPHQL_UPLOAD_MAX_PATH_KEYS` (64) keys — "Invalid object path",
|
|
63
|
+
- a `map` with more than `GRAPHQL_UPLOAD_MAX_MAP_KEYS` (10,000) units. Every entry counts one, every key of its paths
|
|
64
|
+
one more, and every array element a numeric key creates one more, holes included: `{"1":["variables.files.0"]}`
|
|
65
|
+
counts 5, or 4 when the operations already hold `files: [null]`; `variables.f.4294967294` counts more than four
|
|
66
|
+
billion. The path that goes over the bound is answered with "Invalid object path", an entry with "Invalid ‘map’
|
|
67
|
+
multipart field entry key …" before its upload is created.
|
|
68
|
+
|
|
69
|
+
A duplicate file field is ignored. Each of these requests is now answered within about 50 ms (the 83,000 entries:
|
|
70
|
+
~50 ms, +50 MB; `variables.f.4294967294`: ~15 ms, +4 MB). A path a client library builds has a handful of keys
|
|
71
|
+
(`variables.file` 2, `variables.input.files.3` 4, batched `0.variables.file` 3); 10,000 units are at least 2,000 files
|
|
72
|
+
at `variables.files.N`. The most expensive request
|
|
73
|
+
the bounds still accept — 10,000 entries without a path — blocks the event loop for about 80 ms with +35 MB.
|
|
74
|
+
graphql-upload stays at 15.0.2 for its scalar and middleware.
|
|
75
|
+
|
|
76
|
+
**A project that registers `graphqlUploadExpress()` itself** (its own route, its own limits) passes the framework's
|
|
77
|
+
parser — graphql-upload's default is the vulnerable one:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { processGraphQlUploadRequest } from '@lenne.tech/nest-server';
|
|
81
|
+
import graphqlUploadExpress = require('graphql-upload/graphqlUploadExpress.js');
|
|
82
|
+
|
|
83
|
+
consumer
|
|
84
|
+
.apply(graphqlUploadExpress({ maxFiles: 10, maxFileSize: 10_000_000, processRequest: processGraphQlUploadRequest }))
|
|
85
|
+
.forRoutes('graphql');
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Find such registrations with `grep -rn "graphqlUploadExpress(" src/`. A project that calls graphql-upload's
|
|
89
|
+
`processRequest` directly switches to `processGraphQlUploadRequest` (same signature and options).
|
|
90
|
+
|
|
91
|
+
**Behaviour change:** a GraphQL variable literally named `__proto__` that receives a file is refused with 400 (input
|
|
92
|
+
object fields cannot use that name; names starting with `__` are reserved).
|
|
93
|
+
|
|
94
|
+
## 2. Dependencies
|
|
95
|
+
|
|
96
|
+
New direct `dependencies` for the multipart parser (§1): `busboy` 1.6.0, `fs-capacitor` 6.2.0, `http-errors` 2.0.1 and
|
|
97
|
+
`object-path` 0.11.8 — the versions graphql-upload 15.0.2 already installs, so an npm-mode project gets no new package.
|
|
98
|
+
|
|
99
|
+
A **vendor-mode** project declares them in `dependencies`: the core imports them directly, and a pnpm project does not
|
|
100
|
+
see graphql-upload's own copies. A project that compiles with `noImplicitAny` (part of `strict`) also adds
|
|
101
|
+
`@types/busboy` 1.5.4, `@types/http-errors` 2.0.5 and `@types/object-path` 0.11.4 to `devDependencies`.
|
|
102
|
+
|
|
103
|
+
## 3. Security: the complexity check is bounded
|
|
104
|
+
|
|
105
|
+
`ComplexityPlugin` (registered by `CoreModule` whenever GraphQL is on) computes every operation's cost in Apollo's
|
|
106
|
+
`didResolveOperation`, after parsing and validation, before any guard. It called graphql-query-complexity's
|
|
107
|
+
`getComplexity()`, and these requests made that call itself the denial of service — each one anonymous, a plain JSON
|
|
108
|
+
POST to `/graphql` included:
|
|
109
|
+
|
|
110
|
+
- **Invalid variables.** `getComplexity()` coerces the variables with graphql's `getVariableValues()` without an error
|
|
111
|
+
cap, so a list of invalid items (`"variables":{"f":[0,0,…]}` for `$f: [Upload!]!`) created one `GraphQLError` per item.
|
|
112
|
+
- **Many operations, no `operationName`.** Apollo resolves no operation and still calls the hook. `getComplexity()`
|
|
113
|
+
then evaluated EVERY operation of the document and coerced the variables for each.
|
|
114
|
+
- **Fragment spreads.** graphql-query-complexity evaluates a fragment again at every spread, coercing its literal
|
|
115
|
+
arguments each time. Its node cap (10,000 visits) bounds the visits, not what one costs:
|
|
116
|
+
`{...F …×3300} fragment F on Query { findUsers(filter: { singleFilter: { …, value: [0,0,…] } }) { __typename } }`.
|
|
117
|
+
- **Many declared variables.** At every field it visits, the library walks every declared variable.
|
|
118
|
+
- **Many failing arguments.** The library catches the coercion error of every field's arguments and goes on, and every
|
|
119
|
+
error locates itself by scanning the query up to its field: `query($x: String = "a") { a: getUser(id: $x) { id } … }`
|
|
120
|
+
with `{"x": null}` is valid and fails at every field.
|
|
121
|
+
|
|
122
|
+
| Request | 11.46.5 | 11.46.6 |
|
|
123
|
+
|---|---|---|
|
|
124
|
+
| 100 KB of invalid list items | event loop blocked 1.6 s, +320 MB | ~5 ms, +1 MB |
|
|
125
|
+
| 1 MB of invalid list items | event loop blocked 17 s, +1.8 GB | ~10 ms, +14 MB |
|
|
126
|
+
| 860 operations sharing one 16,000-item variable (100 KB) | event loop blocked 5.9 s | < 1 ms, refused by execution |
|
|
127
|
+
| the same with 1,720 operations (200 KB multipart) | event loop blocked 25.5 s | < 1 ms, refused by execution |
|
|
128
|
+
| a 41,667-item literal in a fragment spread 3,300 times (100 KB) | event loop blocked 2.2 s | ~15 ms, "Query is too complex" |
|
|
129
|
+
| the same with a 490,000-item literal (990 KB multipart) | event loop blocked 22.5 s | ~100 ms, "Query is too complex" |
|
|
130
|
+
| 38,000 declared variables and 4,900 spreads (1.2 MB) | event loop blocked 17 s | ~100 ms, "Query is too complex" |
|
|
131
|
+
| 2,300 fields failing their argument, after 25,000 line breaks (98 KiB) | event loop blocked 1.4 s | ~6 ms, refused with the first error |
|
|
132
|
+
| 9,999 such fields after 395,000 line breaks (993 KiB multipart) | event loop blocked 86 s | ~16 ms, refused with the first error |
|
|
133
|
+
|
|
134
|
+
What is left for the large literal and the many variables is linear in the request: graphql's validation and
|
|
135
|
+
execution walk the same literal and the same variables once themselves.
|
|
136
|
+
|
|
137
|
+
The rows after the first two were measured on the development line, which has the same plugin and the same
|
|
138
|
+
graphql-query-complexity 2.0.0.
|
|
139
|
+
|
|
140
|
+
Since 11.46.6 the plugin:
|
|
141
|
+
|
|
142
|
+
1. does nothing when Apollo resolved no operation — graphql's `execute()` then refuses the request ("Must provide
|
|
143
|
+
operation name…") before it coerces a single variable;
|
|
144
|
+
2. coerces the resolved operation's variables, stopping at the first error, and skips the complexity check when they
|
|
145
|
+
do not coerce: `execute()` refuses such variables itself, with graphql's cap of 50, before any resolver runs, so
|
|
146
|
+
there is no operation whose cost could matter;
|
|
147
|
+
3. refuses an operation whose fields (and `@skip` / `@include`) times declared variables exceed 250,000, with
|
|
148
|
+
`Query is too complex: too many fields for its number of variables` — measured at most about 23 ms of analysis.
|
|
149
|
+
With the default cost of 1 per field, a query `maxComplexity: 1000` accepts has at most 1,000 fields; with 30
|
|
150
|
+
variables that is at most 30,000;
|
|
151
|
+
4. computes graphql-query-complexity's number with each fragment evaluated once and reused at every further spread.
|
|
152
|
+
The number is the one `getComplexity()` returns, and the 10,000-node cap still counts every spread. A field's
|
|
153
|
+
`complexity` extension that is a function runs once per fragment instead of once per spread, so it must depend only
|
|
154
|
+
on its arguments and `childComplexity`;
|
|
155
|
+
5. stops the analysis at its first error and refuses the request with it — `getComplexity()` collected every error and
|
|
156
|
+
threw the last one.
|
|
157
|
+
|
|
158
|
+
For valid variables the result is what it was: `Query is too complex: …` above `graphQl.maxComplexity`, and
|
|
159
|
+
`Query exceeds the maximum allowed number of nodes.` above 10,000 nodes.
|
|
160
|
+
|
|
161
|
+
**What clients see:** a request with invalid variables gets execution's errors (up to 50 messages, then "Too many
|
|
162
|
+
errors processing variables, error limit reached. Execution aborted.") instead of the single coercion error the plugin
|
|
163
|
+
threw before. The status changes with it: HTTP 400 with the code `BAD_USER_INPUT` (Apollo 5 default
|
|
164
|
+
`status400ForVariableCoercionErrors`) instead of HTTP 500 with `INTERNAL_SERVER_ERROR`.
|
|
165
|
+
|
|
166
|
+
## 4. Security: PEM private keys are masked in the Hub config panel
|
|
167
|
+
|
|
168
|
+
The Hub config panel's masker (`maskConfigDeep()`) decided by the key name alone. A certificate login usually keeps
|
|
169
|
+
certificate and private key in one PEM under a name such as `certificate`, which no name rule may treat as secret, so
|
|
170
|
+
the panel showed the private key to administrators in clear text. Since 11.46.6 every string and `Buffer` that holds
|
|
171
|
+
a PEM private key (`-----BEGIN … PRIVATE KEY-----`, PGP's `PRIVATE KEY BLOCK` included) is masked as a whole, whatever
|
|
172
|
+
its key is called. A certificate without a key stays readable.
|
|
173
|
+
|
|
174
|
+
No action needed. A project's own `GET /config` route does not use this masker on 11.x; if it returns the
|
|
175
|
+
configuration, it masks with its own rules — check them for the same case.
|
|
176
|
+
|
|
177
|
+
## Compatibility Notes
|
|
178
|
+
|
|
179
|
+
| Pattern | Status |
|
|
180
|
+
|---|---|
|
|
181
|
+
| Uploads through `CoreModule`'s `/graphql` registration | Protected with the update |
|
|
182
|
+
| `graphqlUploadExpress()` registered by the project | Pass `processRequest: processGraphQlUploadRequest` (§1) |
|
|
183
|
+
| Vendor mode, GraphQL uploads | Add the four dependencies (and the `@types/*` under `noImplicitAny`) from §2 |
|
|
184
|
+
| A project's own Apollo plugin that calls `getComplexity()` with the request's variables | Same flaws as §3 — skip a request without a resolved operation, check the variables with `getVariableValues(…, { maxErrors: 50 })` first, and bound fragment spreads and variables, or rely on the framework's plugin |
|
|
185
|
+
|
|
186
|
+
## Troubleshooting
|
|
187
|
+
|
|
188
|
+
| Symptom | Cause | Fix |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| Vendor mode: `Cannot find module 'busboy'` (or `fs-capacitor`, `http-errors`, `object-path`) at start | The core imports them since 11.46.6 | Add them to `dependencies` (§2) |
|
|
191
|
+
| 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 §2 |
|
|
192
|
+
| 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`) |
|
|
193
|
+
| An upload answers 400 `Invalid object path …` for a path with a large number in it | The index creates more array elements than the bound allows | Number the files from 0 (`variables.files.0`, `variables.files.1`) |
|
|
194
|
+
| 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 units | Split the upload into several requests |
|
|
195
|
+
| A request with invalid variables answers with several variable errors instead of one | Execution reports them now (§3) | Fix the variables; the messages are graphql's own |
|
|
196
|
+
| A query answers `Query is too complex: too many fields for its number of variables` | Its fields × declared variables exceed 250,000 (§3) | Split the query, or pass related values as one input-object variable |
|
|
197
|
+
|
|
198
|
+
## Module Documentation
|
|
199
|
+
|
|
200
|
+
- `docs/REQUEST-LIFECYCLE.md` — "3. graphqlUploadExpress", feature table "Complexity Analysis"
|
|
201
|
+
- `src/core/common/helpers/graphql-upload.helper.ts` — the parser, its fixes and bounds
|
|
202
|
+
- `src/core/common/plugins/complexity.plugin.ts` — the bounds and why they exist
|
|
203
|
+
- `src/core/modules/hub/helpers/hub-mask.helper.ts` — the Hub config masker
|