@bymax-one/nest-logger 1.4.13 → 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,136 @@ 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
+
39
+ ## [1.4.14] - 2026-11-09
40
+
41
+ ### Added
42
+
43
+ - **A host can stop the tenant id from being whatever the client sent.** The bundled
44
+ `RequestIdMiddleware` copies the `x-tenant-id` header into `tenantId` on every entry of the
45
+ request, so any client could attribute its requests to another tenant. The default is unchanged.
46
+ `http.tenantIdHeader` now also accepts `false`, which reads no header, and the new
47
+ `http.tenantIdResolver: (request) => string | undefined` takes the tenant from what the host
48
+ trusts. When a resolver is given it is the only source: the header is not read, whether the
49
+ resolver answers or not. Its answer passes the same 256-character rule as the header, and a
50
+ resolver that throws gives no `tenantId`.
51
+ #### Apply to a derived backend
52
+ A backend that authenticates its tenants sets `tenantIdHeader: false` or supplies
53
+ `tenantIdResolver`; otherwise nothing changes.
54
+
55
+ ### Fixed
56
+
57
+ - **A log call no longer throws for an `Error` that holds an accessor with no setter, under
58
+ `redactStrategy: 'paths'`.** A non-enumerable getter-only property on an `Error` (a
59
+ `defineProperty` with `get` and no `set`) met a path that censors it, and the assignment of the
60
+ censor threw out of the log call. The copy of the `Error` the walk makes now discards the write.
61
+ The secret was never written; the call used to fail.
62
+ **Apply to a derived backend:** nothing to do.
63
+ - **A `tenantIdResolver` written as `async` no longer ends the process.** Its answer is a promise,
64
+ which is no tenant id, and one that later rejected was an unhandled rejection. The answer is
65
+ still ignored, and its rejection is now absorbed. Resolve the tenant synchronously, or set it
66
+ later with `LogContextService.set('tenantId', ...)`.
67
+ **Apply to a derived backend:** a resolver that is `async` gave no tenant id before and gives
68
+ none now; read the tenant synchronously, or set it with `LogContextService.set`.
69
+ - **The 415 the body parser raises no longer repeats what the client sent.** `HttpExceptionFilter`
70
+ answered an exposed client error with the parser's own message, and for an unsupported
71
+ `Content-Encoding` or charset that message carries the header value inside quotes. The value
72
+ reached the response and the `HTTP_EXCEPTION_HANDLED` entry. Both now say
73
+ `unsupported content encoding` or `unsupported charset`. The status and every other message are
74
+ unchanged.
75
+ **Apply to a derived backend:** nothing to do.
76
+ - **The query string of a request no longer reaches a logged exception message.** The `url` fields
77
+ of the access log, the interceptor and the filter always had the query stripped, but Nest words
78
+ its not-found message as `Cannot GET /path?code=...&token=...`, with the whole URL, and
79
+ `HttpExceptionFilter` wrote that message as the `msg` of `HTTP_EXCEPTION_HANDLED`. Any request to
80
+ a route that does not exist, such as an OAuth callback or a reset link on a mistyped path,
81
+ put its `code`, `state` or `token` in the log, where name-based redaction cannot censor free
82
+ text. The request's own query string (`originalUrl` and `url`, as a mounted request differs) is
83
+ now cut out of the message by exact substring, in the filter's `msg` and in the `errorMessage` of
84
+ the interceptor and of the access log. The response is unchanged. A secret in the path itself
85
+ (`;jsessionid=...`, a token segment, a percent-encoded `%3F`) is part of the path and stays.
86
+ **Apply to a derived backend:** nothing to do.
87
+ - **The library's entry for a body the parser refused no longer quotes the body.** The parser
88
+ words the message of a JSON syntax error with a piece of the body, or a partial value when one is
89
+ left unquoted, and a `verify` function's message is the application's own text.
90
+ `HttpExceptionFilter` wrote that message as the `msg` of `HTTP_EXCEPTION_HANDLED`, where
91
+ name-based redaction cannot censor it. For `entity.parse.failed`, `entity.verify.failed` and the
92
+ two unsupported 415 types the entry now carries a fixed message and the parser `type` as
93
+ `bodyParserType`; the interceptor's `errorMessage` does the same. Any other exposed client error
94
+ is logged with its own message, as before. Nest rebuilds the parser's `SyntaxError` (malformed
95
+ JSON) as a `BadRequestException` before any filter runs, so on the Express adapter
96
+ `BymaxLoggerModule` mounts a small error layer after the body parser that keeps the parser's
97
+ `type` for the filter; another adapter, or a parser mounted after `app.init()`, keeps the old
98
+ message. The response body is unchanged, and stays the application's concern.
99
+ **Apply to a derived backend:** an alert or query that matched the old `msg` text of these
100
+ entries matches `bodyParserType` now.
101
+ - **A log call no longer throws under `redactStrategy: 'paths'` on JSON-shaped metadata.** A
102
+ `token` or `password` inside an object held under `cookie` or `authorization` made `@pinojs/redact` throw `TypeError: Cannot assign to read only property`, which the
103
+ call surfaced to the application. That module assigns its censor into the object it is given, in
104
+ strict mode, and the copies the name walk builds had non-writable properties. They are
105
+ writable now, and so is the clone of an `Error`, which could also throw on 1.4.13 when a consumer
106
+ path with a wildcard aimed at its `stack`, `message` or `cause` (`a.*.err.stack`) came together
107
+ with a second path (a lone path did not throw). The secret is still censored, and the output of
108
+ every other input is the same. The default `'names'` strategy was never affected.
109
+ **Apply to a derived backend:** nothing to do.
110
+ - **No `toJSON` hook the walk did not see survives the redaction, in the default mode.**
111
+ `JSON.stringify` reads `toJSON` after the redaction, with `[[Get]]`, so a hook the walk had not
112
+ followed ran afterwards and could write a value under a censored name in clear. Shapes that did
113
+ that: a function-valued Proxy whose `get` trap answers a hook that its `has` and descriptor traps
114
+ hide, a `toJSON` accessor on an `Error` or on any object that answers no hook the first time and a
115
+ hook afterwards, which the property loop or the clone of an `Error` copied along with every other
116
+ property, and a function whose prototype is such a Proxy. A callable whose answer can change (a
117
+ Proxy, a function with a `toJSON` accessor, or one with a Proxy on its prototype chain) is now
118
+ dropped as a function with no hook is, a `toJSON` that reads as a function where the stringifier
119
+ would honour it is not copied, and the clone of an `Error` ends with an own, non-enumerable
120
+ `toJSON` set to `undefined`, which the stringifier reads before any hook on the prototype chain.
121
+ The rule is about the output object, not about what the walk read earlier, which the original
122
+ can change before the output is built.
123
+ Ordinary input is unchanged, including a `toJSON` key that is not a function. These shapes need an
124
+ object built by code that hides its hook, not a value read from data. The one visible change is
125
+ that `Object.getOwnPropertyNames` of a logged `Error` clone lists `toJSON`; `Object.keys`, `for...in`
126
+ and the JSON output are the same.
127
+ **Apply to a derived backend:** nothing to do.
128
+
129
+ ### Internal
130
+
131
+ - **`as const` tables are now mutated entry by entry in a development check.** Stryker neither
132
+ removes a property or an element from a constant table nor changes a number in it, so an entry
133
+ could disappear with every test green. `scripts/mutate-const-tables.mjs` does it, against a test
134
+ command you give it, and `CLAUDE.md` has the command. It is a development tool and not a CI
135
+ step. Its first run found 20 entries of the default redaction set that no test pinned, from
136
+ `passwordHash` to `req.headers["x-auth-token"]`; a spec now pins every name and path that was
137
+ shipped, and censors each name through the default redactor. Nothing in the package changes.
138
+ - **The `minimatch` denial-of-service advisory is closed in the dev tree.** The vulnerable range
139
+ (>= 7.0.0 < 11.0.1) was reachable through the TypeScript ESLint parser, Stryker and Jest coverage. The
140
+ 10.x copies resolve to 11 and `test-exclude` moves to 8, which uses a `glob` that accepts it.
141
+ Development dependencies only: the published package has no dependencies and its `dist/` does
142
+ not change.
143
+
14
144
  ## [1.4.13] - 2026-11-08
