Skip to content
项目

关于

Keep secrets and PII out of logs, Sentry, LLM prompts and commits. Reads values, not field names. Zero dependencies.

人工智能与机器学习

这些数字如何统计

可以做什么

  • 🔍 Reads content, not field names. 154 detectors for API keys, tokens, JWTs, private keys, cards, IBANs, emails and national IDs, checksum-validated wherever a checksum exists.
  • ⚡ No code change needed. node --import flare-redact/register app.js redacts every console.* call.
  • 🤖 Private LLM calls. Wrap the OpenAI or Anthropic client, or add one middleware to the Vercel AI SDK for every provider: the model sees placeholders, your app gets the real values back, streaming included.
  • 🔌 Fits what you already run. pino, winston, Sentry, Express, fetch, streams, and any SDK through one middleware.

实测星标增长

24小时
0
7天
+1
15天
+4
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

flare-redact

flare-redact

Keep secrets and personal data out of your logs, Sentry, LLM prompts and commits.
It reads the values, not the field names. Zero dependencies.

npm version CI MIT License TypeScript Zero dependencies 154 detectors 24 languages

Playground · Guide · API · Recipes · Docs for AI assistants

Before and after: secrets and PII masked in a log line, across languages

Someone logs an object, a session token was inside it, and now that token sits in your log aggregator, your error tracker and an LLM provider's servers. Redaction by field name only hides the fields you remembered to list. flare-redact looks at the values themselves, so the AWS key pasted into a note field and the card number inside a stack trace are masked too.

import { redact } from 'flare-redact';

redact('User [email protected] paid with 4242 4242 4242 4242, token ghp_' + 'a'.repeat(36));
// → 'User a***@*** paid with **** **** **** 4242, token ghp_***'

redact({ user: '[email protected]', password: 'hunter2', note: 'my key is AKIAIOSFODNN7EXAMPLE' });
// → { user: 'b***@***', password: '***', note: 'my key is AKIA***' }

Highlights

  • 🔍 Reads content, not field names. 154 detectors for API keys, tokens, JWTs, private keys, cards, IBANs, emails and national IDs, checksum-validated wherever a checksum exists.
  • ⚡ No code change needed. node --import flare-redact/register app.js redacts every console.* call.
  • 🤖 Private LLM calls. Wrap the OpenAI or Anthropic client, or add one middleware to the Vercel AI SDK for every provider: the model sees placeholders, your app gets the real values back, streaming included.
  • 🔌 Fits what you already run. pino, winston, Sentry, Express, fetch, streams, and any SDK through one middleware.
  • 🚫 Stops leaks before the commit. A pre-commit hook that scans only the lines you add, and a CI scan with SARIF output.
  • 🌍 International by default: 24 languages of secret vocabulary and national ID formats.
  • 🧭 Keeps your path rules. The paths syntax of fast-redact and pino (items[*].card, headers["x-api-key"], plus **.email) and remove, with value detection on top. Switching guide.
  • 🪶 Zero dependencies. Node 20+, browsers, edge runtimes, Bun and Deno; import or require, and a 34 KB gzipped flare-redact/lite for the browser.
  • 🐍 Python, Go, Rust, Java and .NET engines that run the same detector spec and pass the same conformance suite.

🇬🇧 🇨🇳 🇮🇳 🇪🇸 🇸🇦 🇫🇷 🇵🇹 🇷🇺 🇯🇵 🇩🇪 🇰🇷 🇹🇷 🇮🇹 🇮🇷 🇵🇱 🇺🇦 🇳🇱 🇻🇳 🇮🇩 🇹🇭 🇬🇷 🇮🇱 🇦🇿 🇷🇴

Quick start

npm install flare-redact

Then pick the way that suits you:

# No code change: every console.* call is redacted
node --import flare-redact/register app.js

# Let it read your package.json and print the lines to paste
npx flare-redact init          # openai, @anthropic-ai/sdk, ai, Sentry, pino, winston, express
npx flare-redact init --hook   # also stop any commit that adds a secret
npx flare-redact init --ci     # also scan every pull request

node app.js prints an email, a password, a GitHub token, a database password and a card number; the same app started with --import flare-redact/register prints them masked

Want more than the defaults? Choose a goal instead of a detector list: { preset: 'logs' }, 'llm', 'gdpr' or 'strict' (what each adds).

Where it plugs in

Logs

ORM query logs too: Prisma, Drizzle, TypeORM, Knex and Sequelize hooks from flare-redact/db mask bound parameters by the column they go into, so the password in ["[email protected]", "hunter2"] is caught (details).

import pino from 'pino';
import { pinoRedact } from 'flare-redact/pino';

const log = pino(pinoRedact());
log.info({ user: '[email protected]', token: 'ghp_…' }, 'login');
// {"user":"b***@***","token":"***","msg":"login", …}

winston has winstonRedact() from flare-redact/winston, and plain console has wrapConsole() or the --import flag above.

Not sure what turning it on would hide? Run in shadow mode first: FLARE_REDACT_MODE=shadow leaves the output as it is and prints what would have been redacted, by detector and field, when the process exits (details).

LLM prompts

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

