@bymax-one/nest-logger 1.4.14 → 1.4.15

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
@@ -11,6 +11,31 @@ heading here.
11
11
 
12
12
  ## [Unreleased]
13
13
 
14
+ ## [1.4.15] - 2026-11-10
15
+
16
+ ### Fixed
17
+
18
+ - **Under `redactStrategy: 'paths'`, an `Error` in the record is no longer written as `{}`.** A
19
+ nested `Error`, or one held as metadata, lost its `type`, `message`, `stack` and `cause` and kept
20
+ only its enumerable own fields, because those parts are not enumerable and the record reached
21
+ Pino as an `Error` instance. It is now written the way the default `'names'` strategy writes it:
22
+ `type`, `message`, `stack`, its own fields and its chain of `cause`s, with your `redactPaths`
23
+ applied on top. The default names are censored in its own fields and its causes at any depth,
24
+ past the four-level ceiling of `fast-redact`; data that is not an `Error` is still matched only
25
+ by your configured paths, which is what the strategy is for. Found by measuring 1.4.13: a nested
26
+ `Error` was `{}` even with no `redactPaths` at all.
27
+ **This also closes a leak.** An `Error` that writes itself through `toJSON`, as an HTTP client's
28
+ error does, was written with the output of that method, and a secret in it deeper than
29
+ `fast-redact` reaches (an `authorization` header under `config.headers`) was
30
+ written in clear under `redactStrategy: 'paths'`. Measured on 1.4.14 with
31
+ `{ top: <Error whose toJSON returns { config: { a: { b: { c: { d: { headers: { authorization } } } } } } }> }`:
32
+ the value appeared as written; it is now `[REDACTED]`.
33
+ **Apply to a derived backend:** a host on `redactStrategy: 'paths'` now sees `type`, `message`,
34
+ `stack` and `cause` where it saw `{}`, so a query or alert that matched the empty object matches
35
+ the fields instead. Hosts on the default strategy are unaffected. A host on `'paths'` that logged
36
+ an `Error` with a `toJSON` carrying credentials should treat what reached its log store as
37
+ exposed and rotate them.
38
+
14
39
  ## [1.4.14] - 2026-11-09
15
40
 
16
41
  ### Added
@@ -2688,7 +2713,8 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
2688
2713
  - Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
2689
2714
  `release.yml`, Dependabot, and issue templates
2690
2715
 
