@bymax-one/nest-logger 1.4.28 → 1.4.29

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
@@ -12,6 +12,67 @@ heading here.
12
12
 
13
13
  ## [Unreleased]
14
14
 
15
+ ## [1.4.29] - 2026-11-21
16
+
17
+ ### Fixed
18
+
19
+ - **Only the key `message` is left to the serializer of `err`.** A field of the object under `err` that
20
+ only spells it (`Message`, a zero-width character inside it, a look-alike letter) is a field like any
21
+ other and is hidden when `message` is a name to hide.
22
+ - **A configured name hides a field however its key is spelled.** The names of `redactPaths`, the
23
+ default names and the leaves of a configured path were compared with a key by exact name, in lower
24
+ case, so a field spelled with a zero-width character, a soft hyphen, a byte order mark, fullwidth
25
+ letters, a no-break space, a tab, a trailing space, a Cyrillic letter, a combining mark, a dotless
26
+ `i` or a separator (`api_key`, `api.Key`) was written in clear under `redactStrategy: 'names'`. Both
27
+ sides are now folded with the folding the library's own keys use (separators folded too), also for the
28
+ header names of a flat `rawHeaders` array. A name that is another word (`apiKeys` for `apiKey`) is
29
+ still another name. Every character that is not a letter or a digit is dropped from both sides (so
30
+ `x\u2011api\u2011key`, `access\u2010token`, `api\u2212key` and `pass:word` are `xapikey`, `accesstoken`, `apikey`
31
+ and `password`), and every letter that is not ASCII and that the look-alike list does not read as one Latin letter
32
+ stands for one or for two letters of a name (`ß`, `ꜷ` and `ꝏ` are two; a capital Cyrillic or Greek i,
33
+ drawn like an `I` and an `l`, is one): a key with such letters is hidden by any name it matches
34
+ everywhere else, which can hide the value of a key that only shares a name's ASCII letters and a
35
+ compatible length. The rule holds for a key made only of letters of another script too, as long as it
36
+ is no longer than the longest name: a spelling of `token` in Cyrillic and Armenian letters is hidden,
37
+ and so is a short field written in words of another script, which is the price of never letting a
38
+ spelling through. A key longer than every name is never taken for one (a configured name written in
39
+ that script still matches itself exactly), and a key with more candidate names of a compatible length
40
+ than a bound is hidden without being compared. This is for hiding a value only: the keys the entry owns, the keys
41
+ its derived fields use and the keys of the mixin are compared exactly after folding, so a caller
42
+ field written with such letters is not dropped for resembling one of them. Under `redactStrategy: 'paths'` the paths are matched exactly by `fast-redact`
43
+ and are not folded.
44
+ - **The stack header is hidden against every key that spells `message` or `stack`.** An object with
45
+ `{ message: 'x', Message: secret, stack: 'Error: secret' }`, or a `stack` beside a `Stack`, kept the
46
+ secret in a header: only the first key that spelled the name was read. Every one is read, once, and
47
+ every distinct text is hidden in every stack, longest first. The 1.4.27 line "whatever the case or
48
+ the look of the two keys" held for a single key of each name only.
49
+ - **More characters that print as nothing, and more letters and dots drawn like another, are read
50
+ through:** the Hangul fillers and the blank Braille pattern, the characters drawn like a full stop
51
+ (`U+3002`, `U+00B7`, `U+22C5` and others) and a few more letters drawn like a Latin one, in the
52
+ comparison of the derived keys, of the owned keys and of the configured names. The list of drawn
53
+ letters is a list, not every look-alike Unicode has.
54
+ - **A message the options hide is hidden wherever a stack repeats it.** Only the header of a stack was
55
+ rewritten, so a library that appends `Caused by: Error: <message>` left the text readable in the first
56
+ 16 KiB of `err.stack`, of the stack of a cause and of `exception.stacktrace`. Every occurrence of the
57
+ message in the part of the stack that is read is replaced now, for an `Error`, an `Error` whose name is
58
+ not text, a cause and an object that is no `Error`. A message short enough to appear in a frame is
59
+ replaced there too.
60
+ - **The `stack` of an object that is no `Error` is bounded and scrubbed at any depth.** A nested plain
61
+ object with a `stack` was written whole, up to its full length and with its dependency frames and
62
+ control characters. It is read up to the same bound as the stack of an error, written without
63
+ `node_modules` frames and with control characters escaped, and cut at the text limit with the suffix.
64
+ The name and the message of such an object are still written as given.
65
+ - **The search for hidden messages in the stacks of one object is bounded.** An object with more than
66
+ eight distinct messages under keys that spell `message`, or more than eight keys that spell `stack`,
67
+ has every stack written as the censor instead of searched, so a payload of thousands of look-alike
68
+ keys cannot stall the event loop.
69
+ - **A list option whose length is not a count is refused.** A Proxy that reports `-1`, `NaN`, `1.5` or
70
+ an infinite length was read as empty; it is refused by the name of the option.
71
+ - **A list option is capped at 10,000 entries.** `redactPaths`, `errorOwnFieldNames`, `destinations`,
72
+ `http.excludePaths` and `http.secretPathSegments` longer than that are refused at startup, by the
73
+ name of the option, before an element is read; a length a host reports as a billion no longer
74
+ allocates.
75
+
15
76
  ## [1.4.28] - 2026-11-21
16
77
 
17
78
  ### Fixed
@@ -3408,7 +3469,8 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
3408
3469
  - Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
3409
3470
  `release.yml`, Dependabot, and issue templates
3410
3471
 
