Skip to main content
Glama
redact-bridge

redact-bridge

by pentestllm
README.md
# redact-bridge

A small local proxy and MCP server for penetration testers. It runs on your machine, replaces client
identifiers in an outgoing prompt with stable placeholders before the request leaves the machine, and puts the
real values back into the model's answer locally. The mapping between placeholders and real values stays on your
machine: in memory, or in an encrypted file you choose.

```
you / your agent  ──►  redact-bridge (127.0.0.1)  ──►  model API
  "scan dc01.corp.client.test"     "scan [[HOST_1]]"
                    ◄──  "dc01.corp.client.test runs SMB without signing"  ◄──  "[[HOST_1]] runs SMB without signing"
```

Works with any OpenAI-compatible or Anthropic-compatible endpoint (Chat Completions, Responses, Messages; streamed
or not). [PentestLLM](https://pentestllm.ai) is the built-in preset. No dependencies beyond Node.js 20 or newer.

## What it replaces

| Placeholder | What | How it is found |
|---|---|---|
| `[[IPV4_n]]` | IPv4 addresses | every valid dotted quad, except `0.0.0.0`, `127.0.0.1`, `255.255.255.255` |
| `[[IPV6_n]]` | IPv6 addresses | every valid address with two or more groups, except `::` and `::1` |
| `[[HOST_n]]` | hostnames and domains in your scope | each domain you pass with `--scope` and all its subdomains, plus any name under `.local`, `.internal`, `.corp`, `.lan`, `.intranet`, `.localdomain`, `.home.arpa`. In a URL only the host is replaced, so the path stays readable |
| `[[EMAIL_n]]` | email addresses | every address, any domain |
| `[[COOKIE_n]]` | cookie values | `Cookie:` and `Set-Cookie:` headers (names and attributes kept) |
| `[[SECRET_n]]` | tokens, keys, passwords | `Authorization` header credentials (Bearer, Basic, Digest ...), other `Bearer` tokens of 16 or more characters, URL `user:password@`, JWTs, keys with a known prefix (`sk-...`, Stripe `sk_live_`/`rk_`, AWS `AKIA`/`ASIA`, GitHub `ghp_`/`github_pat_`, GitLab `glpat-`, Slack `xox?-` and webhooks, Google `AIza`, npm), and the value of any `name=value`, `name: value` or `"name": "value"` whose name contains password, passwd, pwd, secret, token, api_key / apikey, access_key, private_key, session, csrf, xsrf or credential; in a JSON body, any field with such a name |
| `[[KEY_n]]` | private keys | `-----BEGIN ... PRIVATE KEY-----` blocks |
| `[[HASH_n]]` | password hashes | `LM:NT` pairs (secretsdump format), bcrypt, sha256-crypt and sha512-crypt |
| `[[TERM_n]]` | your words | each `--term` (client name, project code name), case-insensitive |
| `[[NAME_n]]` | your patterns | each regex in the config file, under the name you give it |

The same value gets the same placeholder for the whole session (and across sessions with `--map-file`), so the
model can reason about "[[HOST_3]] talks to [[IPV4_2]]" consistently.

## What it does not catch

It is pattern-based. It recognises things by shape or by the scope you give it. It cannot recognise:

- **Secrets with no known shape and no telling label**: a random password written in a sentence, a hex key on its
  own, an internal ticket number. Add a `--term` or a pattern for anything like that.
- **Hostnames outside your scope list** on a public TLD (`client-portal.com` unless you scope it).
- **Usernames, real names, MAC addresses, phone numbers, street addresses, account numbers**, unless you add a
  term or pattern.
- **Anything inside images, PDFs or other files** attached to the request (base64 data is passed through
  unread), and **encoded data** (base64, URL-encoded or hex-encoded copies of a value are not decoded).
- **What the model infers.** A placeholder hides the value, not the context around it.

Restoration gives back the first spelling seen: hosts, emails and terms are matched case-insensitively, so
`ACME` and `Acme` share one placeholder and both come back as the first one seen.

Over-redaction is the safer failure, so some harmless text is replaced too (a version string shaped like an IPv4
address, `name=value` pairs whose name contains "token"). Run `redact` or `--dry-run` on real material before you
rely on it.

## Install

```sh
npm install -g github:pentestllm/redact-bridge
# or run from a clone: node bin/redact-bridge.js ...
```

## See what would be sent first

```sh
redact-bridge redact findings.txt --scope client.example,corp.client.test --term "Contoso Bank" --show-map
```

prints the redacted text to stdout and the placeholder table to stderr. Nothing is sent anywhere.
`redact-bridge proxy --dry-run` does the same for live requests: it prints each redacted request body and answers
the client with a 503 instead of forwarding it.

## Proxy

```sh
redact-bridge proxy --preset pentestllm --scope client.example,corp.client.test --term "Contoso Bank"
# redact-bridge on http://127.0.0.1:8787 -> https://api.pentestllm.ai
```

Point your client at it:

- OpenAI-compatible clients (OpenAI SDKs, OpenCode, Cline, Continue, curl): base URL `http://127.0.0.1:8787/v1`
- Anthropic-compatible clients (Claude Code, Anthropic SDKs): `ANTHROPIC_BASE_URL=http://127.0.0.1:8787`

Your API key goes through unchanged. `proxy` and `mcp` send nothing until you name the destination: `--preset
pentestllm`, or `--upstream https://api.example.com` (the origin, without `/v1`) for any other endpoint.

JSON bodies are redacted field by field (tool-call arguments as JSON), plain-text bodies as text, and query values
in the URL. A body the bridge cannot read (multipart uploads, binary) is refused with a 415 and not sent. Browser
cookies sent to the bridge are not forwarded, and redirects from the upstream are refused so the key never goes to
another origin.

Streaming answers are restored as they arrive. A placeholder split across chunks (`[[HO` then `ST_1]]`) is held
back until it is complete; tool-call arguments are restored as valid JSON.

## MCP server

```json
{
  "mcpServers": {
    "redact-bridge": {
      "command": "npx",
      "args": ["-y", "github:pentestllm/redact-bridge", "mcp", "--preset", "pentestllm", "--scope", "client.example"],
      "env": { "REDACT_BRIDGE_API_KEY": "<your key for the upstream, only needed for ask>" }
    }
  }
}
```

In Claude Desktop you can instead open `redact-bridge-<version>.mcpb` from the [releases](https://github.com/pentestllm/redact-bridge/releases) and fill in the scope there.

Tools: `redact` (text in, placeholders out), `restore` (placeholders in, real values out) and `ask` (redact a prompt,
send it to the upstream's `/v1/chat/completions` with the model you name, restore the answer). Use it when a local
agent should consult a remote model about client material.

## Keeping the mapping

By default the mapping lives in memory and is gone when the process stops. To keep it across runs (to restore a
report written yesterday, or to share placeholders between `proxy` and `restore`):

```sh
export REDACT_BRIDGE_PASSPHRASE='a long passphrase'
redact-bridge proxy --map-file ~/engagements/contoso.map --scope client.example
redact-bridge restore model-answer.md --map-file ~/engagements/contoso.map
```

Use one bridge process and one map file per engagement: every placeholder issued in a process can be restored by
that process, and two processes writing the same map file will overwrite each other.

The file is AES-256-GCM encrypted with a key derived by scrypt from the passphrase, written with mode 600. Without
the passphrase it cannot be read.

## Config file

```json
{
  "scope": ["client.example", "corp.client.test"],
  "terms": ["Contoso Bank", "Project Bluebird"],
  "patterns": [{ "name": "ticket", "regex": "CASE-\\d{5}" }],
  "internalTlds": true
}
```

`redact-bridge proxy --config contoso.json`. Terms and patterns run first.

## Defaults

- Listens on `127.0.0.1` only.
- Logs nothing. `--verbose` prints the method, path and placeholder counts per request, never a value.
- The mapping is never sent upstream, never written unencrypted, and never printed unless you ask with
  `--show-map`.

## Tests

`npm test` runs a corpus of fake findings (a Burp request and response, nmap output, a Python stack trace with
credentials and an NTLM hash) through the redactor, a fake upstream behind the proxy (Chat Completions, Messages,
streamed and not) and the MCP server, and checks that every seeded identifier is gone from what the upstream
receives and back in what the client gets, with placeholders split at every chunk position.

## License

MIT