2691
- [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.14...HEAD
2716
+ [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.15...HEAD
2717
+ [1.4.15]: https://github.com/bymaxone/nest-logger/compare/v1.4.14...v1.4.15
2692
2718
  [1.4.14]: https://github.com/bymaxone/nest-logger/compare/v1.4.13...v1.4.14
2693
2719
  [1.4.13]: https://github.com/bymaxone/nest-logger/compare/v1.4.12...v1.4.13
2694
2720
  [1.4.12]: https://github.com/bymaxone/nest-logger/compare/v1.4.11...v1.4.12
package/README.md CHANGED
@@ -1305,6 +1305,8 @@ There is no name rule that reaches the second one, and scanning inside values fo
1305
1305
 
1306
1306
  `redactStrategy` governs **your** payload — the record you log, your child bindings, and the output of any serializer you supply. The built-in `err` serializer is the library's own output and is always name-walked, including under `'paths'`, because `fast-redact`'s four-wildcard ceiling cannot reach the depth a `cause` chain serializes to.
1307
1307
 
1308
+ Under `redactStrategy: 'paths'`, an `Error` anywhere in the record is converted with the default names censored in its own fields and its `cause` chain at any depth; non-`Error` data is matched only by the configured paths. The `Error` is written as it is under `'names'` (`type`, `message`, `stack`, its own fields and its causes), with your paths applied on top. A secret under a default name in your own data deeper than the ceiling still travels intact, as above.
1309
+
1308
1310
  #### A value interpolated into the message has no name to redact
1309
1311
 
1310
1312
  The case above is a secret inside a field's **value**. The sharper version is a value interpolated into the message itself, where there is no field at all:
@@ -1494,16 +1496,16 @@ There are **two** APIs on this class, and they do not share a signature shape.
1494
1496
 
1495
1497
  Every token is a `Symbol`, never a string, so it cannot collide with one of yours. Inject with an explicit `@Inject(TOKEN)`: the package is built without decorator metadata, and so is any consumer built the same way.
1496
1498
 
1497
- | Export | Provides | Use it to |
1498
- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1499
- | `LOGGER_OPTIONS_TOKEN` | the resolved `ResolvedBymaxLoggerModuleOptions` | read the effective configuration, defaults applied |
1500
- | `LOGGER_PINO_INSTANCE_TOKEN` | the underlying Pino instance | hand it to a library that wants a Pino logger |
1501
- | `LOGGER_DESTINATIONS_TOKEN` | the destinations array, `readonly ILogDestination[]` | inspect what is registered; do not mutate it |
1502
- | `LOGGER_REDACTOR_TOKEN` | the by-name redaction function, `(value: unknown) => unknown`. With `redactStrategy: 'paths'` it returns its input unchanged, because Pino's path redaction then runs at write time instead | apply the module's by-name redaction to a value of your own under the default `'names'` strategy; do not treat it as a sanitization boundary under `'paths'`. |
1503
- | `LOG_CONTEXT_TOKEN` | the `LogContextService` instance (an alias of the class) | inject the context by token |
1504
- | `REDACT_COMMON_FIELDS` | the default sensitive field **names**, matched at any depth | extend the defaults by reference instead of copying the list |
1505
- | `DEFAULT_REDACT_PATHS` | the legacy path expansion of those names | only with `redactStrategy: 'paths'` |
1506
- | `isValidTraceId(id)` | `true` for 32 lowercase hex characters that are not all zeros | apply the rule the trace mixin applies before it injects an id |
1499
+ | Export | Provides | Use it to |
1500
+ | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1501
+ | `LOGGER_OPTIONS_TOKEN` | the resolved `ResolvedBymaxLoggerModuleOptions` | read the effective configuration, defaults applied |
1502
+ | `LOGGER_PINO_INSTANCE_TOKEN` | the underlying Pino instance | hand it to a library that wants a Pino logger |
1503
+ | `LOGGER_DESTINATIONS_TOKEN` | the destinations array, `readonly ILogDestination[]` | inspect what is registered; do not mutate it |
1504
+ | `LOGGER_REDACTOR_TOKEN` | the by-name redaction function, `(value: unknown) => unknown`. With `redactStrategy: 'paths'` it censors no name outside an `Error`, because Pino's path redaction then runs at write time instead | apply the module's by-name redaction to a value of your own under the default `'names'` strategy; do not treat it as a sanitization boundary under `'paths'`. |
1505
+ | `LOG_CONTEXT_TOKEN` | the `LogContextService` instance (an alias of the class) | inject the context by token |
1506
+ | `REDACT_COMMON_FIELDS` | the default sensitive field **names**, matched at any depth | extend the defaults by reference instead of copying the list |
1507
+ | `DEFAULT_REDACT_PATHS` | the legacy path expansion of those names | only with `redactStrategy: 'paths'` |
1508
+ | `isValidTraceId(id)` | `true` for 32 lowercase hex characters that are not all zeros | apply the rule the trace mixin applies before it injects an id |
1507
1509
 
1508
1510
  ### Level maps (from `@bymax-one/nest-logger`)
1509
1511
 
@@ -2038,6 +2038,32 @@ function destinationToStream(destination, health) {
2038
2038
  });
2039
2039
  }
2040
2040
 
2041
+ // src/server/utils/redact-error-clone.util.ts
2042
+ function shadowHook(target) {
2043
+ Reflect.defineProperty(target, "toJSON", { value: void 0, configurable: true });
2044
+ }
2045
+ function withoutEnumerableKeys(clone) {
2046
+ for (const key of Object.keys(clone)) Reflect.deleteProperty(clone, key);
2047
+ }
2048
+ function discardWrite() {
2049
+ }
2050
+ function cloneError(error) {
2051
+ const descriptors = Object.getOwnPropertyDescriptors(error);
2052
+ for (const descriptor of Object.values(descriptors)) {
2053
+ descriptor.configurable = true;
2054
+ if ("value" in descriptor) descriptor.writable = true;
2055
+ else descriptor.set ??= discardWrite;
2056
+ }
2057
+ const clone = Object.create(Object.getPrototypeOf(error), descriptors);
2058
+ const { stack } = error;
2059
+ if (typeof stack === "string") {
2060
+ Reflect.defineProperty(clone, "stack", { value: stack, enumerable: false, writable: true });
2061
+ }
2062
+ withoutEnumerableKeys(clone);
2063
+ shadowHook(clone);
2064
+ return clone;
2065
+ }
2066
+
2041
2067
  // src/server/utils/redact-error-parts.util.ts
