Skip to main content

ADR 013: PII Log Sanitization

Status

Implemented

Context

The codebase has ~590 log statements across 42 files. Audit revealed HIGH-RISK PII exposure in MQTT credentials, password commands, and API endpoints. Only one file (tokenCache.js) had any sanitization. File logging is disabled by default, but when enabled, sensitive data could leak.

Decision

Use custom regex-based sanitization utility (app/utils/logSanitizer.js) instead of third-party libraries.

Pattern replacement order (specific before general):

  1. MQTT URLs → preserve protocol, redact credentials
  2. Bearer tokens → Bearer [TOKEN]
  3. Passwords, auth headers, API keys, tokens, secrets → [REDACTED]
  4. Certificate fingerprints → preserve label, redact value
  5. Emails → [EMAIL]
  6. UUIDs → keep first 8 chars for correlation
  7. IP addresses → [IP]
  8. URL query params → ?[PARAMS]
  9. User paths → preserve structure, redact username

Consequences

Positive

  • Zero dependencies, fast execution
  • Full control over patterns
  • UUIDs remain correlatable for debugging

Negative

  • Requires pattern maintenance
  • May miss edge cases (regex-only, no NER)

Implementation Phases

  1. Done: Sanitizer utility + tests (app/utils/logSanitizer.js)
  2. Done: Logger integration via electron-log hooks (app/config/logger.js)
  3. Apply to high-risk files - Not needed: Hook automatically sanitizes all logs
  4. Done: Log verbosity reduction (21% debug log reduction)

Alternatives Considered

OptionRejected Because
Microsoft PresidioRequires Docker, network latency
PII-PALADIN90MB bundle size
@redactpii/nodeAdditional dependency, less control
Pino with redactionWould require replacing electron-log
  • Implementation: app/utils/logSanitizer.js
  • Logger Hook: app/config/logger.js