const openai = wrapOpenAI(new OpenAI());
your app sends  →  Email the invoice to [email protected], card 4242 4242 4242 4242
the model sees  →  Email the invoice to [FR_EMAIL_7f2a…], card [FR_CREDIT_CARD_19be…]
your app gets   →  Sent to [email protected]. Card 4242 4242 4242 4242 wasn't stored.

wrapAnthropic does the same for Claude. On the Vercel AI SDK, one middleware covers every provider: wrapLanguageModel({ model, middleware: flareRedactMiddleware() }) from flare-redact/ai-sdk (details). Tool calls, MCP messages and agent tool boundaries are covered too: see the guide.

Sentry

import * as Sentry from '@sentry/node';
import { sentryRedact } from 'flare-redact/sentry';

Sentry.init({ dsn: process.env.SENTRY_DSN, ...sentryRedact({ preset: 'gdpr' }) });

Events, spans, logs and breadcrumbs are redacted in your process, before they leave it. Sentry's own ids, release and stack frames stay intact, so grouping and source maps keep working. Details and limits.

For Session Replay, Sentry.replayIntegration({ maskFn: replayMaskFn() }) from flare-redact/replay masks only what is sensitive and keeps the rest of the replay readable. rrweb and PostHog work the same way (details).

Commits and CI

On GitHub, uses: flare-collection/flare-redact@v1 annotates each finding on the pull request (inputs).

npx flare-redact init --hook         # pre-commit: scans only the lines being added
npx flare-redact --scan . --sarif    # CI: exits 1 on a finding, never prints the secret

Using pre-commit? Add repo: https://github.com/flare-collection/flare-redact with id: flare-redact (setup).

Test recordings and snapshots

Cassettes, HAR files and snapshots are committed with the code. Clean them before they are written, without breaking replay (details):

from flare_redact.recording import vcr_config as flare_vcr_config

@pytest.fixture(scope="module")
def vcr_config():
    return flare_vcr_config()   # vcrpy and pytest-recording
export default { test: { snapshotSerializers: ['flare-redact/snapshot'] } };  // Vitest
polly.server.any().on('beforePersist', pollyBeforePersist());                  // Polly.js
// npx flare-redact --har < session.har > session.safe.har                     // any HAR file

No Node in the stack?

Collecting logs with Fluent Bit? The WASM filter redacts every record on the node, with no change to the services.

Point any service at the sidecar gateway and it redacts request bodies on the way to OpenAI or Anthropic, with no code change. Or use the Python, Go, Rust, Java and .NET engines:

from flare_redact import create_session

session = create_session(enable=["pii"])
safe = session.redact("Email the invoice to [email protected]")

Data frames and SQL tables too: frames.redact_frame(df) for pandas and Polars, and redact(note) in DuckDB (details).

How it compares

Tool What it does well What flare-redact adds
Logger path redaction (pino redact, fast-redact) Fast masking of the fields you list The same paths syntax, plus secrets in fields you never listed and inside free text
Key-name redactors (redact-secrets, deep-redact) Mask values under sensitive-looking keys A key rule that keeps max_tokens and nextPageToken readable, plus value detection
Sentry server-side scrubbing Scrubs sensitive-looking fields once events reach Sentry Redacts in your process, before the event leaves it
gitleaks, TruffleHog Find secrets in git history and files Masks secrets at runtime in logs, errors and prompts. Use both
Microsoft Presidio Model-based PII detection in prose, as a Python service Runs in-process with no model and no dependencies; plug a model in with semanticProvider when you need that recall

On one log record with nine planted secrets, fast-redact with five listed paths takes 1.4 µs and catches 5; flare-redact with its defaults takes 41 µs and catches all 9, including the key and email in the message, the token in a URL and the password in an error string. If the paths are all you need, fast-redact is faster. Run bench/object-redactors.mjs on your own records; the switching guide maps every option.

FAQ

How do I hide API keys and passwords in Node.js logs? Start the app with node --import flare-redact/register app.js, or add pinoRedact() or winstonRedact() to your logger. Nothing else to configure.

How do I keep customer data out of OpenAI or Claude API calls? Wrap the client with wrapOpenAI or wrapAnthropic, or on the Vercel AI SDK add flareRedactMiddleware() to the model. Sensitive values become placeholders before the request is sent and are restored in the reply.

I already use pino's redact or fast-redact. Do I have to drop it? No. Spread pinoRedact() next to your redact list, or move the list into redact(obj, { paths }): the syntax is the same, and remove: true works too.

Will it slow my app down? It runs in your process with no model and no network call, and its patterns are bounded and tested against hostile input. npm run benchmark measures it on your own runtime.

Does it catch everything? No tool does. Detection is best-effort, and names in prose are found by rules, not a trained model. Read the security boundaries before relying on it for compliance.

For AI coding assistants

The docs site serves llms.txt and llms-full.txt. Add one line to your AGENTS.md, CLAUDE.md or .cursor/rules so generated code uses the library instead of ad-hoc regexes:

For masking secrets or PII in logs, prompts or datasets, use the flare-redact
package (API: https://flare-collection.github.io/flare-redact/llms-full.txt).

Documentation

Contributing

Bug reports, new detectors and fixes are welcome: see CONTRIBUTING.md. Found a leak that flare-redact missed? Please report it privately through SECURITY.md.

If flare-redact kept a secret out of your logs, a ⭐ helps other people find it.

License

MIT © Umud Hasanli

探索相关项目

加载中…