@bymax-one/nest-logger 1.4.13 → 1.4.14

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,111 @@ heading here.
11
11
 
12
12
  ## [Unreleased]
13
13
 
14
+ ## [1.4.14] - 2026-11-09
15
+
16
+ ### Added
17
+
18
+ - **A host can stop the tenant id from being whatever the client sent.** The bundled
19
+ `RequestIdMiddleware` copies the `x-tenant-id` header into `tenantId` on every entry of the
20
+ request, so any client could attribute its requests to another tenant. The default is unchanged.
21
+ `http.tenantIdHeader` now also accepts `false`, which reads no header, and the new
22
+ `http.tenantIdResolver: (request) => string | undefined` takes the tenant from what the host
23
+ trusts. When a resolver is given it is the only source: the header is not read, whether the
24
+ resolver answers or not. Its answer passes the same 256-character rule as the header, and a
25
+ resolver that throws gives no `tenantId`.
26
+ #### Apply to a derived backend
27
+ A backend that authenticates its tenants sets `tenantIdHeader: false` or supplies
28
+ `tenantIdResolver`; otherwise nothing changes.
29
+
30
+ ### Fixed
31
+
32
+ - **A log call no longer throws for an `Error` that holds an accessor with no setter, under
33
+ `redactStrategy: 'paths'`.** A non-enumerable getter-only property on an `Error` (a
34
+ `defineProperty` with `get` and no `set`) met a path that censors it, and the assignment of the
35
+ censor threw out of the log call. The copy of the `Error` the walk makes now discards the write.
36
+ The secret was never written; the call used to fail.
37
+ **Apply to a derived backend:** nothing to do.
38
+ - **A `tenantIdResolver` written as `async` no longer ends the process.** Its answer is a promise,
39
+ which is no tenant id, and one that later rejected was an unhandled rejection. The answer is
40
+ still ignored, and its rejection is now absorbed. Resolve the tenant synchronously, or set it
41
+ later with `LogContextService.set('tenantId', ...)`.
42
+ **Apply to a derived backend:** a resolver that is `async` gave no tenant id before and gives
43
+ none now; read the tenant synchronously, or set it with `LogContextService.set`.
44
+ - **The 415 the body parser raises no longer repeats what the client sent.** `HttpExceptionFilter`
45
+ answered an exposed client error with the parser's own message, and for an unsupported
46
+ `Content-Encoding` or charset that message carries the header value inside quotes. The value
47
+ reached the response and the `HTTP_EXCEPTION_HANDLED` entry. Both now say
48
+ `unsupported content encoding` or `unsupported charset`. The status and every other message are
49
+ unchanged.
50
+ **Apply to a derived backend:** nothing to do.
51
+ - **The query string of a request no longer reaches a logged exception message.** The `url` fields
52
+ of the access log, the interceptor and the filter always had the query stripped, but Nest words
53
+ its not-found message as `Cannot GET /path?code=...&token=...`, with the whole URL, and
54
+ `HttpExceptionFilter` wrote that message as the `msg` of `HTTP_EXCEPTION_HANDLED`. Any request to
55
+ a route that does not exist, such as an OAuth callback or a reset link on a mistyped path,
56
+ put its `code`, `state` or `token` in the log, where name-based redaction cannot censor free
57
+ text. The request's own query string (`originalUrl` and `url`, as a mounted request differs) is
58
+ now cut out of the message by exact substring, in the filter's `msg` and in the `errorMessage` of
59
+ the interceptor and of the access log. The response is unchanged. A secret in the path itself
60
+ (`;jsessionid=...`, a token segment, a percent-encoded `%3F`) is part of the path and stays.
61
+ **Apply to a derived backend:** nothing to do.
62
+ - **The library's entry for a body the parser refused no longer quotes the body.** The parser
63
+ words the message of a JSON syntax error with a piece of the body, or a partial value when one is
64
+ left unquoted, and a `verify` function's message is the application's own text.
65
+ `HttpExceptionFilter` wrote that message as the `msg` of `HTTP_EXCEPTION_HANDLED`, where
66
+ name-based redaction cannot censor it. For `entity.parse.failed`, `entity.verify.failed` and the
67
+ two unsupported 415 types the entry now carries a fixed message and the parser `type` as
68
+ `bodyParserType`; the interceptor's `errorMessage` does the same. Any other exposed client error
69
+ is logged with its own message, as before. Nest rebuilds the parser's `SyntaxError` (malformed
70
+ JSON) as a `BadRequestException` before any filter runs, so on the Express adapter
71
+ `BymaxLoggerModule` mounts a small error layer after the body parser that keeps the parser's
72
+ `type` for the filter; another adapter, or a parser mounted after `app.init()`, keeps the old
73
+ message. The response body is unchanged, and stays the application's concern.
74
+ **Apply to a derived backend:** an alert or query that matched the old `msg` text of these
75
+ entries matches `bodyParserType` now.
76
+ - **A log call no longer throws under `redactStrategy: 'paths'` on JSON-shaped metadata.** A
77
+ `token` or `password` inside an object held under `cookie` or `authorization` made `@pinojs/redact` throw `TypeError: Cannot assign to read only property`, which the
78
+ call surfaced to the application. That module assigns its censor into the object it is given, in
79
+ strict mode, and the copies the name walk builds had non-writable properties. They are
80
+ writable now, and so is the clone of an `Error`, which could also throw on 1.4.13 when a consumer
81
+ path with a wildcard aimed at its `stack`, `message` or `cause` (`a.*.err.stack`) came together
82
+ with a second path (a lone path did not throw). The secret is still censored, and the output of
83
+ every other input is the same. The default `'names'` strategy was never affected.
84
+ **Apply to a derived backend:** nothing to do.
85
+ - **No `toJSON` hook the walk did not see survives the redaction, in the default mode.**
86
+ `JSON.stringify` reads `toJSON` after the redaction, with `[[Get]]`, so a hook the walk had not
87
+ followed ran afterwards and could write a value under a censored name in clear. Shapes that did
88
+ that: a function-valued Proxy whose `get` trap answers a hook that its `has` and descriptor traps
89
+ hide, a `toJSON` accessor on an `Error` or on any object that answers no hook the first time and a
90
+ hook afterwards, which the property loop or the clone of an `Error` copied along with every other
91
+ property, and a function whose prototype is such a Proxy. A callable whose answer can change (a
92
+ Proxy, a function with a `toJSON` accessor, or one with a Proxy on its prototype chain) is now
93
+ dropped as a function with no hook is, a `toJSON` that reads as a function where the stringifier
94
+ would honour it is not copied, and the clone of an `Error` ends with an own, non-enumerable
95
+ `toJSON` set to `undefined`, which the stringifier reads before any hook on the prototype chain.
96
+ The rule is about the output object, not about what the walk read earlier, which the original
97
+ can change before the output is built.
98
+ Ordinary input is unchanged, including a `toJSON` key that is not a function. These shapes need an
99
+ object built by code that hides its hook, not a value read from data. The one visible change is
100
+ that `Object.getOwnPropertyNames` of a logged `Error` clone lists `toJSON`; `Object.keys`, `for...in`
101
+ and the JSON output are the same.
102
+ **Apply to a derived backend:** nothing to do.
103
+
104
+ ### Internal
105
+
106
+ - **`as const` tables are now mutated entry by entry in a development check.** Stryker neither
107
+ removes a property or an element from a constant table nor changes a number in it, so an entry
108
+ could disappear with every test green. `scripts/mutate-const-tables.mjs` does it, against a test
109
+ command you give it, and `CLAUDE.md` has the command. It is a development tool and not a CI
110
+ step. Its first run found 20 entries of the default redaction set that no test pinned, from
111
+ `passwordHash` to `req.headers["x-auth-token"]`; a spec now pins every name and path that was
112
+ shipped, and censors each name through the default redactor. Nothing in the package changes.
113
+ - **The `minimatch` denial-of-service advisory is closed in the dev tree.** The vulnerable range
114
+ (>= 7.0.0 < 11.0.1) was reachable through the TypeScript ESLint parser, Stryker and Jest coverage. The
115
+ 10.x copies resolve to 11 and `test-exclude` moves to 8, which uses a `glob` that accepts it.
116
+ Development dependencies only: the published package has no dependencies and its `dist/` does
117
+ not change.
118
+
14
119
  ## [1.4.13] - 2026-11-08
15
120
 
16
121
  ### Fixed
@@ -2583,7 +2688,8 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
2583
2688
  - Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
2584
2689
  `release.yml`, Dependabot, and issue templates
2585
2690
 
2586
- [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.13...HEAD
2691
+ [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.14...HEAD
2692
+ [1.4.14]: https://github.com/bymaxone/nest-logger/compare/v1.4.13...v1.4.14
2587
2693
  [1.4.13]: https://github.com/bymaxone/nest-logger/compare/v1.4.12...v1.4.13
2588
2694
  [1.4.12]: https://github.com/bymaxone/nest-logger/compare/v1.4.11...v1.4.12
2589
2695
  [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