Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Sanitize errors and redact sensitive fields in the central logger
Enforce safe error serialization and structured-field redaction centrally so ordinary, framework and fatal logging paths cannot bypass call-site sanitization.
Bad example
| 1 | const logger = pino({ redact: ['*.token'] }); |
| 2 | logger.error({ err: requestError }, 'Request failed'); |
Explanation (EN)
A shallow wildcard does not cover nested request configuration or secrets embedded in error text and URLs.
Objašnjenje (HR)
Plitki uzorak ne pokriva ugniježđenu konfiguraciju zahtjeva ni tajne unutar teksta i URL-ova.
Good example
| 1 | import { serializeSafeError } from './safe-error'; |
| 2 |
|
| 3 | const logger = pino({ |
| 4 | serializers: { err: serializeSafeError }, |
| 5 | redact: { |
| 6 | paths: ['req.headers.authorization', 'req.headers.cookie'], |
| 7 | censor: '[REDACTED]', |
| 8 | }, |
| 9 | }); |
| 10 | logger.error({ err: requestError }, 'Request failed'); |
Explanation (EN)
The audited serializer allowlists error fields and sanitizes retained text, URLs and causes. Structured redaction adds protection for known request fields.
Objašnjenje (HR)
Provjeren serializer dopušta samo sigurna polja pogreške i čisti zadržani tekst, URL-ove i uzroke. Redakcija dodatno štiti poznata polja zahtjeva.
Notes (EN)
Keep logged data minimal. Register the safe serializer on the shared logger used by ordinary calls, framework adapters and crash handlers. Do not copy arbitrary error.config, headers or request objects. Sanitize retained messages, stack text, URLs and nested causes according to the data policy. Test the actual serialized output with synthetic secret markers through every logging entry point. A one-level wildcard is not recursive and a list of object paths does not sanitize arbitrary strings.
Bilješke (HR)
Zapisuj najmanju potrebnu količinu podataka. Siguran serializer registriraj na zajedničkom loggeru koji koriste redovni pozivi, adapteri i obrada pada. Ne kopiraj proizvoljnu konfiguraciju pogreške, zaglavlja ili zahtjeve. Očisti zadržane poruke, stack, URL-ove i uzroke prema politici podataka. Stvarni izlaz svih ulaza provjeri sintetičkim tajnama. Uzorak jedne razine nije rekurzivan i popis putanja ne čisti proizvoljne stringove.
Exceptions / Tradeoffs (EN)
Central redaction is a fallback, not permission to log full payloads. Retain diagnostic fields only when their content is proven safe or sanitized. Custom adapters and alternate error keys need equivalent coverage. Review paths and serialization when models or transports change.
Iznimke / Tradeoffi (HR)
Središnja redakcija je dodatna zaštita, a ne dozvola za zapis cijelog sadržaja. Dijagnostička polja zadrži samo kada su sigurna ili očišćena. Prilagođeni adapteri i drugi ključevi pogreške trebaju jednaku zaštitu. Provjeri pokrivenost nakon promjene modela ili transporta.