noctcore-observability/no-sensitive-fields-in-logs
noctcore-observability/no-sensitive-fields-in-logs
- Package
- observability v1.0.0
- Preset
- recommended
- Severity
- error
- Autofix
- No
- Suggestions
- No
- Options
- Optional
- Type info
- Not needed
A name-heuristic guard against writing credentials and secrets into log sinks. Ships at error.
Logs are long-lived, widely readable, and shipped to third-party aggregators. A password, token,
secret, or authorization header written into a log line is a credential leak that outlives the
request by months. This rule catches the most common shape — a variable, property, or object key
whose name matches a sensitive-field denylist appearing inside a logger call.
It reads names, never values, so it is a heuristic. It still ships at error: a miss puts a
credential in a long-lived log sink, while a false positive costs a rename or a redact() call.
Tests that log a secret on purpose (to prove a redaction boundary works) should turn the rule off for
those files in config.
What it flags
Section titled “What it flags”Inside a logger call (<logger>.<method>(...)), any identifier, member-access property, or object key
whose name matches the denylist:
// all three flaglogger.info('login', { password });logger.error('auth failed', { userPassword: pw });logger.info('session', user.token);// log who, not the credentiallogger.info('login', { userId });logger.error('auth failed', { userId, reason: 'bad-credentials' });logger.info('session', { sessionId: user.sessionId });A call to a redactor is a boundary. The rule does not look inside redact(...) or mask(...) (set
the list with redactors), and an object key whose value is a redactor call is not reported:
// the value is redacted, so neither the key nor the argument is reportedlogger.info('login', { token: redact(token) });logger.info('login', { password: mask(user.password) });Matching is name-segment aware. A single-word denyName (token) matches a camelCase or
snake_case segment (accessToken, access_token) but not a longer word that merely contains it
(tokenize, tokenizer). A multi-word denyName (apiKey) matches the compacted name
(myApiKey → contains apikey).
What it does not flag
Section titled “What it does not flag”String literals are never inspected — only names — so a message that mentions a sensitive word is fine:
// a literal, not a valuelogger.info('password reset email sent');- A longer word that merely contains a denyName (
tokenizer,tokenize): matching is by name segment, as described above. - Names that read as a flag, a count or a timestamp about the field rather than the field itself:
a leading
is,has,should,can,did,was,needsorshowsegment, or a trailingcount,length,size,ttl,at,in,expires,expiry,consent,enabledorrequiredsegment (hasPassword,tokenCount,passwordLength,tokenExpiresAt,cookieConsent). - Names listed in
allowNames. - Sensitive names outside a logger call (
save({ password })). A logger call is a name fromloggerswith a method frommethods; the defaults coverconsole.log, Nest’sthis.logger.log/verbose/fataland pino’strace/fatal.
Options
Section titled “Options”| Option | Type | Default | Meaning |
|---|---|---|---|
denyNames |
string[] |
['password', 'token', 'secret', 'authorization', 'cookie', 'apiKey', 'ssn'] |
Field names to treat as sensitive (case-insensitive, segment-aware). |
redactors |
string[] |
['redact', 'mask'] |
Called names (redact(x), utils.redact(x)) whose arguments are not inspected. |
allowNames |
string[] |
[] |
Exact names never reported (csrfToken). |
loggers |
string[] |
['console', 'logger', 'log'] |
Logger object names to scan. |
methods |
string[] |
['info', 'warn', 'error', 'debug', 'log', 'trace', 'fatal', 'verbose'] |
Method names that make a call on a logger a log call. |
'noctcore-observability/no-sensitive-fields-in-logs': ['error', { denyNames: ['password', 'token', 'secret', 'authorization', 'cookie', 'apiKey', 'ssn', 'iban'], redactors: ['redact', 'mask', 'scrub'],}]When not to use it
Section titled “When not to use it”If your logging pipeline already redacts sensitive fields centrally (a serializer denylist), this
rule is redundant. Otherwise keep it on at error as a second line of defence.