@bymax-one/nest-storage 1.1.7 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -13,6 +13,38 @@ note on each entry is the compatibility contract — read it, not the number.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [1.1.9] - 2026-11-09
17
+
18
+ ### Fixed
19
+
20
+ - **The MIME whitelist now refuses control and non-ASCII characters in the parameter part of a
21
+ content type.** The parameters after `;` were accepted if they held no comma and no line break, so
22
+ a value such as `text/plain; charset=café` or one with a NUL passed the whitelist, although
23
+ RFC 9110 field values are tab, space and printable ASCII (obsolete text aside). The parameter part
24
+ may now hold only tab, space and printable ASCII other than the comma.
25
+
26
+ **Apply to a derived backend:** with `validation.mimeWhitelist` set, a `contentType` whose
27
+ parameters hold any other character now fails with `STORAGE_MIME_NOT_ALLOWED`. A type with
28
+ ordinary parameters, such as `text/plain; charset=utf-8`, is unaffected. Without a whitelist
29
+ nothing changes: the value is passed on as given.
30
+
31
+ ## [1.1.8] - 2026-11-06
32
+
33
+ ### Fixed
34
+
35
+ - **The MIME whitelist no longer accepts a value that lists several types.** The check compared only
36
+ the text before the first `;`, while the whole value was signed or stored, so with a whitelist of
37
+ `image/png`, `image/png;,text/html`, `image/png; charset=x, text/html` and, under `image/*`,
38
+ `image/png,text/html` all passed. A browser reads such a header as a list and takes the last valid
39
+ type, so the object could be served as `text/html`. The check now accepts only one `type/subtype`
40
+ (RFC 9110 token characters) with optional parameters, and no comma or line break anywhere in the
41
+ value.
42
+
43
+ **Apply to a derived backend:** a `contentType` that is a list, or is not a plain `type/subtype`,
44
+ now fails with `STORAGE_MIME_NOT_ALLOWED` when `validation.mimeWhitelist` is set, including under
45
+ `*/*`. A single type with parameters, such as `text/plain; charset=utf-8`, is unaffected. Without
46
+ a whitelist nothing changes: the value is stored as given.
47
+
16
48
  ## [1.1.7] - 2026-11-06
17
49
 
18
50
  ### Fixed
@@ -605,4 +637,6 @@ have regressed from. They are kept because the reasoning is worth having.
605
637
  [1.1.5]: https://github.com/bymaxone/nest-storage/compare/v1.1.4...v1.1.5
606
638
  [1.1.6]: https://github.com/bymaxone/nest-storage/compare/v1.1.5...v1.1.6
607
639
  [1.1.7]: https://github.com/bymaxone/nest-storage/compare/v1.1.6...v1.1.7
608
- [Unreleased]: https://github.com/bymaxone/nest-storage/compare/v1.1.7...HEAD
640
+ [1.1.8]: https://github.com/bymaxone/nest-storage/compare/v1.1.7...v1.1.8
641
+ [1.1.9]: https://github.com/bymaxone/nest-storage/compare/v1.1.8...v1.1.9
642
+ [Unreleased]: https://github.com/bymaxone/nest-storage/compare/v1.1.9...HEAD
package/README.md CHANGED
@@ -274,7 +274,7 @@ The full configuration reference lives in `docs/technical_specification.md` §4.
274
274
  | `multipart.thresholdBytes` | `number` | `5 MiB` | Switch to multipart at or above this size |
275
275
  | `multipart.partSizeBytes` | `number` | `5 MiB` | Part size (S3 minimum: 5 MiB) |
276
276
  | `multipart.queueSize` | `number` | `4` | Concurrent parts |
277
- | `validation.mimeWhitelist` | `string[]` | — | No MIME check when absent. Wildcards: `'image/*'` |
277
+ | `validation.mimeWhitelist` | `string[]` | — | No MIME check when absent. Wildcards: `'image/*'`. A value that lists several types never matches |
278
278
  | `validation.maxSizeBytes` | `number` | — | Maximum upload size in bytes |
279
279
 
280
280
  > **Do not use `maxRetries` or `signatureVersion`** — these are AWS SDK v2 options that do not exist in v3. The v3 SDK is SigV4-only. Use `maxAttempts` (default `3`) for retry configuration.