2042
2068
  function defineOwn(target, key, value) {
2043
2069
  Reflect.defineProperty(target, key, { value, enumerable: true, writable: true });
@@ -2154,30 +2180,6 @@ function resolveToJson(value, viaGet = false) {
2154
2180
  volatile: accessor || proxied
2155
2181
  };
2156
2182
  }
2157
- function shadowHook(target) {
2158
- Reflect.defineProperty(target, "toJSON", { value: void 0, configurable: true });
2159
- }
2160
- function withoutEnumerableKeys(clone) {
2161
- for (const key of Object.keys(clone)) Reflect.deleteProperty(clone, key);
2162
- }
2163
- function discardWrite() {
2164
- }
2165
- function cloneError(error) {
2166
- const descriptors = Object.getOwnPropertyDescriptors(error);
2167
- for (const descriptor of Object.values(descriptors)) {
2168
- descriptor.configurable = true;
2169
- if ("value" in descriptor) descriptor.writable = true;
2170
- else descriptor.set ??= discardWrite;
2171
- }
2172
- const clone = Object.create(Object.getPrototypeOf(error), descriptors);
2173
- const { stack } = error;
2174
- if (typeof stack === "string") {
2175
- Reflect.defineProperty(clone, "stack", { value: stack, enumerable: false, writable: true });
2176
- }
2177
- withoutEnumerableKeys(clone);
2178
- shadowHook(clone);
2179
- return clone;
2180
- }
2181
2183
  function walkArray(value, rules, depth2, ancestors, inSerialized) {
2182
2184
  const length = value.length;
2183
2185
  const copy = [];
@@ -2190,6 +2192,9 @@ function walkArray(value, rules, depth2, ancestors, inSerialized) {
2190
2192
  }
2191
2193
  return copy;
2192
2194
  }
2195
+ function errorRules(rules) {
2196
+ return rules.insideErrors ?? rules;
2197
+ }
2193
2198
  function walk(value, rules, depth2, ancestors, honorToJson, inSerialized = false) {
2194
2199
  if (value === null) {
2195
2200
  return value;
@@ -2207,7 +2212,7 @@ function walk(value, rules, depth2, ancestors, honorToJson, inSerialized = false
2207
2212
  return REDACT_CIRCULAR;
2208
2213
  }
2209
2214
  if (isError(value)) {
2210
- return walkError(value, rules, depth2, ancestors, honorToJson, inSerialized);
2215
+ return walkError(value, errorRules(rules), depth2, ancestors, honorToJson, inSerialized);
2211
2216
  }
2212
2217
  return walkObject(value, rules, depth2, ancestors, honorToJson, inSerialized);
2213
2218
  }
@@ -2314,7 +2319,7 @@ function errorPartsHost(rules, ancestors, inSerialized) {
2314
2319
  hasToJson: (value) => !rules.ownFields.safe && resolveToJson(value).method !== void 0
2315
2320
  };
2316
2321
  }