3411
- [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.28...HEAD
3472
+ [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.29...HEAD
3473
+ [1.4.29]: https://github.com/bymaxone/nest-logger/compare/v1.4.28...v1.4.29
3412
3474
  [1.4.28]: https://github.com/bymaxone/nest-logger/compare/v1.4.27...v1.4.28
3413
3475
  [1.4.27]: https://github.com/bymaxone/nest-logger/compare/v1.4.26...v1.4.27
3414
3476
  [1.4.26]: https://github.com/bymaxone/nest-logger/compare/v1.4.25...v1.4.26
package/README.md CHANGED
@@ -879,7 +879,7 @@ The library censors **62 sensitive field names** wherever they appear in a recor
879
879
  | Other spellings | `access_token`, `refresh_token`, `id_token`, `api_key`, `apikey`, `api_secret`, `client_secret`, `signing_secret`, `private_key`, `secret_key`, `secretKey`, `access-token`, `refresh-token`, `id-token`, `api-key`, `client-secret`, `private-key`, `proxy-authorization`, `session_token`, `sessionToken`, `sessiontoken`, `session-token`, `x-csrf-token`, `x-xsrf-token`, `csrf_token`, `csrfToken`, `csrf-token`, `password_hash`, `new_password`, `old_password` |
880
880
  | HTTP headers (absolute) | `req.headers.authorization`, `req.headers.cookie`, `req.headers["x-api-key"]`, `req.headers["x-auth-token"]`, `res.headers["set-cookie"]` — retained for the legacy `'paths'` strategy; the by-name row above already covers these shapes and every other |
881
881
 
882
- Redaction is one **recursive, snapshotting walk**: a value is censored when its key name is in the set, wherever it sits. Nothing the caller passed is mutated, and every value is read once and pinned into a fresh structure, so what reaches the sink is what was inspected even when the payload carries accessors or a `toJSON` that could answer differently on a second read. A value with a `toJSON` is inspected through that method's output; when the source object itself carries a sensitive key, the method is not trusted and the whole value is censored, because a method could rename what it exposes. `DEFAULT_REDACT_PATHS` is still exported at full fidelity, and `redactStrategy: 'paths'` feeds it to `fast-redact` for anyone depending on exact path semantics, with a four-level ceiling and a much higher cost.
882
+ Redaction is one **recursive, snapshotting walk**: a value is censored when its key name is in the set, wherever it sits. A name and a key are compared in one folded form: the case, every character that is not a letter or a digit (the separators `_`, `.` and `-` and every other dash, mark and punctuation), white space, control and zero-width characters, combining marks, the compatibility forms Unicode defines and a list of letters drawn like a Latin one are read through, and a letter that is not ASCII and that the list does not read as one Latin letter stands for one or two letters (in a key no longer than the longest name; a key longer than every name is never taken for one, so a field of another script is hidden when it is short, which is the price of never letting a spelling of a name through, and kept when it is long), so a key that has one is hidden by a name it matches everywhere else; the keys the entry owns are compared exactly after folding, so a caller field is never dropped for looking like one, so a key that has one is hidden by a name of a compatible length that matches it everywhere else (`autһorization` is hidden by `authorization`, and a key of the same length that only shares its ASCII letters is hidden too), so `apiKey` also hides `api_key`, `API-KEY`, `api\u200bKey` and `\u0430piKey`, and a name hides the field however an untrusted payload spells it. A key that spells a configured name another way is the same name, so a field whose name only differs in those ways is hidden too. Under `redactStrategy: 'paths'` the paths are matched exactly by `fast-redact`: literally, with no folding of case, separators or look-alikes, and none of this applies. Nothing the caller passed is mutated, and every value is read once and pinned into a fresh structure, so what reaches the sink is what was inspected even when the payload carries accessors or a `toJSON` that could answer differently on a second read. A value with a `toJSON` is inspected through that method's output; when the source object itself carries a sensitive key, the method is not trusted and the whole value is censored, because a method could rename what it exposes. `DEFAULT_REDACT_PATHS` is still exported at full fidelity, and `redactStrategy: 'paths'` feeds it to `fast-redact` for anyone depending on exact path semantics, with a four-level ceiling and a much higher cost.
883
883
 
884
884
  > [!NOTE]
885
885
  > A bare `sessionId`, `session_id` or `session-id` is **not** on the list: many applications carry one as a correlation key, and a name cannot be switched off one at a time. A session id that is itself a bearer credential in your system must be added to your own `redactPaths` (`redactPaths: ['sessionId']` censors it at any depth under the default strategy).
@@ -1066,7 +1066,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
1066
1066
  | `fatal` | `(message, ...optionalParams)` | → Pino `fatal` |
1067
1067
  | `error` | `(message \| Error, stack?, context?)` | An `Error` routes to the serialized `err` path |
1068
1068
 
1069
- **An object as the message.** A plain object (an object literal or a parsed JSON object) passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal` is written as the fields of the entry, through the same redaction and `maxStringLength` pipeline as any other field, so `this.logger.warn({ event: 'QUEUE_DRAINED', jobs: 7, password })` gives an entry with `event`, `jobs` and a censored `password`. The entry text (`msg`) is its `message` string, else its `event` string, else empty; a `message` that is the text is not repeated as a field. `logKey`, `userId`, `context`, `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` in the object are dropped, as they are from `meta`. The text is censored under the names of the field it came from (`event` or `message`), also with `redactStrategy: 'paths'`, and cut at `maxStringLength` like that field, within the 16 KiB cap that bounds every log message. A serializer keyed `event` or `message` shapes the field and not `msg`; redaction by name is what covers the text. An `Error`, and an object shaped like one (a string `name` and a string `message`), keep their own error-only path (the text of the entry is the `message`, censored under the name `message` as `err.message` is, and the same text is censored where it opens `err.stack`, the stack of each cause and `exception.stacktrace`, and in `exception.message`; like every log message it is capped at 16 KiB and not cut at `maxStringLength`), and a value that is not plain (a class instance, an array) is still written as its string form. An object that is no error to the library but carries a `message` and a `stack` that are text has the message hidden in the header of that `stack`, everything before its first frame, wherever the options hide `message`; the frames are the stack's own text, and this holds for such an object below the top level of the record as well. A `name` that is an object, an array or a function is hidden with the message, as it may carry anything, and a number `name` is kept. The keys the library owns (`exception.type`, `exception.message`, `exception.stacktrace`, `error.type`) are matched as they look in a viewer: the same key in another case, with white space, combining marks or zero-width characters inside it, in fullwidth letters, or with a letter of another script drawn like a Latin one is dropped too, while `errorType`, `exception_type`, `exceptionType` and `event.name` are other keys and are kept. An object whose `toJSON` returns a `message` that is not text and a `stack` carrying a secret that is not the message text leaves nothing to match, so name such a secret in `redactPaths`. Redaction works on field names and never reads the content of a string, so a text a caller passes as a string, such as ``logger.warn(`card ${number}`)``, is written as it is.
1069
+ **An object as the message.** A plain object (an object literal or a parsed JSON object) passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal` is written as the fields of the entry, through the same redaction and `maxStringLength` pipeline as any other field, so `this.logger.warn({ event: 'QUEUE_DRAINED', jobs: 7, password })` gives an entry with `event`, `jobs` and a censored `password`. The entry text (`msg`) is its `message` string, else its `event` string, else empty; a `message` that is the text is not repeated as a field. `logKey`, `userId`, `context`, `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` in the object are dropped, as they are from `meta`. The text is censored under the names of the field it came from (`event` or `message`), also with `redactStrategy: 'paths'`, and cut at `maxStringLength` like that field, within the 16 KiB cap that bounds every log message. A serializer keyed `event` or `message` shapes the field and not `msg`; redaction by name is what covers the text. An `Error`, and an object shaped like one (a string `name` and a string `message`), keep their own error-only path (the text of the entry is the `message`, censored under the name `message` as `err.message` is, and the same text is censored where it opens `err.stack`, the stack of each cause and `exception.stacktrace`, and in `exception.message`; like every log message it is capped at 16 KiB and not cut at `maxStringLength`), and a value that is not plain (a class instance, an array) is still written as its string form. An object that is no error to the library but carries a `message` and a `stack` that are text has the message hidden in the header of that `stack`, everything before its first frame, wherever the options hide `message`; the message is hidden wherever the stack repeats it (a `Caused by:` line, a frame), within the part of the stack that is read, and this holds for such an object below the top level of the record as well. The `stack` of any object that is no `Error`, at any depth, is written like the stack of an error: without dependency frames, with control characters escaped and cut at the text limit. An object with more than eight distinct messages under keys that spell `message`, or more than eight keys that spell `stack`, has every stack written as the censor. A `name` that is an object, an array or a function is hidden with the message, as it may carry anything, and a number `name` is kept. The keys the library owns (`exception.type`, `exception.message`, `exception.stacktrace`, `error.type`) are matched as they look in a viewer: the same key in another case, with white space, combining marks, zero-width characters or characters that print as nothing inside it, in fullwidth letters, or with a letter of another script drawn like a Latin one is dropped too, while `errorType`, `exception_type`, `exceptionType` and `event.name` are other keys and are kept. An object whose `toJSON` returns a `message` that is not text and a `stack` carrying a secret that is not the message text leaves nothing to match, so name such a secret in `redactPaths`. Redaction works on field names and never reads the content of a string, so a text a caller passes as a string, such as ``logger.warn(`card ${number}`)``, is written as it is.
1070
1070
 
1071
1071
  **Helpers**
1072
1072
 
@@ -1237,18 +1237,20 @@ Two kinds of failure, and they surface differently. A **thrown `Error`** carries
1237
1237
 
1238
1238
  ### Thrown errors
1239
1239
 
1240
- | Message starts with | Thrown from | When | Action |
1241
- | -------------------------------------------------------- | ------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
1242
- | `[BymaxLoggerModule] options.` | `forRoot` / `forRootAsync`, at module setup | any option fails validation: a missing `service`, a `level` outside the set, a bad type | Fix the option the message names; it prints the path and what it received |
1243
- | `[BymaxLoggerModule] options could not be read` | `forRoot` / `forRootAsync`, at module setup | an option the host supplies threw when it was read (a getter or a Proxy trap) | Fix the option; the error the host threw is the `cause` |
1244
- | `[BymaxLoggerModule] useNestLogger(app) called but` | `BymaxLoggerModule.useNestLogger` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
1245
- | `[BymaxLoggerModule] applyAccessLog(app) called but` | `applyAccessLog` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
1246
- | `[BymaxLoggerModule] useRequestContext(app) called but` | `useRequestContext` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
1247
- | `[PrettyDevDestination] pino-pretty is not installed` | `PrettyDevDestination.onInit` | the destination is registered and resolving `pino-pretty` itself fails | Install `pino-pretty` or drop the destination |
1248
- | `[PrettyDevDestination] pino-pretty failed to start` | `PrettyDevDestination.onInit` | `pino-pretty` is found but importing it or building the transform throws | Read the message and the error's `cause`: it is the real failure |
1249
- | `[PrettyDevDestination] refused in production` | `PrettyDevDestination.onInit` | `NODE_ENV` is exactly `production` | Use `DefaultStdoutDestination` in production |
1250
- | `[LogContextService] set() called outside run() scope` | `LogContextService.set` | called with no active `run()` | Wrap the work in `logContext.run({ ... }, () => ...)` |
1251
- | `[LogContextService] Refusing to set unsafe context key` | `LogContextService.set` | the key is `__proto__`, `constructor` or `prototype` | Use an ordinary key |
1240
+ | Message starts with | Thrown from | When | Action |
1241
+ | -------------------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
1242
+ | `[BymaxLoggerModule] options.` | `forRoot` / `forRootAsync`, at module setup | any option fails validation: a missing `service`, a `level` outside the set, a bad type | Fix the option the message names; it prints the path and what it received |
1243
+ | `[BymaxLoggerModule] options could not be read` | `forRoot` / `forRootAsync`, at module setup | an option the host supplies threw when it was read (a getter or a Proxy trap) | Fix the option; the error the host threw is the `cause` |
1244
+ | `holds more than` | `forRoot` / `forRootAsync`, at module setup | a list option (`redactPaths`, `errorOwnFieldNames`, `destinations`, `http.excludePaths`, `http.secretPathSegments`) is longer than 10,000 entries | Shorten the list; it is refused before any element is read |
1245
+ | `has a length that is not a count` | `forRoot` / `forRootAsync`, at module setup | a list option reports a length that is negative, fractional, `NaN` or infinite (a Proxy; an array never does) | Fix the option; it is refused before any element is read |
1246
+ | `[BymaxLoggerModule] useNestLogger(app) called but` | `BymaxLoggerModule.useNestLogger` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
1247
+ | `[BymaxLoggerModule] applyAccessLog(app) called but` | `applyAccessLog` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
1248
+ | `[BymaxLoggerModule] useRequestContext(app) called but` | `useRequestContext` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
1249
+ | `[PrettyDevDestination] pino-pretty is not installed` | `PrettyDevDestination.onInit` | the destination is registered and resolving `pino-pretty` itself fails | Install `pino-pretty` or drop the destination |
1250
+ | `[PrettyDevDestination] pino-pretty failed to start` | `PrettyDevDestination.onInit` | `pino-pretty` is found but importing it or building the transform throws | Read the message and the error's `cause`: it is the real failure |
1251
+ | `[PrettyDevDestination] refused in production` | `PrettyDevDestination.onInit` | `NODE_ENV` is exactly `production` | Use `DefaultStdoutDestination` in production |
1252
+ | `[LogContextService] set() called outside run() scope` | `LogContextService.set` | called with no active `run()` | Wrap the work in `logContext.run({ ... }, () => ...)` |
1253
+ | `[LogContextService] Refusing to set unsafe context key` | `LogContextService.set` | the key is `__proto__`, `constructor` or `prototype` | Use an ordinary key |
1252
1254
 
1253
1255
  The `PrettyDevDestination` errors are thrown inside `onInit`, which the registry contains: the boot continues and the failure is reported as `LOGGER_DESTINATION_INIT_FAILED` below.
1254
1256
 
@@ -25,6 +25,23 @@ var __decorateClass = (decorators, target, key, kind) => {
25
25
  };
26
26
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
27
27
 
28
+ // src/server/config/options-refusal.util.ts
29
+ var refusals = /* @__PURE__ */ new WeakSet();
30
+ var UNREADABLE = "[BymaxLoggerModule] options could not be read";
31
+ function refuse(message) {
32
+ const error = new Error(message);
33
+ refusals.add(error);
34
+ throw error;
35
+ }
36
+ function guardOptions(read) {
37
+ try {
38
+ return read();
39
+ } catch (error) {
40
+ if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
41
+ throw new Error(UNREADABLE, { cause: error });
42
+ }
43
+ }
44
+
28
45
  // src/server/config/drop-unset-options.ts
29
46
  var OPTION_KEYS = {
30
47
  service: true,
@@ -83,11 +100,20 @@ function readSet(source, keys) {
83
100
  }
84
101
  var LIST_OPTIONS = ["redactPaths", "errorOwnFieldNames", "destinations"];
85
102
  var HTTP_LISTS = ["excludePaths", "secretPathSegments"];
86
- function copyLists(holder, names) {
103
+ var MAX_LIST_ENTRIES = 1e4;
104
+ function copyLists(holder, names, prefix) {
87
105
  for (const name of names) {
88
106
  const value = Reflect.get(holder, name);
89
107
  if (!Array.isArray(value)) continue;
90
108
  const length = Reflect.get(value, "length");
109
+ if (!Number.isInteger(length) || length < 0) {
110
+ refuse(`[BymaxLoggerModule] options.${prefix}${name} has a length that is not a count`);
111
+ }
112
+ if (length > MAX_LIST_ENTRIES) {
113
+ refuse(
114
+ `[BymaxLoggerModule] options.${prefix}${name} holds more than ${String(MAX_LIST_ENTRIES)} entries`
115
+ );
116
+ }
91
117
  Reflect.set(
92
118
  holder,
93
119
  name,
@@ -107,29 +133,12 @@ function dropUnsetOptions(options) {
107
133
  if (isRecord(service)) Reflect.set(set, "service", { ...service });
108
134
  const serializers = Reflect.get(set, "serializers");
109
135
  if (isRecord(serializers)) Reflect.set(set, "serializers", { ...serializers });
110
- copyLists(set, LIST_OPTIONS);
136
+ copyLists(set, LIST_OPTIONS, "");
111
137
  const http = Reflect.get(set, "http");
112
- if (isRecord(http)) copyLists(http, HTTP_LISTS);
138
+ if (isRecord(http)) copyLists(http, HTTP_LISTS, "http.");
113
139
  return set;
114
140
  }
115
141
 
116
- // src/server/config/options-refusal.util.ts
117
- var refusals = /* @__PURE__ */ new WeakSet();
118
- var UNREADABLE = "[BymaxLoggerModule] options could not be read";
119
- function refuse(message) {
120
- const error = new Error(message);
121
- refusals.add(error);
122
- throw error;
123
- }
124
- function guardOptions(read) {
125
- try {
126
- return read();
127
- } catch (error) {
128
- if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
129
- throw new Error(UNREADABLE, { cause: error });
130
- }
131
- }
132
-
133
142
  // src/server/constants/lifecycle-timeouts.constants.ts
134
143
  var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
135
144
  var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
@@ -650,49 +659,141 @@ function escapeControlCharacters(text) {
650
659
  }
651
660
 
652
661
  // src/server/utils/fold-key.util.ts
653
- var IGNORED = /[\s._\p{Cc}\p{Cf}\p{M}-]/gu;
654
- var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}]/gu;
662
+ var NOT_NAME = /[^\p{L}\p{N}]|[\u115f\u1160\u3164\uffa0]/gu;
663
+ var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}\u115f\u1160\u2800\u3164\uffa0]/gu;
664
+ var DOTS = /[\u3002\u0701\u06d4\u22c5\u00b7\ufe12]/gu;
655
665
  var PLAIN = /^[\x21-\x7e]*$/;
666
+ var NON_ASCII = /[^\x20-\x7e]/;
667
+ var NOT_ASCII_NAME = /[^A-Za-z0-9]/g;
656
668
  var LOOKALIKES = new Map(
657
669
  Object.entries({
658
670
  a: "\u0430\u03B1\u1D00",
659
671
  b: "\u0299",
660
- c: "\u0441\u03F2\u1D04",
672
+ c: "\u0441\u03F2\u1D04\u023C\u0188",
661
673
  d: "\u0501\u1D05",
662
- e: "\u0435\u03B5\u03F5\u1D07",
674
+ e: "\u0435\u03B5\u03F5\u1D07\u025B\u04BD",
663
675
  f: "\uA730",
664
676
  g: "\u0262",
665
677
  h: "\u029C",
666
- i: "\u0456\u03B9\u0131\u026A",
667
678
  j: "\u0458\u1D0A",
668
679
  k: "\u1D0B",
669
680
  l: "\u029F",
670
681
  m: "\u1D0D",
671
682
  n: "\u0274",
672
- o: "\u043E\u03BF\u1D0F",
673
- p: "\u0440\u03C1\u1D18",
683
+ o: "\u043E\u03BF\u1D0F\xF8",
684
+ p: "\u0440\u03C1\u1D18\u01BF",
674
685
  q: "\u051B",
675
686
  r: "\u0280",
676
687
  s: "\u0455\uA731",
677
- t: "\u1D1B",
688
+ t: "\u1D1B\u0167",
678
689
  u: "\u1D1C",
679
- v: "\u03BD\u1D20",
690
+ v: "\u1D20",
680
691
  w: "\u051D\u1D21",
681
692
  x: "\u0445",
682
- y: "\u0443\u028F",
693
+ y: "\u0443\u028F\u04AF",
683
694
  z: "\u1D22"
684
695
  }).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
685
696
  );
697
+ var I_LIKE = new Map(
698
+ [..."\u0456\u03B9\u0131\u026A\u0269"].map((letter) => [letter, "i"])
699
+ );
686
700
  function foldKey(key, keepSeparators = false) {
687
- const ignored = keepSeparators ? INVISIBLE : IGNORED;
688
- if (PLAIN.test(key)) return key.replace(ignored, "").toLowerCase();
689
- let folded = key.normalize("NFKD").toLowerCase().replace(ignored, "");
690
- for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
691
- return folded;
701
+ if (keepSeparators) {
702
+ if (PLAIN.test(key)) return key.toLowerCase();
703
+ return withLookalikes(
704
+ key.normalize("NFKD").toLowerCase().replace(DOTS, ".").replace(INVISIBLE, ""),
705
+ true
706
+ );
707
+ }
708
+ if (PLAIN.test(key)) return key.replace(NOT_ASCII_NAME, "").toLowerCase();
709
+ return withLookalikes(key.normalize("NFKD").toLowerCase().replace(NOT_NAME, ""), true);
710
+ }
711
+ function foldStrict(key) {
712
+ if (PLAIN.test(key)) return key.replace(NOT_ASCII_NAME, "").toLowerCase();
713
+ return withLookalikes(key.normalize("NFKD").toLowerCase().replace(NOT_NAME, ""), false);
714
+ }
715
+ function withLookalikes(folded, all) {
716
+ let read = folded;
717
+ for (const [letter, latin] of LOOKALIKES) read = read.replaceAll(letter, latin);
718
+ if (all) for (const [letter, latin] of I_LIKE) read = read.replaceAll(letter, latin);
719
+ return read;
720
+ }
721
+ var ALNUM = /^[A-Za-z0-9]*$/;
722
+ function formOf(key) {
723
+ return ALNUM.test(key) ? key.toLowerCase() : foldStrict(key);
724
+ }
725
+ var answers = /* @__PURE__ */ new WeakMap();
726
+ function foldName(key) {
727
+ return formOf(key);
728
+ }
729
+ function foldedNames(names) {
730
+ return new Set(Array.from(names, foldName).filter((name) => name !== ""));
731
+ }
732
+ var MAX_CANDIDATES = 64;
733
+ var grouped = /* @__PURE__ */ new WeakMap();
734
+ function groupsOf(names) {
735
+ let groups = grouped.get(names);
736
+ if (groups === void 0) {
737
+ const built = /* @__PURE__ */ new Map();
738
+ let longest = 0;
739
+ for (const name of names) {
740
+ const size = [...name].length;
741
+ const same = built.get(size);
742
+ if (same === void 0) built.set(size, [name]);
743
+ else same.push(name);
744
+ longest = Math.max(longest, size);
745
+ }
746
+ groups = { byLength: built, longest };
747
+ grouped.set(names, groups);
748
+ }
749
+ return groups;
750
+ }
751
+ function matchesFolded(names, folded) {
752
+ if (names.has(folded)) return true;
753
+ if (!NON_ASCII.test(folded)) return false;
754
+ const letters = [...folded];
755
+ const wide = letters.filter((letter) => !isAscii(letter)).length;
756
+ const { byLength, longest } = groupsOf(names);
757
+ if (letters.length > longest) return false;
758
+ const lengths = Array.from(
759
+ { length: wide + 1 },
760
+ (_, extra) => byLength.get(letters.length + extra) ?? []
761
+ );
762
+ if (lengths.reduce((count, same) => count + same.length, 0) > MAX_CANDIDATES) return true;
763
+ return lengths.some((same) => same.some((name) => matchesName(letters, [...name])));
764
+ }
765
+ var isAscii = (letter) => letter < "\x80";
766
+ function matchesName(letters, name) {
767
+ let at = /* @__PURE__ */ new Set([0]);
768
+ for (const letter of letters) {
769
+ const next = /* @__PURE__ */ new Set();
770
+ for (const position of at) {
771
+ if (isAscii(letter)) {
772
+ if (name[position] === letter) next.add(position + 1);
773
+ continue;
774
+ }
775
+ next.add(position + 1);
776
+ next.add(position + 2);
777
+ }
778
+ at = next;
779
+ }
780
+ return at.has(name.length);
781
+ }
782
+ function matchesKey(names, key) {
783
+ const seen = answers.get(names) ?? /* @__PURE__ */ new Map();
784
+ answers.set(names, seen);
785
+ const known = seen.get(key);
786
+ if (known !== void 0) return known;
787
+ const folded = formOf(key);
788
+ const answer = names.has(folded) || matchesFolded(names, folded);
789
+ if (key.length <= 64) {
790
+ if (seen.size > 1023) seen.clear();
791
+ seen.set(key, answer);
792
+ }
793
+ return answer;
692
794
  }
693
795
 
694
796
  // src/server/utils/hide-message-in-stack.util.ts
695
- var FRAME_LINE = /\n[ \t]+at /g;
696
797
  function failureTable(message) {
697
798
  const table = new Int32Array(message.length);
698
799
  for (let i = 1, matched = 0; i < message.length; i += 1) {
@@ -703,41 +804,38 @@ function failureTable(message) {
703
804
  return table;
704
805
  }
705
806
  function occurrences(stack, message) {
807
+ if (message.length > stack.length) return [];
706
808
  const table = failureTable(message);
707
809
  const spans = [];
708
810
  for (let i = 0, matched = 0; i < stack.length; i += 1) {
709
811
  while (matched > 0 && stack[i] !== message[matched]) matched = table[matched - 1];
710
812
  if (stack[i] === message[matched]) matched += 1;
711
813
  if (matched === message.length) {
712
- const start = i + 1 - message.length;
713
- const last = spans[spans.length - 1];
714
- if (last !== void 0 && start < last[1]) last[1] = i + 1;
715
- else spans.push([start, i + 1]);
814
+ spans.push([i + 1 - message.length, i + 1]);
716
815
  }
717
816
  }
718
817
  return spans;
719
818
  }
720
- function headerEnd(stack, spans) {
721
- let next = 0;
722
- for (const line of stack.matchAll(FRAME_LINE)) {
723
- while (next < spans.length && spans[next][1] <= line.index) next += 1;
724
- const span = spans[next];
725
- if (span === void 0 || line.index < span[0]) return line.index;
726
- }
727
- return stack.length;
728
- }
729
- function hideMessageInStack(stack, message, replacement) {
730
- if (message === "") return stack;
731
- if (message.length > stack.length) return stack;
732
- const spans = occurrences(stack, message);
733
- const end = headerEnd(stack, spans);
819
+ function hideMessagesInStack(stack, messages, replacement, limit) {
820
+ const spans = messages.filter((message) => message !== "").flatMap((message) => occurrences(stack, message)).sort((a, b) => a[0] - b[0]);
734
821
  let result = "";
735
822
  let from = 0;
736
- for (const [start, stop] of spans.filter(([, stop2]) => stop2 <= end)) {
823
+ let end = limit;
824
+ for (const [start, stop] of spans) {
825
+ if (start >= end) break;
826
+ if (start < from) {
827
+ from = Math.max(from, stop);
828
+ end = Math.max(end, from);
829
+ continue;
830
+ }
737
831
  result += stack.slice(from, start) + replacement;
738
832
  from = stop;
833
+ end = Math.max(end, stop);
739
834
  }
740
- return result + stack.slice(from);
835
+ return result + stack.slice(from, Math.max(end, from));
836
+ }
837
+ function hideMessageInStack(stack, message, replacement) {
838
+ return hideMessagesInStack(stack, [message], replacement, stack.length);
741
839
  }
742
840
 
743
841
  // src/server/utils/is-plain-record.util.ts
@@ -756,17 +854,17 @@ function endsHeader(stack, message, from) {
756
854
  const end = from + message.length;
757
855
  return stack.startsWith(message, from) && (end === stack.length || stack.startsWith("\n", end));
758
856
  }
759
- function censorStackHeader(stack, name, message, censored) {
760
- if (message === "" || censored === message) return stack;
857
+ function splitCensoredHeader(stack, name, message, censored) {
858
+ if (message === "" || censored === message) return ["", stack];
761
859
  const separator = stack.indexOf(NAME_SEPARATOR);
762
860
  if (separator !== -1 && stack.lastIndexOf("\n", separator) === -1) {
763
861
  const from = separator + NAME_SEPARATOR.length;
764
862
  if (endsHeader(stack, message, from)) {
765
- return stack.slice(0, from) + censored + stack.slice(from + message.length);
863
+ return [stack.slice(0, from) + censored, stack.slice(from + message.length)];
766
864
  }
767
865
  }
768
- if (endsHeader(stack, message, 0)) return censored + stack.slice(message.length);
769
- return name === "" ? censored : name + NAME_SEPARATOR + censored;
866
+ if (endsHeader(stack, message, 0)) return [censored, stack.slice(message.length)];
867
+ return [name === "" ? censored : name + NAME_SEPARATOR + censored, ""];
770
868
  }
771
869
  function isError(value) {
772
870
  try {
@@ -855,12 +953,12 @@ function readScrubbedStack(value, name, message, textName, result, walk2) {
855
953
  const header = headerCensor(name, message, walk2.censorMessage);
856
954
  return textName ? scrubStack(stack, header) : scrubStack(withNamedHeader(stack, message), header, stack.length > MAX_STACK_SCAN);
857
955
  }
858
- var FRAME_LINE2 = /\n[ \t]+at /;
956
+ var FRAME_LINE = /\n[ \t]+at /;
859
957
  function withNamedHeader(stack, message) {
860
958
  const head = stack.slice(0, MAX_STACK_SCAN);
861
959
  const found = message === "" ? -1 : head.indexOf(message);
862
960
  if (found !== -1) return `Error: ${head.slice(found)}`;
863
- const end = head.search(FRAME_LINE2);
961
+ const end = head.search(FRAME_LINE);
864
962
  const frames = end === -1 ? "" : head.slice(end);
865
963
  return `Error${message === "" ? "" : `: ${message}`}${frames}`;
866
964
  }
@@ -989,15 +1087,24 @@ function headerCensor(name, message, censorMessage) {
989
1087
  function censorStackName(stack, header) {
990
1088
  return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
991
1089
  }
1090
+ function censorMessageInStack(stack, header) {
1091
+ const [opened, rest] = splitCensoredHeader(
1092
+ censorStackName(stack, header),
1093
+ header.censoredName,
1094
+ header.message,
1095
+ header.censored
1096
+ );
1097
+ return header.censored === header.message ? opened + rest : opened + hideMessagesInStack(
1098
+ rest,
1099
+ [header.message],
1100
+ header.censored,
1101
+ Math.max(0, MAX_STACK_SCAN - (stack.length - rest.length))
1102
+ );
1103
+ }
992
1104
  function scrubStack(stack, header, wasLonger = false) {
993
- const head = stack.slice(0, MAX_STACK_SCAN);
1105
+ const window = stack.slice(0, MAX_STACK_SCAN + (header?.message.length ?? 0));
994
1106
  const scrubbed = escapeControlCharacters(
995
- (header === void 0 ? head : censorStackHeader(
996
- censorStackName(head, header),
997
- header.censoredName,
998
- header.message,
999
- header.censored
1000
- )).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
1107
+ (header === void 0 ? window : censorMessageInStack(window, header)).slice(0, MAX_STACK_SCAN).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
1001
1108
  );
1002
1109
  return cutText(scrubbed, wasLonger || stack.length > MAX_STACK_SCAN);
1003
1110
  }
@@ -2789,7 +2896,7 @@ function mergeMixinSafely(mergeObject, mixinObject) {
2789
2896
  function censorRawHeaders(raw, sensitive, censor) {
2790
2897
  return raw.map((entry, index) => {
2791
2898
  const name = index % 2 === 1 ? raw[index - 1] : void 0;
2792
- return typeof name === "string" && sensitive.has(name.toLowerCase()) ? censor : entry;
2899
+ return typeof name === "string" && matchesKey(sensitive, name) ? censor : entry;
2793
2900
  });
2794
2901
  }
2795
2902
 
@@ -2899,34 +3006,57 @@ function rulesBelow(rules, key, value, honorToJson) {
2899
3006
  return rules.exemptKeys === void 0 && rules.headerKept !== true ? rules : { ...rules, exemptKeys: void 0, headerKept: void 0 };
2900
3007
  }
2901
3008
  function isCensored(rules, key, value) {
2902
- const lower = key.toLowerCase();
2903
- return rules.sensitive.has(lower) && !(typeof value === "string" && rules.exemptKeys?.has(lower));
3009
+ return matchesKey(rules.sensitive, key) && !(typeof value === "string" && rules.exemptKeys?.has(key));
2904
3010
  }
2905
3011
  function messageCensor(rules) {
2906
3012
  return (text) => rules.sensitive.has("message") ? rules.censor : text;
2907
3013
  }
3014
+ var STACK_NAMES = /* @__PURE__ */ new Set(["stack"]);
3015
+ var MESSAGE_NAMES = /* @__PURE__ */ new Set(["message"]);
3016
+ var MAX_STACK_ALIASES = 8;
3017
+ var NO_STACK = { texts: /* @__PURE__ */ new Map(), stackKeys: /* @__PURE__ */ new Set(), overflow: false };
2908
3018
  function headerMessage(rules, source, keys, isError2) {
2909
- if (isError2 || !rules.sensitive.has("message") || rules.exemptKeys?.has("message") === true)
2910
- return void 0;
2911
- if (rules.headerKept === true) return void 0;
2912
- const key = keys.find((candidate) => foldKey(candidate) === "message");
2913
- if (key === void 0 || !keys.some((candidate) => foldKey(candidate) === "stack")) {
2914
- return void 0;
3019
+ if (isError2) return void 0;
3020
+ const keysOf = (names) => keys.filter((candidate) => matchesKey(names, candidate));
3021
+ const stacks = keysOf(STACK_NAMES);
3022
+ if (stacks.length === 0) return NO_STACK;
3023
+ const hides = rules.sensitive.has("message") && rules.exemptKeys?.has("message") !== true && rules.headerKept !== true;
3024
+ const texts = /* @__PURE__ */ new Map();
3025
+ if (hides) {
3026
+ for (const key of keysOf(MESSAGE_NAMES)) {
3027
+ const text = Reflect.get(source, key);
3028
+ if (typeof text === "string") texts.set(key, text);
3029
+ }
3030
+ const named = keys.includes("message") ? void 0 : Reflect.get(source, "message");
3031
+ if (typeof named === "string") texts.set("message", named);
2915
3032
  }
2916
- const text = Reflect.get(source, key);
2917
- return typeof text === "string" ? { key, text } : void 0;
3033
+ const overflow = stacks.length > MAX_STACK_ALIASES || new Set(texts.values()).size > MAX_STACK_ALIASES;
3034
+ return { texts, stackKeys: new Set(stacks), overflow };
2918
3035
  }
2919
3036
  function readField(source, key, header) {
2920
- return header !== void 0 && key === header.key ? header.text : Reflect.get(source, key);
3037
+ return header?.texts.get(key) ?? Reflect.get(source, key);
2921
3038
  }
2922
3039
  function censorAnyName(rules, name) {
2923
3040
  if (typeof name === "string") return censorName(name, messageCensor(rules));
2924
3041
  const holder = typeof name === "object" && name !== null || typeof name === "function";
2925
3042
  return holder && rules.sensitive.has("message") ? rules.censor : name;
2926
3043
  }
3044
+ function scrubPlainStack(rules, stack, header) {
3045
+ const texts = [...new Set(header?.texts.values())];
3046
+ const longest = texts.reduce((most, text) => Math.max(most, text.length), 0);
3047
+ const hidden = hideMessagesInStack(
3048
+ // Stryker disable next-line MethodExpression: equivalent in output: an occurrence that starts before the bound ends inside the window, and one that starts after it is not read, so a longer text gives the same result; the slice only bounds the search.
3049
+ stack.slice(0, MAX_STACK_SCAN + longest),
3050
+ texts,
3051
+ rules.censor,
3052
+ MAX_STACK_SCAN
3053
+ );
3054
+ return scrubStack(hidden, void 0, stack.length > MAX_STACK_SCAN);
3055
+ }
2927
3056
  function errorTextField(rules, key, value, isError2, header) {
2928
- if (header !== void 0 && foldKey(key) === "stack" && typeof value === "string") {
2929
- return hideMessageInStack(value, header.text, rules.censor);
3057
+ const isStack = !isError2 && typeof value === "string" && (header === void 0 ? matchesKey(STACK_NAMES, key) : header.stackKeys.has(key));
3058
+ if (isStack) {
3059
+ return header?.overflow === true ? rules.censor : scrubPlainStack(rules, value, header);
2930
3060
  }
2931
3061
  if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
2932
3062
  const cut = cutIfText(value);
@@ -2962,7 +3092,7 @@ function cloneError(error) {
2962
3092
  // src/server/utils/redact-by-name.util.ts
2963
3093
  var RAW_HEADER_KEYS = /* @__PURE__ */ new Set(["rawheaders", "rawtrailers"]);
2964
3094
  function censorHeaderArray(key, walked, rules) {
2965
- return RAW_HEADER_KEYS.has(key.toLowerCase()) && Array.isArray(walked) ? censorRawHeaders(walked, rules.headerNames, rules.censor) : walked;
3095
+ return matchesKey(RAW_HEADER_KEYS, key) && Array.isArray(walked) ? censorRawHeaders(walked, rules.headerNames, rules.censor) : walked;
2966
3096
  }
2967
3097
  var REDACT_MAX_TRAVERSAL_DEPTH = 100;
2968
3098
  var REDACT_DEPTH_EXCEEDED = "[REDACTION_DEPTH_EXCEEDED]";
@@ -3075,7 +3205,7 @@ function walkForm(value, resolved, rules, depth2, ancestors, honorToJson, inSeri
3075
3205
  return walkProperties(value, rules, depth2, ancestors, honorToJson, inSerialized);
3076
3206
  }
3077
3207
  function walkToJsonOutput(value, toJson, rules, depth2, ancestors, inSerialized) {
3078
- if (Object.keys(value).some((key) => rules.sensitive.has(key.toLowerCase()))) {
3208
+ if (Object.keys(value).some((key) => matchesKey(rules.sensitive, key))) {
3079
3209
  return rules.censor;
3080
3210
  }
3081
3211
  return walk(toJson.call(value), rules, depth2 + 1, ancestors, true, inSerialized);
@@ -3143,8 +3273,8 @@ function errorPartsHost(rules, ancestors, inSerialized) {
3143
3273
  }
3144
3274
  function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames, headerNames, errorTextToSerializer = false) {
3145
3275
  const rules = {
3146
- sensitive: new Set(Array.from(fieldNames, (name) => name.toLowerCase())),
3147
- headerNames: new Set(Array.from(headerNames ?? fieldNames, (name) => name.toLowerCase())),
3276
+ sensitive: foldedNames(fieldNames),
3277
+ headerNames: foldedNames(headerNames ?? fieldNames),
3148
3278
  censor,
3149
3279
  serializedKeys: new Set(serializedKeys),
3150
3280
  errorsAsData: serializedKeys !== void 0,
@@ -3152,7 +3282,7 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
3152
3282
  maxVisits,
3153
3283
  ownFields
3154
3284
  };
3155
- const insideNames = errorOnlyNames === void 0 ? void 0 : new Set(Array.from(errorOnlyNames, (name) => name.toLowerCase()));
3285
+ const insideNames = errorOnlyNames === void 0 ? void 0 : foldedNames(errorOnlyNames);
3156
3286
  return (value, isRecordRoot = false) => {
3157
3287
  try {
3158
3288
  const visits = { count: 0 };
@@ -22,6 +22,23 @@ var __decorateParam = (index, decorator) => (target, key) => decorator(target, k
22
22
  var getFilename = () => fileURLToPath(import.meta.url);
23
23
  var __filename$1 = /* @__PURE__ */ getFilename();
24
24
 
25
+ // src/server/config/options-refusal.util.ts
26
+ var refusals = /* @__PURE__ */ new WeakSet();
27
+ var UNREADABLE = "[BymaxLoggerModule] options could not be read";
28
+ function refuse(message) {
29
+ const error = new Error(message);
30
+ refusals.add(error);
31
+ throw error;
32
+ }
33
+ function guardOptions(read) {
34
+ try {
35
+ return read();
36
+ } catch (error) {
37
+ if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
38
+ throw new Error(UNREADABLE, { cause: error });
39
+ }
40
+ }
41
+
25
42
  // src/server/config/drop-unset-options.ts
26
43
  var OPTION_KEYS = {
27
44
  service: true,
@@ -80,11 +97,20 @@ function readSet(source, keys) {
80
97
  }
81
98
  var LIST_OPTIONS = ["redactPaths", "errorOwnFieldNames", "destinations"];
82
99
  var HTTP_LISTS = ["excludePaths", "secretPathSegments"];
83
- function copyLists(holder, names) {
100
+ var MAX_LIST_ENTRIES = 1e4;
101
+ function copyLists(holder, names, prefix) {
84
102
  for (const name of names) {
85
103
  const value = Reflect.get(holder, name);
86
104
  if (!Array.isArray(value)) continue;
87
105
  const length = Reflect.get(value, "length");
106
+ if (!Number.isInteger(length) || length < 0) {
107
+ refuse(`[BymaxLoggerModule] options.${prefix}${name} has a length that is not a count`);
108
+ }
109
+ if (length > MAX_LIST_ENTRIES) {
110
+ refuse(
111
+ `[BymaxLoggerModule] options.${prefix}${name} holds more than ${String(MAX_LIST_ENTRIES)} entries`
112
+ );
113
+ }
88
114
  Reflect.set(
89
115
  holder,
90
116
  name,
@@ -104,29 +130,12 @@ function dropUnsetOptions(options) {
104
130
  if (isRecord(service)) Reflect.set(set, "service", { ...service });
105
131
  const serializers = Reflect.get(set, "serializers");
106
132
  if (isRecord(serializers)) Reflect.set(set, "serializers", { ...serializers });
107
- copyLists(set, LIST_OPTIONS);
133
+ copyLists(set, LIST_OPTIONS, "");
108
134
  const http = Reflect.get(set, "http");
109
- if (isRecord(http)) copyLists(http, HTTP_LISTS);
135
+ if (isRecord(http)) copyLists(http, HTTP_LISTS, "http.");
110
136
  return set;
111
137
  }
112
138
 
113
- // src/server/config/options-refusal.util.ts
114
- var refusals = /* @__PURE__ */ new WeakSet();
115
- var UNREADABLE = "[BymaxLoggerModule] options could not be read";
116
- function refuse(message) {
117
- const error = new Error(message);
118
- refusals.add(error);
119
- throw error;
120
- }
121
- function guardOptions(read) {
122
- try {
123
- return read();
124
- } catch (error) {
125
- if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
126
- throw new Error(UNREADABLE, { cause: error });
127
- }
128
- }
129
-
130
139
  // src/server/constants/lifecycle-timeouts.constants.ts
131
140
  var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
132
141
  var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
@@ -647,49 +656,141 @@ function escapeControlCharacters(text) {
647
656
  }
648
657
 
649
658
  // src/server/utils/fold-key.util.ts
650
- var IGNORED = /[\s._\p{Cc}\p{Cf}\p{M}-]/gu;
651
- var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}]/gu;
659
+ var NOT_NAME = /[^\p{L}\p{N}]|[\u115f\u1160\u3164\uffa0]/gu;
660
+ var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}\u115f\u1160\u2800\u3164\uffa0]/gu;
661
+ var DOTS = /[\u3002\u0701\u06d4\u22c5\u00b7\ufe12]/gu;
652
662
  var PLAIN = /^[\x21-\x7e]*$/;
663
+ var NON_ASCII = /[^\x20-\x7e]/;
664
+ var NOT_ASCII_NAME = /[^A-Za-z0-9]/g;
653
665
  var LOOKALIKES = new Map(
654
666
  Object.entries({
655
667
  a: "\u0430\u03B1\u1D00",
656
668
  b: "\u0299",
657
- c: "\u0441\u03F2\u1D04",
669
+ c: "\u0441\u03F2\u1D04\u023C\u0188",
658
670
  d: "\u0501\u1D05",
659
- e: "\u0435\u03B5\u03F5\u1D07",
671
+ e: "\u0435\u03B5\u03F5\u1D07\u025B\u04BD",
660
672
  f: "\uA730",
661
673
  g: "\u0262",
662
674
  h: "\u029C",
663
- i: "\u0456\u03B9\u0131\u026A",
664
675
  j: "\u0458\u1D0A",
665
676
  k: "\u1D0B",
666
677
  l: "\u029F",
667
678
  m: "\u1D0D",
668
679
  n: "\u0274",
669
- o: "\u043E\u03BF\u1D0F",
670
- p: "\u0440\u03C1\u1D18",
680
+ o: "\u043E\u03BF\u1D0F\xF8",
681
+ p: "\u0440\u03C1\u1D18\u01BF",
671
682
  q: "\u051B",
672
683
  r: "\u0280",
673
684
  s: "\u0455\uA731",
674
- t: "\u1D1B",
685
+ t: "\u1D1B\u0167",
675
686
  u: "\u1D1C",
676
- v: "\u03BD\u1D20",
687
+ v: "\u1D20",
677
688
  w: "\u051D\u1D21",
678
689
  x: "\u0445",
679
- y: "\u0443\u028F",
690
+ y: "\u0443\u028F\u04AF",
680
691
  z: "\u1D22"
681
692
  }).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
682
693
  );
694
+ var I_LIKE = new Map(
695
+ [..."\u0456\u03B9\u0131\u026A\u0269"].map((letter) => [letter, "i"])
696
+ );
683
697
  function foldKey(key, keepSeparators = false) {
684
- const ignored = keepSeparators ? INVISIBLE : IGNORED;
685
- if (PLAIN.test(key)) return key.replace(ignored, "").toLowerCase();
686
- let folded = key.normalize("NFKD").toLowerCase().replace(ignored, "");
687
- for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
688
- return folded;
698
+ if (keepSeparators) {
699
+ if (PLAIN.test(key)) return key.toLowerCase();
700
+ return withLookalikes(
701
+ key.normalize("NFKD").toLowerCase().replace(DOTS, ".").replace(INVISIBLE, ""),
702
+ true
703
+ );
704
+ }
705
+ if (PLAIN.test(key)) return key.replace(NOT_ASCII_NAME, "").toLowerCase();
706
+ return withLookalikes(key.normalize("NFKD").toLowerCase().replace(NOT_NAME, ""), true);
707
+ }
708
+ function foldStrict(key) {
709
+ if (PLAIN.test(key)) return key.replace(NOT_ASCII_NAME, "").toLowerCase();
710
+ return withLookalikes(key.normalize("NFKD").toLowerCase().replace(NOT_NAME, ""), false);
711
+ }
712
+ function withLookalikes(folded, all) {
713
+ let read = folded;
714
+ for (const [letter, latin] of LOOKALIKES) read = read.replaceAll(letter, latin);
715
+ if (all) for (const [letter, latin] of I_LIKE) read = read.replaceAll(letter, latin);
716
+ return read;
717
+ }
718
+ var ALNUM = /^[A-Za-z0-9]*$/;
719
+ function formOf(key) {
720
+ return ALNUM.test(key) ? key.toLowerCase() : foldStrict(key);
721
+ }
722
+ var answers = /* @__PURE__ */ new WeakMap();
723
+ function foldName(key) {
724
+ return formOf(key);
725
+ }
726
+ function foldedNames(names) {
727
+ return new Set(Array.from(names, foldName).filter((name) => name !== ""));
728
+ }
729
+ var MAX_CANDIDATES = 64;
730
+ var grouped = /* @__PURE__ */ new WeakMap();
731
+ function groupsOf(names) {
732
+ let groups = grouped.get(names);
733
+ if (groups === void 0) {
734
+ const built = /* @__PURE__ */ new Map();
735
+ let longest = 0;
736
+ for (const name of names) {
737
+ const size = [...name].length;
738
+ const same = built.get(size);
739
+ if (same === void 0) built.set(size, [name]);
740
+ else same.push(name);
741
+ longest = Math.max(longest, size);
742
+ }
743
+ groups = { byLength: built, longest };
744
+ grouped.set(names, groups);
745
+ }
746
+ return groups;
747
+ }
748
+ function matchesFolded(names, folded) {
749
+ if (names.has(folded)) return true;
750
+ if (!NON_ASCII.test(folded)) return false;
751
+ const letters = [...folded];
752
+ const wide = letters.filter((letter) => !isAscii(letter)).length;
753
+ const { byLength, longest } = groupsOf(names);
754
+ if (letters.length > longest) return false;
755
+ const lengths = Array.from(
756
+ { length: wide + 1 },
757
+ (_, extra) => byLength.get(letters.length + extra) ?? []
758
+ );
759
+ if (lengths.reduce((count, same) => count + same.length, 0) > MAX_CANDIDATES) return true;
760
+ return lengths.some((same) => same.some((name) => matchesName(letters, [...name])));
761
+ }
762
+ var isAscii = (letter) => letter < "\x80";
763
+ function matchesName(letters, name) {
764
+ let at = /* @__PURE__ */ new Set([0]);
765
+ for (const letter of letters) {
766
+ const next = /* @__PURE__ */ new Set();
767
+ for (const position of at) {
768
+ if (isAscii(letter)) {
769
+ if (name[position] === letter) next.add(position + 1);
770
+ continue;
771
+ }
772
+ next.add(position + 1);
773
+ next.add(position + 2);
774
+ }
775
+ at = next;
776
+ }
777
+ return at.has(name.length);
778
+ }
779
+ function matchesKey(names, key) {
780
+ const seen = answers.get(names) ?? /* @__PURE__ */ new Map();
781
+ answers.set(names, seen);
782
+ const known = seen.get(key);
783
+ if (known !== void 0) return known;
784
+ const folded = formOf(key);
785
+ const answer = names.has(folded) || matchesFolded(names, folded);
786
+ if (key.length <= 64) {
787
+ if (seen.size > 1023) seen.clear();
788
+ seen.set(key, answer);
789
+ }
790
+ return answer;
689
791
  }
690
792
 
691
793
  // src/server/utils/hide-message-in-stack.util.ts
692
- var FRAME_LINE = /\n[ \t]+at /g;
693
794
  function failureTable(message) {
694
795
  const table = new Int32Array(message.length);
695
796
  for (let i = 1, matched = 0; i < message.length; i += 1) {
@@ -700,41 +801,38 @@ function failureTable(message) {
700
801
  return table;
701
802
  }
702
803
  function occurrences(stack, message) {
804
+ if (message.length > stack.length) return [];
703
805
  const table = failureTable(message);
704
806
  const spans = [];
705
807
  for (let i = 0, matched = 0; i < stack.length; i += 1) {
706
808
  while (matched > 0 && stack[i] !== message[matched]) matched = table[matched - 1];
707
809
  if (stack[i] === message[matched]) matched += 1;
708
810
  if (matched === message.length) {
709
- const start = i + 1 - message.length;
710
- const last = spans[spans.length - 1];
711
- if (last !== void 0 && start < last[1]) last[1] = i + 1;
712
- else spans.push([start, i + 1]);
811
+ spans.push([i + 1 - message.length, i + 1]);
713
812
  }
714
813
  }
715
814
  return spans;
716
815
  }
717
- function headerEnd(stack, spans) {
718
- let next = 0;
719
- for (const line of stack.matchAll(FRAME_LINE)) {
720
- while (next < spans.length && spans[next][1] <= line.index) next += 1;
721
- const span = spans[next];
722
- if (span === void 0 || line.index < span[0]) return line.index;
723
- }
724
- return stack.length;
725
- }
726
- function hideMessageInStack(stack, message, replacement) {
727
- if (message === "") return stack;
728
- if (message.length > stack.length) return stack;
729
- const spans = occurrences(stack, message);
730
- const end = headerEnd(stack, spans);
816
+ function hideMessagesInStack(stack, messages, replacement, limit) {
817
+ const spans = messages.filter((message) => message !== "").flatMap((message) => occurrences(stack, message)).sort((a, b) => a[0] - b[0]);
731
818
  let result = "";
732
819
  let from = 0;
733
- for (const [start, stop] of spans.filter(([, stop2]) => stop2 <= end)) {
820
+ let end = limit;
821
+ for (const [start, stop] of spans) {
822
+ if (start >= end) break;
823
+ if (start < from) {
824
+ from = Math.max(from, stop);
825
+ end = Math.max(end, from);
826
+ continue;
827
+ }
734
828
  result += stack.slice(from, start) + replacement;
735
829
  from = stop;
830
+ end = Math.max(end, stop);
736
831
  }
737
- return result + stack.slice(from);
832
+ return result + stack.slice(from, Math.max(end, from));
833
+ }
834
+ function hideMessageInStack(stack, message, replacement) {
835
+ return hideMessagesInStack(stack, [message], replacement, stack.length);
738
836
  }
739
837
 
740
838
  // src/server/utils/is-plain-record.util.ts
@@ -753,17 +851,17 @@ function endsHeader(stack, message, from) {
753
851
  const end = from + message.length;
754
852
  return stack.startsWith(message, from) && (end === stack.length || stack.startsWith("\n", end));
755
853
  }
756
- function censorStackHeader(stack, name, message, censored) {
757
- if (message === "" || censored === message) return stack;
854
+ function splitCensoredHeader(stack, name, message, censored) {
855
+ if (message === "" || censored === message) return ["", stack];
758
856
  const separator = stack.indexOf(NAME_SEPARATOR);
759
857
  if (separator !== -1 && stack.lastIndexOf("\n", separator) === -1) {
760
858
  const from = separator + NAME_SEPARATOR.length;
761
859
  if (endsHeader(stack, message, from)) {
762
- return stack.slice(0, from) + censored + stack.slice(from + message.length);
860
+ return [stack.slice(0, from) + censored, stack.slice(from + message.length)];
763
861
  }
764
862
  }
765
- if (endsHeader(stack, message, 0)) return censored + stack.slice(message.length);
766
- return name === "" ? censored : name + NAME_SEPARATOR + censored;
863
+ if (endsHeader(stack, message, 0)) return [censored, stack.slice(message.length)];
864
+ return [name === "" ? censored : name + NAME_SEPARATOR + censored, ""];
767
865
  }
768
866
  function isError(value) {
769
867
  try {
@@ -852,12 +950,12 @@ function readScrubbedStack(value, name, message, textName, result, walk2) {
852
950
  const header = headerCensor(name, message, walk2.censorMessage);
853
951
  return textName ? scrubStack(stack, header) : scrubStack(withNamedHeader(stack, message), header, stack.length > MAX_STACK_SCAN);
854
952
  }
855
- var FRAME_LINE2 = /\n[ \t]+at /;
953
+ var FRAME_LINE = /\n[ \t]+at /;
856
954
  function withNamedHeader(stack, message) {
857
955
  const head = stack.slice(0, MAX_STACK_SCAN);
858
956
  const found = message === "" ? -1 : head.indexOf(message);
859
957
  if (found !== -1) return `Error: ${head.slice(found)}`;
860
- const end = head.search(FRAME_LINE2);
958
+ const end = head.search(FRAME_LINE);
861
959
  const frames = end === -1 ? "" : head.slice(end);
862
960
  return `Error${message === "" ? "" : `: ${message}`}${frames}`;
863
961
  }
@@ -986,15 +1084,24 @@ function headerCensor(name, message, censorMessage) {
986
1084
  function censorStackName(stack, header) {
987
1085
  return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
988
1086
  }
1087
+ function censorMessageInStack(stack, header) {
1088
+ const [opened, rest] = splitCensoredHeader(
1089
+ censorStackName(stack, header),
1090
+ header.censoredName,
1091
+ header.message,
1092
+ header.censored
1093
+ );
1094
+ return header.censored === header.message ? opened + rest : opened + hideMessagesInStack(
1095
+ rest,
1096
+ [header.message],
1097
+ header.censored,
1098
+ Math.max(0, MAX_STACK_SCAN - (stack.length - rest.length))
1099
+ );
1100
+ }
989
1101
  function scrubStack(stack, header, wasLonger = false) {
990
- const head = stack.slice(0, MAX_STACK_SCAN);
1102
+ const window = stack.slice(0, MAX_STACK_SCAN + (header?.message.length ?? 0));
991
1103
  const scrubbed = escapeControlCharacters(
992
- (header === void 0 ? head : censorStackHeader(
993
- censorStackName(head, header),
994
- header.censoredName,
995
- header.message,
996
- header.censored
997
- )).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
1104
+ (header === void 0 ? window : censorMessageInStack(window, header)).slice(0, MAX_STACK_SCAN).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
998
1105
  );
999
1106
  return cutText(scrubbed, wasLonger || stack.length > MAX_STACK_SCAN);
1000
1107
  }
@@ -2786,7 +2893,7 @@ function mergeMixinSafely(mergeObject, mixinObject) {
2786
2893
  function censorRawHeaders(raw, sensitive, censor) {
2787
2894
  return raw.map((entry, index) => {
2788
2895
  const name = index % 2 === 1 ? raw[index - 1] : void 0;
2789
- return typeof name === "string" && sensitive.has(name.toLowerCase()) ? censor : entry;
2896
+ return typeof name === "string" && matchesKey(sensitive, name) ? censor : entry;
2790
2897
  });
2791
2898
  }
2792
2899
 
@@ -2896,34 +3003,57 @@ function rulesBelow(rules, key, value, honorToJson) {
2896
3003
  return rules.exemptKeys === void 0 && rules.headerKept !== true ? rules : { ...rules, exemptKeys: void 0, headerKept: void 0 };
2897
3004
  }
2898
3005
  function isCensored(rules, key, value) {
2899
- const lower = key.toLowerCase();
2900
- return rules.sensitive.has(lower) && !(typeof value === "string" && rules.exemptKeys?.has(lower));
3006
+ return matchesKey(rules.sensitive, key) && !(typeof value === "string" && rules.exemptKeys?.has(key));
2901
3007
  }
2902
3008
  function messageCensor(rules) {
2903
3009
  return (text) => rules.sensitive.has("message") ? rules.censor : text;
2904
3010
  }
3011
+ var STACK_NAMES = /* @__PURE__ */ new Set(["stack"]);
3012
+ var MESSAGE_NAMES = /* @__PURE__ */ new Set(["message"]);
3013
+ var MAX_STACK_ALIASES = 8;
3014
+ var NO_STACK = { texts: /* @__PURE__ */ new Map(), stackKeys: /* @__PURE__ */ new Set(), overflow: false };
2905
3015
  function headerMessage(rules, source, keys, isError2) {
2906
- if (isError2 || !rules.sensitive.has("message") || rules.exemptKeys?.has("message") === true)
2907
- return void 0;
2908
- if (rules.headerKept === true) return void 0;
2909
- const key = keys.find((candidate) => foldKey(candidate) === "message");
2910
- if (key === void 0 || !keys.some((candidate) => foldKey(candidate) === "stack")) {
2911
- return void 0;
3016
+ if (isError2) return void 0;
3017
+ const keysOf = (names) => keys.filter((candidate) => matchesKey(names, candidate));
3018
+ const stacks = keysOf(STACK_NAMES);
3019
+ if (stacks.length === 0) return NO_STACK;
3020
+ const hides = rules.sensitive.has("message") && rules.exemptKeys?.has("message") !== true && rules.headerKept !== true;
3021
+ const texts = /* @__PURE__ */ new Map();
3022
+ if (hides) {
3023
+ for (const key of keysOf(MESSAGE_NAMES)) {
3024
+ const text = Reflect.get(source, key);
3025
+ if (typeof text === "string") texts.set(key, text);
3026
+ }
3027
+ const named = keys.includes("message") ? void 0 : Reflect.get(source, "message");
3028
+ if (typeof named === "string") texts.set("message", named);
2912
3029
  }
2913
- const text = Reflect.get(source, key);
2914
- return typeof text === "string" ? { key, text } : void 0;
3030
+ const overflow = stacks.length > MAX_STACK_ALIASES || new Set(texts.values()).size > MAX_STACK_ALIASES;
3031
+ return { texts, stackKeys: new Set(stacks), overflow };
2915
3032
  }
2916
3033
  function readField(source, key, header) {
2917
- return header !== void 0 && key === header.key ? header.text : Reflect.get(source, key);
3034
+ return header?.texts.get(key) ?? Reflect.get(source, key);
2918
3035
  }
2919
3036
  function censorAnyName(rules, name) {
2920
3037
  if (typeof name === "string") return censorName(name, messageCensor(rules));
2921
3038
  const holder = typeof name === "object" && name !== null || typeof name === "function";
2922
3039
  return holder && rules.sensitive.has("message") ? rules.censor : name;
2923
3040
  }
3041
+ function scrubPlainStack(rules, stack, header) {
3042
+ const texts = [...new Set(header?.texts.values())];
3043
+ const longest = texts.reduce((most, text) => Math.max(most, text.length), 0);
3044
+ const hidden = hideMessagesInStack(
3045
+ // Stryker disable next-line MethodExpression: equivalent in output: an occurrence that starts before the bound ends inside the window, and one that starts after it is not read, so a longer text gives the same result; the slice only bounds the search.
3046
+ stack.slice(0, MAX_STACK_SCAN + longest),
3047
+ texts,
3048
+ rules.censor,
3049
+ MAX_STACK_SCAN
3050
+ );
3051
+ return scrubStack(hidden, void 0, stack.length > MAX_STACK_SCAN);
3052
+ }
2924
3053
  function errorTextField(rules, key, value, isError2, header) {
2925
- if (header !== void 0 && foldKey(key) === "stack" && typeof value === "string") {
2926
- return hideMessageInStack(value, header.text, rules.censor);
3054
+ const isStack = !isError2 && typeof value === "string" && (header === void 0 ? matchesKey(STACK_NAMES, key) : header.stackKeys.has(key));
3055
+ if (isStack) {
3056
+ return header?.overflow === true ? rules.censor : scrubPlainStack(rules, value, header);
2927
3057
  }
2928
3058
  if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
2929
3059
  const cut = cutIfText(value);
@@ -2959,7 +3089,7 @@ function cloneError(error) {
2959
3089
  // src/server/utils/redact-by-name.util.ts
2960
3090
  var RAW_HEADER_KEYS = /* @__PURE__ */ new Set(["rawheaders", "rawtrailers"]);
2961
3091
  function censorHeaderArray(key, walked, rules) {
2962
- return RAW_HEADER_KEYS.has(key.toLowerCase()) && Array.isArray(walked) ? censorRawHeaders(walked, rules.headerNames, rules.censor) : walked;
3092
+ return matchesKey(RAW_HEADER_KEYS, key) && Array.isArray(walked) ? censorRawHeaders(walked, rules.headerNames, rules.censor) : walked;
2963
3093
  }
2964
3094
  var REDACT_MAX_TRAVERSAL_DEPTH = 100;
2965
3095
  var REDACT_DEPTH_EXCEEDED = "[REDACTION_DEPTH_EXCEEDED]";
@@ -3072,7 +3202,7 @@ function walkForm(value, resolved, rules, depth2, ancestors, honorToJson, inSeri
3072
3202
  return walkProperties(value, rules, depth2, ancestors, honorToJson, inSerialized);
3073
3203
  }
3074
3204
  function walkToJsonOutput(value, toJson, rules, depth2, ancestors, inSerialized) {
3075
- if (Object.keys(value).some((key) => rules.sensitive.has(key.toLowerCase()))) {
3205
+ if (Object.keys(value).some((key) => matchesKey(rules.sensitive, key))) {
3076
3206
  return rules.censor;
3077
3207
  }
3078
3208
  return walk(toJson.call(value), rules, depth2 + 1, ancestors, true, inSerialized);
@@ -3140,8 +3270,8 @@ function errorPartsHost(rules, ancestors, inSerialized) {
3140
3270
  }
3141
3271
  function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames, headerNames, errorTextToSerializer = false) {
3142
3272
  const rules = {
3143
- sensitive: new Set(Array.from(fieldNames, (name) => name.toLowerCase())),
3144
- headerNames: new Set(Array.from(headerNames ?? fieldNames, (name) => name.toLowerCase())),
3273
+ sensitive: foldedNames(fieldNames),
3274
+ headerNames: foldedNames(headerNames ?? fieldNames),
3145
3275
  censor,
3146
3276
  serializedKeys: new Set(serializedKeys),
3147
3277
  errorsAsData: serializedKeys !== void 0,
@@ -3149,7 +3279,7 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
3149
3279
  maxVisits,
3150
3280
  ownFields
3151
3281
  };
3152
- const insideNames = errorOnlyNames === void 0 ? void 0 : new Set(Array.from(errorOnlyNames, (name) => name.toLowerCase()));
3282
+ const insideNames = errorOnlyNames === void 0 ? void 0 : foldedNames(errorOnlyNames);
3153
3283
  return (value, isRecordRoot = false) => {
3154
3284
  try {
3155
3285
  const visits = { count: 0 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-logger",
3
- "version": "1.4.28",
3
+ "version": "1.4.29",
4
4
  "description": "Structured JSON logging for NestJS based on Pino 10, with optional OpenTelemetry correlation.",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",