@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.
Files changed (72) hide show
  1. package/.claude/rules/package-management.md +4 -3
  2. package/.claude/rules/testing.md +4 -4
  3. package/FRAMEWORK-API.md +1 -1
  4. package/dist/core/common/helpers/byte-range.helper.d.ts +8 -0
  5. package/dist/core/common/helpers/byte-range.helper.js +76 -0
  6. package/dist/core/common/helpers/byte-range.helper.js.map +1 -0
  7. package/dist/core/common/helpers/graphql-upload.helper.d.ts +10 -0
  8. package/dist/core/common/helpers/graphql-upload.helper.js +240 -0
  9. package/dist/core/common/helpers/graphql-upload.helper.js.map +1 -0
  10. package/dist/core/common/helpers/gridfs.helper.d.ts +7 -2
  11. package/dist/core/common/helpers/gridfs.helper.js +7 -4
  12. package/dist/core/common/helpers/gridfs.helper.js.map +1 -1
  13. package/dist/core/common/plugins/complexity.plugin.js +71 -7
  14. package/dist/core/common/plugins/complexity.plugin.js.map +1 -1
  15. package/dist/core/common/services/core-s3.service.d.ts +3 -0
  16. package/dist/core/common/services/core-s3.service.js +8 -1
  17. package/dist/core/common/services/core-s3.service.js.map +1 -1
  18. package/dist/core/modules/error-code/error-codes.d.ts +9 -0
  19. package/dist/core/modules/error-code/error-codes.js +8 -0
  20. package/dist/core/modules/error-code/error-codes.js.map +1 -1
  21. package/dist/core/modules/file/core-file.controller.d.ts +5 -0
  22. package/dist/core/modules/file/core-file.controller.js +67 -3
  23. package/dist/core/modules/file/core-file.controller.js.map +1 -1
  24. package/dist/core/modules/file/core-file.service.d.ts +2 -0
  25. package/dist/core/modules/file/core-file.service.js +17 -6
  26. package/dist/core/modules/file/core-file.service.js.map +1 -1
  27. package/dist/core/modules/file/filesystem-file.helper.d.ts +2 -1
  28. package/dist/core/modules/file/filesystem-file.helper.js +2 -2
  29. package/dist/core/modules/file/filesystem-file.helper.js.map +1 -1
  30. package/dist/core/modules/file/interfaces/file-service-options.interface.d.ts +2 -0
  31. package/dist/core/modules/file/s3-file.helper.d.ts +2 -0
  32. package/dist/core/modules/file/s3-file.helper.js.map +1 -1
  33. package/dist/core/modules/hub/helpers/hub-mask.helper.js +5 -1
  34. package/dist/core/modules/hub/helpers/hub-mask.helper.js.map +1 -1
  35. package/dist/core.module.js +2 -1
  36. package/dist/core.module.js.map +1 -1
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.js +2 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/server/modules/error-code/error-codes.d.ts +1 -0
  41. package/dist/test/test.helper.d.ts +1 -0
  42. package/dist/test/test.helper.js +6 -0
  43. package/dist/test/test.helper.js.map +1 -1
  44. package/dist/tsconfig.build.tsbuildinfo +1 -1
  45. package/dist/types/graphql-upload.d.ts +35 -1
  46. package/docs/REQUEST-LIFECYCLE.md +27 -4
  47. package/docs/error-codes.md +14 -0
  48. package/docs/security-overrides.md +21 -6
  49. package/migration-guides/11.46.4-to-11.46.5.md +183 -0
  50. package/migration-guides/11.46.5-to-11.46.6.md +203 -0
  51. package/package.json +14 -7
  52. package/src/core/common/helpers/byte-range.helper.ts +144 -0
  53. package/src/core/common/helpers/graphql-upload.helper.ts +522 -0
  54. package/src/core/common/helpers/gridfs.helper.ts +20 -6
  55. package/src/core/common/plugins/complexity.plugin.ts +150 -9
  56. package/src/core/common/services/core-s3.service.ts +16 -2
  57. package/src/core/modules/error-code/error-codes.ts +13 -0
  58. package/src/core/modules/file/INTEGRATION-CHECKLIST.md +1 -0
  59. package/src/core/modules/file/README.md +74 -1
  60. package/src/core/modules/file/core-file.controller.ts +139 -3
  61. package/src/core/modules/file/core-file.service.ts +33 -13
  62. package/src/core/modules/file/filesystem-file.helper.ts +8 -3
  63. package/src/core/modules/file/interfaces/file-service-options.interface.ts +13 -0
  64. package/src/core/modules/file/s3-file.helper.ts +3 -2
  65. package/src/core/modules/hub/helpers/hub-mask.helper.ts +16 -3
  66. package/src/core/modules/system-setup/INTEGRATION-CHECKLIST.md +8 -8
  67. package/src/core/modules/system-setup/README.md +6 -6
  68. package/src/core.module.ts +5 -1
  69. package/src/index.ts +2 -0
  70. package/src/test/README.md +8 -4
  71. package/src/test/test.helper.ts +12 -0
  72. package/src/types/graphql-upload.d.ts +35 -1