15
145
 
16
146
  ### Fixed
@@ -2583,7 +2713,9 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
2583
2713
  - Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
2584
2714
  `release.yml`, Dependabot, and issue templates
2585
2715
 
2586
- [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.13...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
2718
+ [1.4.14]: https://github.com/bymaxone/nest-logger/compare/v1.4.13...v1.4.14
2587
2719
  [1.4.13]: https://github.com/bymaxone/nest-logger/compare/v1.4.12...v1.4.13
2588
2720
  [1.4.12]: https://github.com/bymaxone/nest-logger/compare/v1.4.11...v1.4.12
2589
2721
  [1.4.11]: https://github.com/bymaxone/nest-logger/compare/v1.4.10...v1.4.11
package/README.md CHANGED
@@ -373,7 +373,9 @@ in a guard, and at that point there is no principal yet. The acting user is on t
373
373
  entry, where the guard has populated it. Both entries carry the same `requestId`, so joining on
374
374
  that gives the whole request.
375
375
 
376
- URLs are automatically normalized — `/users/550e8400-e29b-41d4-a716-446655440000` becomes `/users/:id` so Loki/Grafana cardinality stays bounded. The query string is stripped from every logged URL, because a magic-link token or reset code in a query parameter is a secret no key-name redaction can scrub out of a string value.
376
+ For the parser errors listed here the request body's text stays out of the library's own entry. For a body that does not parse (`entity.parse.failed`), a body the `verify` function of the parser refuses (`entity.verify.failed`) and an unsupported content encoding or charset, `HTTP_EXCEPTION_HANDLED` carries a fixed message and the parser `type` in a `bodyParserType` field, because the parser's message can quote part of the body and no key-name redaction can censor a string. The response body is the application's concern: for a body that does not parse or that `verify` refuses, the parser's own message still reaches the client unless the application answers the error itself. A `verify` function that gives its error a `type` of its own is outside this list. The malformed-JSON case needs the Express adapter and a body parser mounted before `app.init()`, as Nest's own default one is: the module mounts a small error layer after that parser, because Nest rebuilds the parser's error as a `BadRequestException` that no longer has its `type`. With another adapter, or a parser you mount after `app.init()`, that entry keeps the parser's message.
377
+
378
+ URLs are automatically normalized — `/users/550e8400-e29b-41d4-a716-446655440000` becomes `/users/:id` so Loki/Grafana cardinality stays bounded. The query string is stripped from every logged URL, because a magic-link token or reset code in a query parameter is a secret no key-name redaction can scrub out of a string value. The same cut applies to the message of a logged exception: Nest words its not-found message as `Cannot GET /path?code=...`, so the request's own query string is removed from `HTTP_EXCEPTION_HANDLED`'s `msg` and from `errorMessage`. The response still carries what Nest wrote, which is the application's concern. Only a literal `?` starts a query: a secret placed in the path itself (`;jsessionid=...`, a token segment, a percent-encoded `%3F`) is part of the path and stays in `url`.
377
379
 
378
380
  > [!IMPORTANT]
379
381
  > **Why middleware and not an interceptor.** NestJS runs middleware → guards → interceptors →
@@ -805,6 +807,11 @@ The bundled `RequestIdMiddleware` does not trust the headers it reads. A request
805
807
  | `x-request-id` | a fresh UUID, or none when `http.shouldGenerateRequestId` is `false` (an enclosing scope's `requestId`, if any, is then inherited) |
806
808
  | the tenant header (`http.tenantIdHeader`) | no `tenantId` from the header; a tenant is never minted |
807
809
 
810
+ **A `tenantId` read from the header is what the client asserted.** Any client can send any tenant in `x-tenant-id`, and every entry of its requests will carry it. The 256-character rule above keeps the value safe to write; it does not make it true. Do not use a header-derived `tenantId` to decide whose data an entry is about unless something in front of the application sets or overwrites the header. A host that authenticates its tenants has two options, and both leave the default unchanged for everyone else:
811
+
812
+ - `http: { tenantIdHeader: false }` reads no header, so the middleware takes no `tenantId` from the request.
813
+ - `http: { tenantIdResolver: (req) => ... }` takes the tenant from what the host trusts, for example a value an earlier middleware put on the request after verifying a token. When a resolver is given it is the only source: the header is not read even if the resolver answers nothing, so a client cannot fall back to it. The answer passes the same 256-character rule, and a resolver that throws gives no `tenantId`. The middleware runs before guards, so a tenant known only after authentication is set later with `LogContextService.set('tenantId', ...)`.
814
+
808
815
  An accepted id is echoed back on the response `x-request-id` header and written to every entry the request produces, which is why the set is narrow. The example above reads the header raw to stay short; use `RequestIdMiddleware` through `applyAccessLog(app)` or `applyRequestIdMiddleware(consumer)` unless you apply the same rule yourself.
809
816
 
810
817
  ---
@@ -841,13 +848,14 @@ Full options reference for `BymaxLoggerModule.forRoot(options)`:
841
848
 
842
849
  ### `http` options
843
850
 
844
- | Option | Type | Default | Description |
845
- | ------------------------------ | ---------- | ------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
846
- | `http.isEnabled` | `boolean` | `false` | Register `HttpLoggingInterceptor` (and, on `forRoot`, `HttpExceptionFilter`) globally |
847
- | `http.shouldCaptureExceptions` | `boolean` | `true` | Capture unhandled HTTP exceptions and emit `HTTP_EXCEPTION_UNHANDLED`. `forRoot` only: see the note under [Async configuration](#3-async-configuration-with-configservice) |
848
- | `http.shouldGenerateRequestId` | `boolean` | `true` | Generate a `requestId` when the inbound request header is absent |
849
- | `http.excludePaths` | `RegExp[]` | `[/^\/health$/, /^\/health\/live$/, /^\/health\/ready$/, /^\/metrics$/]` | Paths that bypass HTTP logging. Use anchored, linear-time regexes (ReDoS-safe) |
850
- | `http.tenantIdHeader` | `string` | `'x-tenant-id'` | Request header carrying the tenant identifier |
851
+ | Option | Type | Default | Description |
852
+ | ------------------------------ | ------------------------------ | ------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
853
+ | `http.isEnabled` | `boolean` | `false` | Register `HttpLoggingInterceptor` (and, on `forRoot`, `HttpExceptionFilter`) globally |
854
+ | `http.shouldCaptureExceptions` | `boolean` | `true` | Capture unhandled HTTP exceptions and emit `HTTP_EXCEPTION_UNHANDLED`. `forRoot` only: see the note under [Async configuration](#3-async-configuration-with-configservice) |
855
+ | `http.shouldGenerateRequestId` | `boolean` | `true` | Generate a `requestId` when the inbound request header is absent |
856
+ | `http.excludePaths` | `RegExp[]` | `[/^\/health$/, /^\/health\/live$/, /^\/health\/ready$/, /^\/metrics$/]` | Paths that bypass HTTP logging. Use anchored, linear-time regexes (ReDoS-safe) |
857
+ | `http.tenantIdHeader` | `string \| false` | `'x-tenant-id'` | Request header carrying the tenant identifier, or `false` to read none. A value from the header is what the client asserted: see [Inbound `x-request-id` and tenant header](#inbound-x-request-id-and-tenant-header) |
858
+ | `http.tenantIdResolver` | `(req) => string \| undefined` | none | Resolves the tenant id on the server side. When given it is the only source and the header is not read |
851
859
 
852
860
  ### `otel` options
853
861
 
@@ -1297,6 +1305,8 @@ There is no name rule that reaches the second one, and scanning inside values fo
1297
1305
 
1298
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.
1299
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
+
1300
1310
  #### A value interpolated into the message has no name to redact
1301
1311
 
1302
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:
@@ -1486,16 +1496,16 @@ There are **two** APIs on this class, and they do not share a signature shape.
1486
1496
 
1487
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.
1488
1498
 
1489
- | Export | Provides | Use it to |
1490
- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1491
- | `LOGGER_OPTIONS_TOKEN` | the resolved `ResolvedBymaxLoggerModuleOptions` | read the effective configuration, defaults applied |
1492
- | `LOGGER_PINO_INSTANCE_TOKEN` | the underlying Pino instance | hand it to a library that wants a Pino logger |
1493
- | `LOGGER_DESTINATIONS_TOKEN` | the destinations array, `readonly ILogDestination[]` | inspect what is registered; do not mutate it |
1494
- | `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'`. |
1495
- | `LOG_CONTEXT_TOKEN` | the `LogContextService` instance (an alias of the class) | inject the context by token |
1496
- | `REDACT_COMMON_FIELDS` | the default sensitive field **names**, matched at any depth | extend the defaults by reference instead of copying the list |
1497
- | `DEFAULT_REDACT_PATHS` | the legacy path expansion of those names | only with `redactStrategy: 'paths'` |
1498
- | `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 |
1499
1509
 
1500
1510
  ### Level maps (from `@bymax-one/nest-logger`)
1501
1511