DEV Community

Umud Hasanli
Umud Hasanli

Posted on

Your logger redaction only hides the fields you remembered

Every leaked secret I have seen started the same way. Someone wrote logger.info({ user }), the code looked harmless, and user carried a session token. Now that token lives in the log aggregator, the error tracker and a few vendors' systems, for as long as they keep logs.

Most loggers have an answer for this. pino has a redact option, and you can write a winston format. Both work the same way: you list the paths that are sensitive, and those fields are masked.

The trouble is the list. It only covers what you remembered. The leak is always somewhere else:

  • a free-text note field where a customer pasted an API key
  • a nested payload from a third-party SDK you never looked inside
  • an error message that includes the request URL, with a token in the query string

Read the values, not the names

I built flare-redact to check the content itself. It knows what an AWS key, a GitHub token, a JWT, a card number or an IBAN looks like, and checks a checksum wherever one exists, so the card number 4242 4242 4242 4242 is masked but 4242 4242 4242 4243, which fails the card checksum, is left alone.

import { redact } from 'flare-redact';

redact({ user: 'bob@corp.com', password: 'hunter2', note: 'my key is AKIAIOSFODNN7EXAMPLE' });
// { user: 'b***@***', password: '***', note: 'my key is AKIA***' }
Enter fullscreen mode Exit fullscreen mode

There is nothing to configure and no list to maintain. The shape you pass in is the shape you get back.

Turn it on without touching the code

node --import flare-redact/register app.js
Enter fullscreen mode Exit fullscreen mode

Every console.log, warn and error is redacted before it is written. You can add it to a Dockerfile or a deploy setting without opening the code. For pino and winston there are one-line integrations.

LLM prompts are the new log file

The same leak now happens in prompts. A support bot sends the customer's message to a model, and the message contains an email and a card number. Wrap the client once:

import OpenAI from 'openai';
import { wrapOpenAI } from 'flare-redact/llm';

const openai = wrapOpenAI(new OpenAI());
Enter fullscreen mode Exit fullscreen mode

The model sees [FR_EMAIL_7f2a…] instead of the address, and your app gets the real value back in the reply, streaming included.

Sentry and commits

sentryRedact() redacts events, spans and breadcrumbs before they leave your process, while keeping Sentry's own ids and stack frames so grouping still works. And npx flare-redact init --hook adds a pre-commit hook that scans only the lines a commit adds, so it does not block you for old code.

What it does not do

It is honest pattern matching, not a model. It will miss a person's name with no context around it, and a clean scan is not proof that data has no PII. If you need model-level recall for names in prose, you can plug a local model in. It also does not replace gitleaks or TruffleHog, which scan your git history; flare-redact covers runtime data. They work well together.

Try it

npm install flare-redact
npx flare-redact init
Enter fullscreen mode Exit fullscreen mode

There is a playground that runs entirely in the browser. If it misses something or masks something it should not, please open an issue. Those reports are the most useful thing for a library like this.

Top comments (0)