@@ -19,6 +19,7 @@ import { decideFileAccess, fileAccessNeedsRawDocument, resolveFileAccessPreset }
19
19
  import { warnOnUndecidedFileAccess } from './file-roles.config';
20
20
  import { FileServiceOptions } from './interfaces/file-service-options.interface';
21
21
  import { FileUploadSource } from './interfaces/file-upload.interface';
22
+ import { assertByteRange } from '../../common/helpers/byte-range.helper';
22
23
  import {
23
24
  assertFileStorageAvailable,
24
25
  FileStorageDriver,
@@ -475,6 +476,10 @@ export abstract class CoreFileService {
475
476
 
476
477
  /**
477
478
  * Get file stream (for big files) via file ID
479
+ *
480
+ * With `serviceOptions.range`, only those bytes (both inclusive) — from every store: S3 with a ranged
481
+ * `GetObject`, GridFS from the chunk that holds the first byte, the filesystem from that offset. See
482
+ * {@link FileServiceOptions.range} for the contract and `resolveDownloadRange()` for producing one from a request.
478
483
  */
479
484
  async getFileStream(
480
485
  id: string | Types.ObjectId,
@@ -484,6 +489,8 @@ export abstract class CoreFileService {
484
489
  if (this.isMalformedFileId(id)) {
485
490
  return null;
486
491
  }
492
+ // Checked before anything is asked: a malformed range is a caller's bug, answered the same for every store
493
+ assertByteRange(serviceOptions?.range);
487
494
  if (!(await this.checkRights(id, { ...serviceOptions, checkInputType: 'id' }))) {
488
495
  return null;
489
496
  }
@@ -493,6 +500,19 @@ export abstract class CoreFileService {
493
500
  // the same one-to-three metadata round trips are not repeated per download.
494
501
  // Omitting it keeps the previous behaviour exactly.
495
502
  const store = knownStore ?? (await this.locateFile(id));
503
+ return this.openStoreStream(store, id, serviceOptions);
504
+ }
505
+
506
+ /**
507
+ * Open the download stream of a file in the store that holds it — the whole file, or `serviceOptions.range` —
508
+ * guarded against a caller that stops reading. The rights check is the caller's: this only reads bytes.
509
+ */
510
+ protected async openStoreStream(
511
+ store: FileStorageDriver,
512
+ id: string | Types.ObjectId,
513
+ serviceOptions?: FileServiceOptions,
514
+ ): Promise<Readable> {
515
+ const range = assertByteRange(serviceOptions?.range);
496
516
  if (store === 's3') {
497
517
  return this.guardDownloadStream(
498
518
  await S3FileHelper.getStream(this.options.s3Service, id, this.s3StreamOptions(serviceOptions)),
@@ -500,10 +520,10 @@ export abstract class CoreFileService {
500
520
  );
501
521
  }
502
522
  if (store === 'filesystem') {
503
- return this.guardDownloadStream(FilesystemFileHelper.getStream(this.filesystemDir, id), serviceOptions);
523
+ return this.guardDownloadStream(FilesystemFileHelper.getStream(this.filesystemDir, id, range), serviceOptions);
504
524
  }
505
525
  return this.guardDownloadStream(
506
- GridFSHelper.openDownloadStream(this.files, getObjectIds(id)) as mongo.GridFSBucketReadStream,
526
+ GridFSHelper.openDownloadStream(this.files, getObjectIds(id), range) as mongo.GridFSBucketReadStream,
507
527
  serviceOptions,
508
528
  );
509
529
  }
@@ -526,12 +546,17 @@ export abstract class CoreFileService {
526
546
  });
527
547
  }
528
548
 
529
- /** Options for the S3 stream of a download: the caller's abort signal and idle time. */
549
+ /** Options for the S3 stream of a download: the caller's abort signal, idle time and byte range. */
530
550
  protected s3StreamOptions(serviceOptions?: FileServiceOptions): {
531
551
  abortSignal?: AbortSignal;
532
552
  idleTimeoutMs?: false | number;
553
+ range?: FileServiceOptions['range'];
533
554
  } {
534
- return { abortSignal: serviceOptions?.abortSignal, idleTimeoutMs: serviceOptions?.downloadIdleTimeoutMs };
555
+ return {
556
+ abortSignal: serviceOptions?.abortSignal,
557
+ idleTimeoutMs: serviceOptions?.downloadIdleTimeoutMs,
558
+ ...(serviceOptions?.range ? { range: serviceOptions.range } : {}),
559
+ };
535
560
  }
536
561
 
537
562
  /**
@@ -639,22 +664,17 @@ export abstract class CoreFileService {
639
664
  * unchanged; what changed is that the document authorization inspected is the one being served.
640
665
  */
641
666
  async getFileStreamByName(filename: string, serviceOptions?: FileServiceOptions): Promise<Readable> {
667
+ assertByteRange(serviceOptions?.range);
642
668
  if (!(await this.checkRights(filename, { ...serviceOptions, checkInputType: 'filename' }))) {
643
669
  return null;
644
670
  }
645
671
  const s3FileInfo = await this.findS3FileByName(filename);
646
672
  if (s3FileInfo) {
647
- return this.guardDownloadStream(
648
- await S3FileHelper.getStream(this.options.s3Service, s3FileInfo._id, this.s3StreamOptions(serviceOptions)),
649
- serviceOptions,
650
- );
673
+ return this.openStoreStream('s3', s3FileInfo._id, serviceOptions);
651
674
  }
652
675
  const fsFileInfo = await this.findFilesystemFileByName(filename);
653
676
  if (fsFileInfo) {
654
- return this.guardDownloadStream(
655
- FilesystemFileHelper.getStream(this.filesystemDir, fsFileInfo._id),
656
- serviceOptions,
657
- );
677
+ return this.openStoreStream('filesystem', fsFileInfo._id, serviceOptions);
658
678
  }
659
679
  const gridFsInfo = await GridFSHelper.findFileByName(this.files, filename);
660
680
  if (!gridFsInfo) {
@@ -662,7 +682,7 @@ export abstract class CoreFileService {
662
682
  // itself, asynchronously on the stream, which the controller turns into a 404.
663
683
  return this.guardDownloadStream(GridFSHelper.openDownloadStreamByName(this.files, filename), serviceOptions);
664
684
  }
665
- return this.guardDownloadStream(GridFSHelper.openDownloadStream(this.files, gridFsInfo._id), serviceOptions);
685
+ return this.openStoreStream('gridfs', gridFsInfo._id, serviceOptions);
666
686
  }
667
687
 
668
688
  /**
@@ -14,6 +14,7 @@ import {
14
14
  findMetadataByName,
15
15
  } from './file-metadata.helper';
16
16
  import { streamToBuffer } from './s3-file.helper';
17
+ import type { ByteRange } from '../../common/helpers/byte-range.helper';
17
18
 
18
19
  /** Metadata collection for files stored on the local filesystem */
19
20
  export const FILESYSTEM_FILES_COLLECTION = 'filesystem-files';
@@ -169,10 +170,14 @@ export class FilesystemFileHelper {
169
170
  }
170
171
 
171
172
  /**
172
- * Get the download stream of a file
173
+ * Get the download stream of a file — with `range`, only those bytes (both inclusive, as `createReadStream()`
174
+ * counts them)
173
175
  */
174
- static getStream(directory: string, id: string | Types.ObjectId): Readable {
175
- return createReadStream(FilesystemFileHelper.filePath(directory, id));
176
+ static getStream(directory: string, id: string | Types.ObjectId, range?: ByteRange): Readable {
177
+ return createReadStream(
178
+ FilesystemFileHelper.filePath(directory, id),
179
+ range ? { end: range.end, start: range.start } : undefined,
180
+ );
176
181
  }
177
182
 
178
183
  /**
@@ -1,3 +1,5 @@
1
+ import type { ByteRange } from '../../../common/helpers/byte-range.helper';
2
+
1
3
  /**
2
4
  * Interface for service options in file services
3
5
  */
@@ -40,5 +42,16 @@ export interface FileServiceOptions {
40
42
  */
41
43
  metadata?: Record<string, any>;
42
44
 
45
+ /**
46
+ * Read only these bytes of the file (both inclusive) — `getFileStream()` / `getFileStreamByName()`, every store.
47
+ *
48
+ * What a route needs to answer a `Range` request with `206 Partial Content` (video and audio in Safari and every
49
+ * media player, resumed downloads). The range must lie inside the file (`end` below its `length`): produce it with
50
+ * `resolveDownloadRange(res, file.length)`, which also answers an unsatisfiable range with `416`. A malformed range
51
+ * (negative, not an integer, `start > end`) throws a `RangeError` before any store is asked. The rights check runs
52
+ * first, as for a whole file. Since 11.46.5.
53
+ */
54
+ range?: ByteRange;
55
+
43
56
  roles?: string | string[];
44
57
  }
@@ -2,6 +2,7 @@ import { Types } from 'mongoose';
2
2
  import { Readable } from 'stream';
3
3
 
4
4
  import { CoreS3Service } from '../../common/services/core-s3.service';
5
+ import type { ByteRange } from '../../common/helpers/byte-range.helper';
5
6
  import {
6
7
  ensureFilenameIndex,
7
8
  FileCollection,
@@ -212,12 +213,12 @@ export class S3FileHelper {
212
213
  }
213
214
 
214
215
  /**
215
- * Get the download stream of a file
216
+ * Get the download stream of a file — with `range`, only those bytes (both inclusive)
216
217
  */
217
218
  static async getStream(
218
219
  s3Service: CoreS3Service,
219
220
  id: string | Types.ObjectId,
220
- options?: { abortSignal?: AbortSignal; idleTimeoutMs?: false | number },
221
+ options?: { abortSignal?: AbortSignal; idleTimeoutMs?: false | number; range?: ByteRange },
221
222
  ): Promise<Readable> {
222
223
  const objectId = typeof id === 'string' ? new Types.ObjectId(id) : id;
223
224
  return (await s3Service.getObject(objectId.toHexString(), options)).body;
@@ -30,6 +30,15 @@ const SECRET_KEY_PATTERN =
30
30
  */
31
31
  const URI_CREDENTIAL_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/[^/@:\s]*:)([^@/\s]+)(@)/i;
32
32
 
33
+ /**
34
+ * Value-shape heuristic: a PEM block holding a private key — `-----BEGIN PRIVATE KEY-----` and its `RSA`, `EC`,
35
+ * `ENCRYPTED`, `OPENSSH` variants, and PGP's `-----BEGIN PGP PRIVATE KEY BLOCK-----`. Checked in every string and
36
+ * `Buffer`, whatever its key is called (11.46.6): a certificate login keeps certificate and key in ONE PEM, usually
37
+ * under a name such as `certificate` that no key heuristic may call secret — a certificate alone is public. Until
38
+ * 11.46.6 such a key reached the Hub config panel in clear text. The whole value is masked.
39
+ */
40
+ const PRIVATE_KEY_PEM_PATTERN = /-----BEGIN [A-Z0-9 ]*PRIVATE KEY[A-Z ]*-----/i;
41
+
33
42
  const MASK = '***';
34
43
 
35
44
  /**
@@ -37,7 +46,7 @@ const MASK = '***';
37
46
  *
38
47
  * A value is masked when its key matches {@link SECRET_KEY_PATTERN} or appears in `extraSecretKeys`.
39
48
  * Additionally, any string that looks like a credentialed connection URI has its password segment
40
- * masked regardless of key name.
49
+ * masked regardless of key name, and a string or `Buffer` holding a PEM private key is masked as a whole.
41
50
  *
42
51
  * @param value - the object/value to mask (not mutated)
43
52
  * @param extraSecretKeys - additional exact key names to always mask (e.g. `security.secretFields`)
@@ -69,6 +78,9 @@ function maskValue(value: unknown, keyIsSecret: boolean, extra: Set<string>): un
69
78
  if (keyIsSecret) {
70
79
  return MASK;
71
80
  }
81
+ if (typeof value === 'string' && PRIVATE_KEY_PEM_PATTERN.test(value)) {
82
+ return MASK;
83
+ }
72
84
  return typeof value === 'string' ? maskString(value) : value;
73
85
  }
74
86
 
@@ -78,9 +90,10 @@ function maskValue(value: unknown, keyIsSecret: boolean, extra: Set<string>): un
78
90
  }
79
91
 
80
92
  // Preserve non-plain objects verbatim (Date, Buffer, etc.) — cloning would lose their type and
81
- // they never carry framework secrets.
93
+ // they never carry framework secrets — unless a Buffer holds a PEM private key (`readFileSync('key.pem')`
94
+ // without an encoding, which JSON would print byte by byte).
82
95
  if (value instanceof Date || Buffer.isBuffer(value)) {
83
- return value;
96
+ return Buffer.isBuffer(value) && PRIVATE_KEY_PEM_PATTERN.test(value.toString('latin1')) ? MASK : value;
84
97
  }
85
98
 
86
99
  if (Array.isArray(value)) {
@@ -8,14 +8,14 @@
8
8
 
9
9
  ## Do You Need This Checklist?
10
10
 
11
- | Scenario | Action Needed |
12
- | ---------------------------------------------------- | ----------------------------------------------- |
13
- | Local development / e2e suites (`local`, `ci`, `e2e`) | None - the init endpoint is open there by default |
14
- | A deployed stage needs its first admin (11.46.0+) | Set ENV variables (Step 1) - the HTTP init is closed there by default |
15
- | A deployed stage must be set up through a UI form | Step 1b (setup token) |
16
- | Automated deployment (Docker/CI) needs auto-creation | Set ENV variables (Step 1) |
17
- | Want to disable system setup | Set `systemSetup: { enabled: false }` in config |
18
- | Custom setup logic (extra fields, notifications) | Step 2 (Custom Controller) |
11
+ | Scenario | Action Needed |
12
+ | ----------------------------------------------------- | --------------------------------------------------------------------- |
13
+ | Local development / e2e suites (`local`, `ci`, `e2e`) | None - the init endpoint is open there by default |
14
+ | A deployed stage needs its first admin (11.46.0+) | Set ENV variables (Step 1) - the HTTP init is closed there by default |
15
+ | A deployed stage must be set up through a UI form | Step 1b (setup token) |
16
+ | Automated deployment (Docker/CI) needs auto-creation | Set ENV variables (Step 1) |
17
+ | Want to disable system setup | Set `systemSetup: { enabled: false }` in config |
18
+ | Custom setup logic (extra fields, notifications) | Step 2 (Custom Controller) |
19
19
 
20
20
  ---
21
21
 
@@ -197,12 +197,12 @@ NEST_SERVER_CONFIG='{ "systemSetup": { "initialAdmin": { "email": "admin@example
197
197
  Since 11.46.0 (backport of 12.4.0) the anonymous init is fail-closed outside the local environments: whoever reaches
198
198
  an API without users through it would become its administrator.
199
199
 
200
- | `systemSetup.httpInit` | `local` / `ci` / `e2e` | every other environment |
201
- |---|---|---|
202
- | not set | open | **closed** — 403 `LTNS_0053` |
203
- | `true` (`NSC__SYSTEM_SETUP__HTTP_INIT=true`) | open | open, without a token |
204
- | `{ token }` (`NSC__SYSTEM_SETUP__HTTP_INIT__TOKEN`, at least 16 characters) | open, token required | open, token required |
205
- | `false` / `{ enabled: false }` | closed | closed |
200
+ | `systemSetup.httpInit` | `local` / `ci` / `e2e` | every other environment |
201
+ | --------------------------------------------------------------------------- | ---------------------- | ---------------------------- |
202
+ | not set | open | **closed** — 403 `LTNS_0053` |
203
+ | `true` (`NSC__SYSTEM_SETUP__HTTP_INIT=true`) | open | open, without a token |
204
+ | `{ token }` (`NSC__SYSTEM_SETUP__HTTP_INIT__TOKEN`, at least 16 characters) | open, token required | open, token required |
205
+ | `false` / `{ enabled: false }` | closed | closed |
206
206
 
207
207
  The environment is the configured `env`, but where that is local only because 11.x fell back to the `local` block (a
208
208
  `NODE_ENV` without a block of its own, or an empty one), `NODE_ENV` decides — such a stage counts as deployed
@@ -17,6 +17,7 @@ import mongoose from 'mongoose';
17
17
 
18
18
  import { MongooseCastErrorFilter } from './core/common/filters/mongoose-cast-error.filter';
19
19
  import { merge } from './core/common/helpers/config.helper';
20
+ import { processGraphQlUploadRequest } from './core/common/helpers/graphql-upload.helper';
20
21
  import { registerWsConnection } from './core/common/helpers/graphql-ws-connection.helper';
21
22
  import {
22
23
  buildRequestContextAwareExecute,
@@ -111,7 +112,10 @@ export class CoreModule implements NestModule {
111
112
  // config read here and the values there.
112
113
  consumer.apply(SecurityHeadersMiddleware).forRoutes('*');
113
114
  if (CoreModule.graphQlEnabled) {
114
- consumer.apply(graphqlUploadExpress()).forRoutes('graphql');
115
+ // The framework's processRequest, never graphql-upload's default: the default (graphql-upload < 18.0.2) lets
116
+ // one anonymous multipart request crash the process (GHSA-5vm7-vc2x-p3w2) and leaks temporary files on
117
+ // duplicate file fields (GHSA-qwwm-252j-9whw). This middleware runs before any authentication.
118
+ consumer.apply(graphqlUploadExpress({ processRequest: processGraphQlUploadRequest })).forRoutes('graphql');
115
119
  }
116
120
  }
117
121
 
package/src/index.ts CHANGED
@@ -30,6 +30,7 @@ export * from './core/common/enums/sort-order.emum';
30
30
  export * from './core/common/exceptions/access-denied.exception';
31
31
  export * from './core/common/filters/http-exception-log.filter';
32
32
  export * from './core/common/filters/mongoose-cast-error.filter';
33
+ export * from './core/common/helpers/byte-range.helper';
33
34
  export * from './core/common/helpers/common.helper';
34
35
  export * from './core/common/helpers/config.helper';
35
36
  export * from './core/common/helpers/content-disposition.helper';
@@ -42,6 +43,7 @@ export * from './core/common/helpers/execution-context-request.helper';
42
43
  export * from './core/common/helpers/file.helper';
43
44
  export * from './core/common/helpers/filter.helper';
44
45
  export * from './core/common/helpers/graphql.helper';
46
+ export * from './core/common/helpers/graphql-upload.helper';
45
47
  export * from './core/common/helpers/graphql-ws-connection.helper';
46
48
  export * from './core/common/helpers/graphql-ws-context.helper';
47
49
  export * from './core/common/helpers/interceptor.helper';
@@ -205,10 +205,11 @@ await fs.promises.writeFile('/tmp/downloaded.bin', buffer);
205
205
 
206
206
  The second parameter accepts either a plain token string or a `TestDownloadOptions` object:
207
207
 
208
- | Option | Type | Description |
209
- | --------- | -------- | ------------------------------------------------------------- |
210
- | `token` | `string` | Bearer token via Authorization header (JWT) |
211
- | `cookies` | `string` | Plain session token, converted via `buildBetterAuthCookies()` |
208
+ | Option | Type | Description |
209
+ | --------- | ------------------------ | ------------------------------------------------------------- |
210
+ | `token` | `string` | Bearer token via Authorization header (JWT) |
211
+ | `cookies` | `string` | Plain session token, converted via `buildBetterAuthCookies()` |
212
+ | `headers` | `Record<string, string>` | Additional request headers, e.g. `Range` (since 11.46.5) |
212
213
 
213
214
  Both can be used simultaneously — `token` sets the Authorization header while `cookies` sets the Cookie header.
214
215
 
@@ -224,6 +225,9 @@ await testHelper.download('/files/id/abc123', { cookies: sessionToken });
224
225
 
225
226
  // Both simultaneously
226
227
  await testHelper.download('/files/id/abc123', { cookies: sessionToken, token: jwtToken });
228
+
229
+ // A byte range: 206, `Content-Range: bytes 0-1/<length>`, two bytes in `res.data`
230
+ const res = await testHelper.download('/files/id/abc123', { headers: { Range: 'bytes=0-1' }, token: jwtToken });
227
231
  ```
228
232
 
229
233
  ## GraphQL Testing (`testHelper.graphQl()`)
@@ -189,6 +189,12 @@ export interface TestDownloadOptions {
189
189
  */
190
190
  cookies?: string;
191
191
 
192
+ /**
193
+ * Additional request headers, e.g. `{ Range: 'bytes=0-1' }` for a ranged download or `If-None-Match`.
194
+ * Set before `cookies` and `token`, which win for their own header. Since 11.46.5.
195
+ */
196
+ headers?: Record<string, string>;
197
+
192
198
  /**
193
199
  * Bearer token via Authorization header (JWT authentication).
194
200
  * Can be used simultaneously with `cookies` — token sets the Authorization header
@@ -379,6 +385,9 @@ export class TestHelper {
379
385
  if (typeof tokenOrOptions === 'string') {
380
386
  request.set('Authorization', `bearer ${tokenOrOptions}`);
381
387
  } else if (tokenOrOptions) {
388
+ for (const [name, value] of Object.entries(tokenOrOptions.headers ?? {})) {
389
+ request.set(name, value);
390
+ }
382
391
  if (tokenOrOptions.cookies) {
383
392
  const cookieRecord = TestHelper.buildBetterAuthCookies(tokenOrOptions.cookies);
384
393
  request.set(
@@ -424,6 +433,9 @@ export class TestHelper {
424
433
  if (typeof tokenOrOptions === 'string') {
425
434
  request.set('Authorization', `bearer ${tokenOrOptions}`);
426
435
  } else if (tokenOrOptions) {
436
+ for (const [name, value] of Object.entries(tokenOrOptions.headers ?? {})) {
437
+ request.set(name, value);
438
+ }
427
439
  if (tokenOrOptions.cookies) {
428
440
  const cookieRecord = TestHelper.buildBetterAuthCookies(tokenOrOptions.cookies);
429
441
  request.set(
@@ -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