2317
- function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS) {
2322
+ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames) {
2318
2323
  const rules = {
2319
2324
  sensitive: new Set(Array.from(fieldNames, (name) => name.toLowerCase())),
2320
2325
  censor,
@@ -2323,9 +2328,15 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
2323
2328
  maxVisits,
2324
2329
  ownFields
2325
2330
  };
2331
+ const insideNames = errorOnlyNames === void 0 ? void 0 : new Set(Array.from(errorOnlyNames, (name) => name.toLowerCase()));
2326
2332
  return (value, isRecordRoot = false) => {
2327
2333
  try {
2328
- const call = { ...rules, visits: { count: 0 } };
2334
+ const visits = { count: 0 };
2335
+ const call = {
2336
+ ...rules,
2337
+ visits,
2338
+ insideErrors: insideNames === void 0 ? void 0 : { ...rules, sensitive: insideNames, visits, insideErrors: void 0 }
2339
+ };
2329
2340
  return walk(value, call, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
2330
2341
  } catch {
2331
2342
  return {
@@ -2566,6 +2577,9 @@ function resolveNameRedactor(options) {
2566
2577
  function ownFieldPolicyOf(options) {
2567
2578
  return createOwnFieldPolicy(options.errorOwnFields, options.errorOwnFieldNames);
2568
2579
  }
2580
+ function namesInsideErrors(options) {
2581
+ return options.shouldDisableDefaultRedact ? void 0 : REDACT_COMMON_FIELDS;
2582
+ }
2569
2583
  function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true) {
2570
2584
  const names = coversNames ? [
2571
2585
  ...options.shouldDisableDefaultRedact ? [] : REDACT_COMMON_FIELDS,
@@ -2576,12 +2590,13 @@ function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = tr
2576
2590
  if (!walks && resolveRedactOption(options) === void 0) {
2577
2591
  return PASS_THROUGH;
2578
2592
  }
2579
- return nestedErrorsAsData && walks ? createNameRedactor(
2593
+ return nestedErrorsAsData && (walks || !coversNames) ? createNameRedactor(
2580
2594
  names,
2581
2595
  options.redactCensor,
2582
2596
  ["err", ...Object.keys(options.serializers)],
2583
2597
  void 0,
2584
- ownFields
2598
+ ownFields,
2599
+ coversNames ? void 0 : namesInsideErrors(options)
2585
2600
  ) : createNameRedactor(names, options.redactCensor, void 0, void 0, ownFields);
2586
2601
  }
2587
2602
  function resolveRedactOption(options) {
@@ -2035,6 +2035,32 @@ function destinationToStream(destination, health) {
2035
2035
  });
2036
2036
  }
2037
2037
 
2038
+ // src/server/utils/redact-error-clone.util.ts
2039
+ function shadowHook(target) {
2040
+ Reflect.defineProperty(target, "toJSON", { value: void 0, configurable: true });
2041
+ }
2042
+ function withoutEnumerableKeys(clone) {
2043
+ for (const key of Object.keys(clone)) Reflect.deleteProperty(clone, key);
2044
+ }
2045
+ function discardWrite() {
2046
+ }
2047
+ function cloneError(error) {
2048
+ const descriptors = Object.getOwnPropertyDescriptors(error);
2049
+ for (const descriptor of Object.values(descriptors)) {
2050
+ descriptor.configurable = true;
2051
+ if ("value" in descriptor) descriptor.writable = true;
2052
+ else descriptor.set ??= discardWrite;
2053
+ }
2054
+ const clone = Object.create(Object.getPrototypeOf(error), descriptors);
2055
+ const { stack } = error;
2056
+ if (typeof stack === "string") {
2057
+ Reflect.defineProperty(clone, "stack", { value: stack, enumerable: false, writable: true });
2058
+ }
2059
+ withoutEnumerableKeys(clone);
2060
+ shadowHook(clone);
2061
+ return clone;
2062
+ }
2063
+
2038
2064
  // src/server/utils/redact-error-parts.util.ts
2039
2065
  function defineOwn(target, key, value) {
2040
2066
  Reflect.defineProperty(target, key, { value, enumerable: true, writable: true });
@@ -2151,30 +2177,6 @@ function resolveToJson(value, viaGet = false) {
2151
2177
  volatile: accessor || proxied
2152
2178
  };
2153
2179
  }
2154
- function shadowHook(target) {
2155
- Reflect.defineProperty(target, "toJSON", { value: void 0, configurable: true });
2156
- }
2157
- function withoutEnumerableKeys(clone) {
2158
- for (const key of Object.keys(clone)) Reflect.deleteProperty(clone, key);
2159
- }
2160
- function discardWrite() {
2161
- }
2162
- function cloneError(error) {
2163
- const descriptors = Object.getOwnPropertyDescriptors(error);
2164
- for (const descriptor of Object.values(descriptors)) {
2165
- descriptor.configurable = true;
2166
- if ("value" in descriptor) descriptor.writable = true;
2167
- else descriptor.set ??= discardWrite;
2168
- }
2169
- const clone = Object.create(Object.getPrototypeOf(error), descriptors);
2170
- const { stack } = error;
2171
- if (typeof stack === "string") {
2172
- Reflect.defineProperty(clone, "stack", { value: stack, enumerable: false, writable: true });
2173
- }
2174
- withoutEnumerableKeys(clone);
2175
- shadowHook(clone);
2176
- return clone;
2177
- }
2178
2180
  function walkArray(value, rules, depth2, ancestors, inSerialized) {
2179
2181
  const length = value.length;
2180
2182
  const copy = [];
@@ -2187,6 +2189,9 @@ function walkArray(value, rules, depth2, ancestors, inSerialized) {
2187
2189
  }
2188
2190
  return copy;
2189
2191
  }
2192
+ function errorRules(rules) {
2193
+ return rules.insideErrors ?? rules;
2194
+ }
2190
2195
  function walk(value, rules, depth2, ancestors, honorToJson, inSerialized = false) {
2191
2196
  if (value === null) {
2192
2197
  return value;
@@ -2204,7 +2209,7 @@ function walk(value, rules, depth2, ancestors, honorToJson, inSerialized = false
2204
2209
  return REDACT_CIRCULAR;
2205
2210
  }
2206
2211
  if (isError(value)) {
2207
- return walkError(value, rules, depth2, ancestors, honorToJson, inSerialized);
2212
+ return walkError(value, errorRules(rules), depth2, ancestors, honorToJson, inSerialized);
2208
2213
  }
2209
2214
  return walkObject(value, rules, depth2, ancestors, honorToJson, inSerialized);
2210
2215
  }
@@ -2311,7 +2316,7 @@ function errorPartsHost(rules, ancestors, inSerialized) {
2311
2316
  hasToJson: (value) => !rules.ownFields.safe && resolveToJson(value).method !== void 0
2312
2317
  };
2313
2318
  }
2314
- function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS) {
2319
+ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames) {
2315
2320
  const rules = {
2316
2321
  sensitive: new Set(Array.from(fieldNames, (name) => name.toLowerCase())),
2317
2322
  censor,
@@ -2320,9 +2325,15 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
2320
2325
  maxVisits,
2321
2326
  ownFields
2322
2327
  };
2328
+ const insideNames = errorOnlyNames === void 0 ? void 0 : new Set(Array.from(errorOnlyNames, (name) => name.toLowerCase()));
2323
2329
  return (value, isRecordRoot = false) => {
2324
2330
  try {
2325
- const call = { ...rules, visits: { count: 0 } };
2331
+ const visits = { count: 0 };
2332
+ const call = {
2333
+ ...rules,
2334
+ visits,
2335
+ insideErrors: insideNames === void 0 ? void 0 : { ...rules, sensitive: insideNames, visits, insideErrors: void 0 }
2336
+ };
2326
2337
  return walk(value, call, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
2327
2338
  } catch {
2328
2339
  return {
@@ -2563,6 +2574,9 @@ function resolveNameRedactor(options) {
2563
2574
  function ownFieldPolicyOf(options) {
2564
2575
  return createOwnFieldPolicy(options.errorOwnFields, options.errorOwnFieldNames);
2565
2576
  }
2577
+ function namesInsideErrors(options) {
2578
+ return options.shouldDisableDefaultRedact ? void 0 : REDACT_COMMON_FIELDS;
2579
+ }
2566
2580
  function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true) {
2567
2581
  const names = coversNames ? [
2568
2582
  ...options.shouldDisableDefaultRedact ? [] : REDACT_COMMON_FIELDS,
@@ -2573,12 +2587,13 @@ function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = tr
2573
2587
  if (!walks && resolveRedactOption(options) === void 0) {
2574
2588
  return PASS_THROUGH;
2575
2589
  }
2576
- return nestedErrorsAsData && walks ? createNameRedactor(
2590
+ return nestedErrorsAsData && (walks || !coversNames) ? createNameRedactor(
2577
2591
  names,
2578
2592
  options.redactCensor,
2579
2593
  ["err", ...Object.keys(options.serializers)],
2580
2594
  void 0,
2581
- ownFields
2595
+ ownFields,
2596
+ coversNames ? void 0 : namesInsideErrors(options)
2582
2597
  ) : createNameRedactor(names, options.redactCensor, void 0, void 0, ownFields);
2583
2598
  }
2584
2599
  function resolveRedactOption(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-logger",
3
- "version": "1.4.14",
3
+ "version": "1.4.15",
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",
@@ -63,7 +63,8 @@
63
63
  "check:published": "node scripts/check-published-surface.mjs",
64
64
  "check:file-length": "node scripts/check-file-length.mjs",
65
65
  "clean": "rm -rf dist coverage",
66
- "lint": "eslint src scripts test bench '*.config.ts' '*.config.mjs' '*.config.cjs'",
66
+ "check:socket-gate": "node scripts/check-socket-gate.mjs",
67
+ "lint": "eslint src scripts test bench '*.config.ts' '*.config.mjs' '*.config.cjs' && pnpm check:socket-gate",
67
68
  "lint:fix": "eslint src scripts test bench '*.config.ts' '*.config.mjs' '*.config.cjs' --fix",
68
69
  "mutation": "stryker run",
69
70
  "mutation:full": "node -e \"require('node:fs').rmSync('reports/stryker-incremental.json',{force:true,recursive:true})\" && stryker run",