@@ -824,15 +824,13 @@ async function readStreamUpTo(source, maxBytes) {
824
824
  }
825
825
 
826
826
  // src/server/utils/mime-match.ts
827
+ var SINGLE_MEDIA_TYPE = /^[ \t]*[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+[ \t]*(?:;[\t \x21-\x2B\x2D-\x7E]*)?$/;
827
828
  function mimeMatches(mime, whitelist) {
828
- if (typeof mime !== "string") {
829
+ if (typeof mime !== "string" || !SINGLE_MEDIA_TYPE.test(mime)) {
829
830
  return false;
830
831
  }
831
832
  const mimeBase = mime.includes(";") ? mime.slice(0, mime.indexOf(";")) : mime;
832
833
  const normalized = mimeBase.trim().toLowerCase();
833
- if (normalized.length === 0 || !normalized.includes("/")) {
834
- return false;
835
- }
836
834
  const slashIdx = normalized.indexOf("/");
837
835
  const type = normalized.slice(0, slashIdx);
838
836
  for (const rawPattern of whitelist) {
@@ -843,13 +841,8 @@ function mimeMatches(mime, whitelist) {
843
841
  if (pattern === "*/*") {
844
842
  return true;
845
843
  }
846
- const patSlash = pattern.indexOf("/");
847
- if (patSlash !== -1) {
848
- const patType = pattern.slice(0, patSlash);
849
- const patSubtype = pattern.slice(patSlash + 1);
850
- if (patSubtype === "*" && patType === type) {
851
- return true;
852
- }
844
+ if (pattern.endsWith("/*") && pattern.slice(0, -2) === type) {
845
+ return true;
853
846
  }
854
847
  }
855
848
  return false;
@@ -822,15 +822,13 @@ async function readStreamUpTo(source, maxBytes) {
822
822
  }
823
823
 
824
824
  // src/server/utils/mime-match.ts
825
+ var SINGLE_MEDIA_TYPE = /^[ \t]*[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+[ \t]*(?:;[\t \x21-\x2B\x2D-\x7E]*)?$/;
825
826
  function mimeMatches(mime, whitelist) {
826
- if (typeof mime !== "string") {
827
+ if (typeof mime !== "string" || !SINGLE_MEDIA_TYPE.test(mime)) {
827
828
  return false;
828
829
  }
829
830
  const mimeBase = mime.includes(";") ? mime.slice(0, mime.indexOf(";")) : mime;
830
831
  const normalized = mimeBase.trim().toLowerCase();
831
- if (normalized.length === 0 || !normalized.includes("/")) {
832
- return false;
833
- }
834
832
  const slashIdx = normalized.indexOf("/");
835
833
  const type = normalized.slice(0, slashIdx);
836
834
  for (const rawPattern of whitelist) {
@@ -841,13 +839,8 @@ function mimeMatches(mime, whitelist) {
841
839
  if (pattern === "*/*") {
842
840
  return true;
843
841
  }
844
- const patSlash = pattern.indexOf("/");
845
- if (patSlash !== -1) {
846
- const patType = pattern.slice(0, patSlash);
847
- const patSubtype = pattern.slice(patSlash + 1);
848
- if (patSubtype === "*" && patType === type) {
849
- return true;
850
- }
842
+ if (pattern.endsWith("/*") && pattern.slice(0, -2) === type) {
843
+ return true;
851
844
  }
852
845
  }
853
846
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-storage",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Provider-agnostic S3-compatible object storage for NestJS. Works with AWS S3, DigitalOcean Spaces, Cloudflare R2, Backblaze B2, MinIO, Wasabi.",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",
@@ -48,6 +48,7 @@
48
48
  "check:api": "node scripts/check-api-surface.mjs",
49
49
  "check:exports": "attw --pack . --profile strict",
50
50
  "check:mutants": "node scripts/check-mutation-directives.mjs",
51
+ "check:file-length": "node scripts/check-file-length.mjs",
51
52
  "check:published": "node scripts/check-published-surface.mjs",
52
53
  "check:runtime": "node scripts/check-consumer-runtime.mjs",
53
54
  "clean": "rm -rf dist coverage",