@lenne.tech/nest-server 11.46.5 → 11.46.7

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.
Files changed (36) hide show
  1. package/.claude/rules/package-management.md +5 -4
  2. package/.claude/rules/testing.md +4 -4
  3. package/FRAMEWORK-API.md +1 -1
  4. package/dist/core/common/helpers/graphql-upload.helper.d.ts +10 -0
  5. package/dist/core/common/helpers/graphql-upload.helper.js +240 -0
  6. package/dist/core/common/helpers/graphql-upload.helper.js.map +1 -0
  7. package/dist/core/common/plugins/complexity.plugin.js +71 -7
  8. package/dist/core/common/plugins/complexity.plugin.js.map +1 -1
  9. package/dist/core/modules/better-auth/better-auth-cookie-prefix.helper.d.ts +2 -0
  10. package/dist/core/modules/better-auth/better-auth-cookie-prefix.helper.js +7 -0
  11. package/dist/core/modules/better-auth/better-auth-cookie-prefix.helper.js.map +1 -1
  12. package/dist/core/modules/better-auth/core-better-auth.middleware.js +4 -2
  13. package/dist/core/modules/better-auth/core-better-auth.middleware.js.map +1 -1
  14. package/dist/core/modules/hub/helpers/hub-mask.helper.js +5 -1
  15. package/dist/core/modules/hub/helpers/hub-mask.helper.js.map +1 -1
  16. package/dist/core.module.js +2 -1
  17. package/dist/core.module.js.map +1 -1
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +1 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/tsconfig.build.tsbuildinfo +1 -1
  22. package/dist/types/graphql-upload.d.ts +35 -1
  23. package/docs/REQUEST-LIFECYCLE.md +26 -3
  24. package/migration-guides/11.46.5-to-11.46.6.md +203 -0
  25. package/migration-guides/11.46.6-to-11.46.7.md +70 -0
  26. package/package.json +9 -2
  27. package/src/core/common/helpers/graphql-upload.helper.ts +522 -0
  28. package/src/core/common/plugins/complexity.plugin.ts +150 -9
  29. package/src/core/modules/better-auth/better-auth-cookie-prefix.helper.ts +17 -0
  30. package/src/core/modules/better-auth/core-better-auth.middleware.ts +9 -4
  31. package/src/core/modules/hub/helpers/hub-mask.helper.ts +16 -3
  32. package/src/core/modules/system-setup/INTEGRATION-CHECKLIST.md +8 -8
  33. package/src/core/modules/system-setup/README.md +6 -6
  34. package/src/core.module.ts +5 -1
  35. package/src/index.ts +1 -0
  36. 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 GraphQLUploadOptions {
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
 
@@ -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
  ---
@@ -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
@@ -0,0 +1,70 @@
1
+ # Migration Guide: 11.46.6 → 11.46.7
2
+
3
+ ## Overview
4
+
5
+ | Category | Details |
6
+ |---|---|
7
+ | **Breaking Changes** | None |
8
+ | **New Features** | None. `resolveJwtCookieName()` and `DEFAULT_JWT_COOKIE_NAME` name the JWT cookie |
9
+ | **Bugfixes** | With `COOKIE_PREFIX`, the API reads a JWT-mode frontend's JWT cookie under `<prefix>-jwt-token`, the name `@lenne.tech/nuxt-extensions` writes (§1) |
10
+ | **Security** | None |
11
+ | **Migration Effort** | Package update. Only projects that set `COOKIE_PREFIX` and run in JWT mode (`cookies: false`) notice a difference |
12
+
13
+ ## Quick Migration
14
+
15
+ ```bash
16
+ pnpm add @lenne.tech/nest-server@11.46.7
17
+ pnpm run update # nest-server-starter based projects
18
+ pnpm run build
19
+ pnpm test
20
+ ```
21
+
22
+ **Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual.
23
+
24
+ ## 1. Bugfix: the JWT cookie follows `COOKIE_PREFIX`
25
+
26
+ **No action needed.** Keep `COOKIE_PREFIX` (API) and `NUXT_PUBLIC_COOKIE_PREFIX` (app) equal, as before.
27
+
28
+ In JWT mode the frontend keeps the Better-Auth JWT in a cookie as well as sending it as a bearer token. A request that
29
+ carries the cookie but no `Authorization` header is authenticated by `CoreBetterAuthMiddleware` from that cookie: a
30
+ server-side rendered page that forwards the browser's cookies, and a passkey request from the app.
31
+
32
+ `@lenne.tech/nuxt-extensions` names that cookie `<NUXT_PUBLIC_COOKIE_PREFIX>-jwt-token` when a prefix is set. Up to
33
+ 11.46.6 the API read `lt-jwt-token` only. With a prefix such a request was anonymous, and Better-Auth's plugin routes
34
+ (passkey registration, two-factor) answered `401`.
35
+
36
+ | `COOKIE_PREFIX` | JWT cookie read since 11.46.7 | Before |
37
+ |---|---|---|
38
+ | not set | `lt-jwt-token` | `lt-jwt-token` |
39
+ | `acme` | `acme-jwt-token` | `lt-jwt-token` |
40
+
41
+ The prefix is sanitised by the same rule as on the frontend (`[A-Za-z0-9._-]`). The base path does not enter the name,
42
+ unlike the session cookie (`<prefix>.session_token`, else `iam.session_token`). There is no fallback to `lt-jwt-token`
43
+ while `COOKIE_PREFIX` is set: the prefix keeps the apps on one host apart, and the session cookie does not fall back
44
+ either.
45
+
46
+ ## 2. Dependencies
47
+
48
+ A pnpm override lifts `i18next` to 26.4.4 under `@compodoc/compodoc` (GHSA-6jcc-5g8w-32mx, GHSA-5jr9-983r-c8x4). It is dev tooling of this repository (`pnpm run docs`) and does not reach consumers; nothing to do in a project.
49
+
50
+ ## Compatibility Notes
51
+
52
+ | Pattern | Status |
53
+ |---|---|
54
+ | No `COOKIE_PREFIX` | Unchanged |
55
+ | `COOKIE_PREFIX` with cookies (the default `cookies: true`) | Unchanged; the session cookie already followed the prefix |
56
+ | `COOKIE_PREFIX` with `cookies: false` and a matching `NUXT_PUBLIC_COOKIE_PREFIX` | Fixed: the JWT cookie is read |
57
+ | A frontend that sets `COOKIE_PREFIX` on the API but writes `lt-jwt-token` | No longer authenticated through the cookie. Set the same prefix on both sides |
58
+
59
+ ## Troubleshooting
60
+
61
+ | Symptom | Cause | Fix |
62
+ |---|---|---|
63
+ | Passkey or 2FA routes answer `401` in JWT mode with a cookie prefix | 11.46.6 or older read only `lt-jwt-token` | Update to 11.46.7 |
64
+ | Still `401` after the update | The API and the app use different prefixes | Set `COOKIE_PREFIX` and `NUXT_PUBLIC_COOKIE_PREFIX` to the same value |
65
+
66
+ ## Module Documentation
67
+
68
+ - `src/core/modules/better-auth/better-auth-cookie-prefix.helper.ts`: `resolveJwtCookieName()`, `resolveBetterAuthCookiePrefix()`
69
+ - Same fix on the current line: 12.11.2
70
+ - `migration-guides/11.26.1-to-11.26.2.md`, §1: `COOKIE_PREFIX` and the frontend pairing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "11.46.5",
3
+ "version": "11.46.7",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
@@ -108,6 +108,7 @@
108
108
  "@tus/server": "2.4.6",
109
109
  "@types/supertest": "7.2.1",
110
110
  "bcrypt": "6.0.0",
111
+ "busboy": "1.6.0",
111
112
  "class-transformer": "0.5.1",
112
113
  "class-validator": "0.15.1",
113
114
  "compression": "1.8.2",
@@ -116,11 +117,13 @@
116
117
  "dotenv": "17.4.2",
117
118
  "ejs": "6.0.1",
118
119
  "express": "5.2.1",
120
+ "fs-capacitor": "6.2.0",
119
121
  "graphql": "16.14.2",
120
122
  "graphql-query-complexity": "2.0.0",
121
123
  "graphql-subscriptions": "3.0.0",
122
124
  "graphql-upload": "15.0.2",
123
125
  "graphql-ws": "6.2.1",
126
+ "http-errors": "2.0.1",
124
127
  "jose": "6.2.12",
125
128
  "js-sha256": "1.0.0",
126
129
  "json-to-graphql-query": "2.3.0",
@@ -130,6 +133,7 @@
130
133
  "multer": "2.5.0",
131
134
  "node-mailjet": "6.0.11",
132
135
  "nodemailer": "10.4.1",
136
+ "object-path": "0.11.8",
133
137
  "passport": "0.7.0",
134
138
  "passport-jwt": "4.0.1",
135
139
  "reflect-metadata": "0.2.2",
@@ -194,13 +198,16 @@
194
198
  "@swc/cli": "0.8.1",
195
199
  "@swc/core": "1.16.18",
196
200
  "@tus/s3-store": "2.0.8",
201
+ "@types/busboy": "1.5.4",
197
202
  "@types/compression": "1.8.1",
198
203
  "@types/cookie-parser": "1.4.10",
199
204
  "@types/ejs": "3.1.5",
200
205
  "@types/express": "5.0.6",
206
+ "@types/http-errors": "2.0.5",
201
207
  "@types/lodash": "4.17.26",
202
208
  "@types/multer": "2.3.0",
203
209
  "@types/node": "26.6.5",
210
+ "@types/object-path": "0.11.4",
204
211
  "@types/passport": "1.0.17",
205
212
  "@vitest/coverage-v8": "4.1.12",
206
213
  "better-auth": "1.7.16",
@@ -220,7 +227,7 @@
220
227
  "tus-js-client": "4.3.1",
221
228
  "typescript": "5.9.3",
222
229
  "unplugin-swc": "2.0.0",
223
- "vite": "8.3.4",
230
+ "vite": "8.3.8",
224
231
  "vite-plugin-node": "8.0.0",
225
232
  "vitest": "4.1.12"
226
233
  },