Skip to main content
Glama
README.md
<p align="center">
  <picture>
    <img src="https://github.com/ItsAxware/DontLeak/raw/main/assets/dontleak-banner.png" alt="Don't Leak" width="100%" />
  </picture>
</p>

<div align="center">

# Your Data. Your Control.

<code>npx -y dont-leak-mcp setup</code>

[Guide](GUIDE.md) · [Before & After](#before-and-after) · [Install](#install) · [10-Agent Hooks](#automatic-interception) · [Detectors](#detectors) · [Deploy](#self-hosted-deployment) · [FAQ](#faq)

[![npm version](https://img.shields.io/npm/v/dont-leak-mcp?style=flat-square&color=cb3837&label=npm)](https://www.npmjs.com/package/dont-leak-mcp)
[![Node.js](https://img.shields.io/badge/Node.js-22.13%2B-339933?style=flat-square&logo=nodedotjs&logoColor=white)](package.json)
[![CI](https://img.shields.io/github/actions/workflow/status/ItsAxware/DontLeak/ci.yml?branch=main&style=flat-square&label=CI)](https://github.com/ItsAxware/DontLeak/actions/workflows/ci.yml)
[![GHCR](https://img.shields.io/badge/GHCR-dontleak-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/ItsAxware/DontLeak/pkgs/container/dontleak)
[![MIT license](https://img.shields.io/badge/license-MIT-f4c430?style=flat-square)](LICENSE)

</div>

---

**Don't Leak** is a local-first privacy filter for AI coding agents. It detects, redacts, masks, or blocks personal data (PII), credentials, custom RE2 regex patterns, and restricted words before prompts or local files reach a cloud model. One shared `@dont-leak/core` engine powers the MCP Server, automatic hooks for 10 AI agents, a local LLM HTTP proxy, a bilingual (`ID` / `EN`) Web Dashboard, and the CLI. Raw sensitive values never leave your machine and are never stored in SQLite audit logs.

## Before and after

One developer prompt containing customer PII and production credentials, before and after passing through Don't Leak:

| **Before: raw input sent to the AI** | **After: filtered locally by Don't Leak** |
|:--|:--|
| <pre lang="text">Debug failed webhook for budi.santoso@klien.co.id&#10;Applicant NIK: 3171014507900003&#10;Phone: +6281298765432&#10;DATABASE_URL=postgresql://app:Sup3rS3cret99@db.internal:5432/prod&#10;WEBHOOK_SECRET=whsec_9fK3mPq8Rw2Lx7Nz4Vb6Cd1Fg5Hj0Kl3</pre> | <pre lang="text">Debug failed webhook for &lt;EMAIL_001&gt;&#10;Applicant NIK: &lt;NIK_001&gt;&#10;Phone: &lt;PHONE_001&gt;&#10;DATABASE_URL=&lt;DB_CREDENTIAL_001&gt;&#10;WEBHOOK_SECRET=&lt;HIGH_ENTROPY_SECRET_001&gt;</pre> |
| Customer identity, database password, and signing secret enter the model context permanently. | Context stays readable and deterministic (`budi...` maps to `<EMAIL_001>` everywhere in the turn), while raw values stay on your machine. |

<details>
<summary><strong>Click here for more before and after examples (Masking, Blocked phrases, Safe .env reader, Reversible Vault)</strong></summary>

<br>

### 1. Partial masking (`action: mask`)

Useful in development presets when you still want visual confirmation of which record was matched:

| **Input** | **Masked output** |
|:--|:--|
| `Charge card 4111 1111 1111 1111 and notify admin@corp.id` | `Charge card 41************11 and notify ad***@corp.id` |

### 2. Hard block on internal codenames (`action: block`)

When any finding resolves to `block` (or when `failMode: closed` catches a validation error), Don't Leak withholds the entire payload before the model is called:

```text
Input:   "Summarize the Q4 acquisition memo for Project Garuda"
Verdict: BLOCKED (status: "blocked", summary: { BLOCKED_WORD: 1 })
Output:  Withheld. Nothing is sent upstream.
```

### 3. Reading `.env` safely via MCP (`read_sanitized_file`)

Agent hooks block direct `cat .env` or `read_file(".env")` calls and instruct the agent to call `read_sanitized_file` instead, so the agent sees variable names without raw credentials:

| **`.env` on disk** | **Returned to AI agent** |
|:--|:--|
| `PORT=3000`<br>`PUBLIC_APP_NAME="Billing Portal"`<br>`SUPABASE_SERVICE_ROLE_KEY=sbp_v1_8f9K2mPqR7xLw4nZt6vBc3dFgH1jKlMn` | `PORT=3000`<br>`PUBLIC_APP_NAME="Billing Portal"`<br>`SUPABASE_SERVICE_ROLE_KEY=<HIGH_ENTROPY_SECRET_001>` |

### 4. Human-only reversible Token Vault (`<LABEL_VXXXXXX>`)

When the encrypted vault is enabled, headless hooks and MCP seal values with an `RSA-OAEP-256` public key. Only a human with the admin password can restore them afterward:

```bash
# AI receives and replies using sealed tokens:
"Send the invoice confirmation to <EMAIL_V4F9A2C>."

# You restore original values locally when needed:
npx -y dont-leak-mcp detokenize ./ai-reply.txt
# -> "Send the invoice confirmation to finance@klien.co.id."
```

</details>

---

## Install

Pick the setup that matches how you run your AI tools. Every route shares the same `config.yaml` and SQLite metadata store. Full step-by-step instructions, including updates and removal, live in [GUIDE.md](GUIDE.md#install-update-and-remove).

| Route | What it does | Best for |
|---|---|---|
| **[Interactive wizard](#the-setup-wizard-recommended)** | Configures detectors, country profiles, policy preset, Dashboard password, and project hooks | First-time setup on any machine |
| **[Automatic agent hooks](#automatic-interception)** | Intercepts prompts and `.env`/secret tool calls automatically on every new session | OpenCode, OMP/Pi, Antigravity, Claude Code, Cursor, Gemini CLI, Windsurf, Cline, Copilot, Codex |
| **[MCP Server](#mcp-server)** | Gives the AI client 9 local sanitization, inspection, and safe-file tools over `stdio` | Claude Desktop, Cursor, Antigravity, OpenCode, Windsurf, Cline |
| **[Local HTTP proxy](#local-llm-http-proxy)** | Sanitizes OpenAI, Anthropic, and Gemini JSON request bodies in transit | Custom scripts, SDKs, or chat apps without hook support |

### The setup wizard (recommended)

Requirements: **Node.js `>= 22.13`**. Run one command and answer the prompts:

```bash
npx -y dont-leak-mcp setup
```

Verify your environment or open the local Web Dashboard (`http://127.0.0.1:3000` by default) anytime:

```bash
npx -y dont-leak-mcp doctor
npx -y dont-leak-mcp dashboard
```

### MCP Server

Add `dont-leak` to your client's `mcpServers` configuration:

```json
{
  "mcpServers": {
    "dont-leak": {
      "command": "npx",
      "args": ["-y", "dont-leak-mcp"]
    }
  }
}
```

By default, MCP runs in read/sanitize-only mode (`5` tools). Append `"--allow-admin"` to `args` only if you want the AI client to add or remove custom regex rules, blocked words, and allowlist entries.

<details>
<summary><strong>Click to see where each MCP client stores this JSON config</strong></summary>

<br>

| Client | Config file location |
|---|---|
| **Claude Desktop** | Windows: `%APPDATA%\Claude\claude_desktop_config.json`<br>macOS: `~/Library/Application Support/Claude/claude_desktop_config.json` |
| **Claude Code** | `~/.claude.json` or project `.mcp.json` |
| **Cursor** | `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global) |
| **Antigravity** | `~/.gemini/antigravity/mcp_config.json` |
| **OpenCode** | `~/.config/opencode/opencode.json` or project `opencode.json` (under `"mcp"`) |
| **Windsurf** | `~/.codeium/windsurf/mcp_config.json` |
| **Cline** | VS Code Cline panel -> **MCP Servers -> Configure MCP Servers** |

</details>

### Automatic interception

Standard MCP servers are passive: an AI model only filters text through MCP when it chooses to call a tool. To filter prompts and block direct `.env` or private-key reads **automatically on every new session**, install lifecycle hooks for your coding agent:

```bash
# Auto-detect agent folders in the current project:
npx -y dont-leak-mcp setup-hooks

# Or install globally across your machine for specific / all 10 agents:
npx -y dont-leak-mcp setup-hooks --target opencode,omp,antigravity,claude,cursor --global
npx -y dont-leak-mcp setup-hooks --target all --global
```

Add `--strict-prompt` if you want prompts containing redactable PII/secrets to be hard-blocked on agents whose hook protocol cannot rewrite prompt text in-place.

<details>
<summary><strong>OpenCode v2 (in-place prompt rewrite + tool guard)</strong></summary>

```bash
npx -y dont-leak-mcp setup-hooks --target opencode --global
```

Writes `~/.opencode/plugins/dont-leak.js` (or `.opencode/plugins/dont-leak.js` for a single repo) using OpenCode v2's `{ id, setup(ctx) }` plugin contract. Hooks `ctx.session.hook("prompt")` to rewrite PII/secrets into placeholders before persistence and `ctx.tool.hook("execute.before")` to block `.env` or secret shell reads. If OpenCode is already open, run `opencode reload` or `opencode service restart`.

</details>

<details>
<summary><strong>OMP / Oh My Pi & Pi coding agent (in-place prompt transform + tool guard)</strong></summary>

```bash
npx -y dont-leak-mcp setup-hooks --target omp --global
# Alias also supported: --target pi
```

Writes native `ExtensionAPI` module `dont-leak.js` (`pi.on("input")` prompt transform + error toast on blocked phrases, and `pi.on("tool_call")` guard) alongside `settings.json` command hooks.

</details>

<details>
<summary><strong>Antigravity, Claude Code, Cursor, Gemini CLI, Windsurf, Cline, Copilot, Codex</strong></summary>

<br>

Install one or several by name (`--global` for machine-wide, omit `--global` for current workspace):

```bash
npx -y dont-leak-mcp setup-hooks --target antigravity,claude,cursor,gemini,windsurf,cline,copilot,codex
```

| Agent | Project path | Global path | Interception behavior |
|---|---|---|---|
| **Antigravity** | `.agents/hooks.json` | `~/.gemini/config/hooks.json` | `PreInvocation` gate + `PreToolUse` (`read_file`, `run_command`, `grep_search`) |
| **Claude Code** | `.claude/settings.json` | `~/.claude/settings.json` | `UserPromptSubmit` + `PreToolUse` (`Read`, `Bash`, `Grep`) |
| **Cursor** | `.cursor/hooks.json` | `~/.cursor/hooks.json` | `beforeSubmitPrompt` + `beforeReadFile` + `beforeShellExecution` |
| **Gemini CLI** | `.gemini/settings.json` | `~/.gemini/settings.json` | `BeforeAgent` + `BeforeTool` (`decision: "deny"`) |
| **Windsurf** | `.windsurf/hooks.json` | `~/.codeium/windsurf/hooks.json` | `pre_user_prompt` + `pre_read_code` + `pre_run_command` (exit code `2`) |
| **Cline** | `.clinerules/hooks/*` | `~/Documents/Cline/Rules/Hooks/*` | POSIX `sh` `UserPromptSubmit` & `PreToolUse` (`cancel: true`) |
| **GitHub Copilot** | `.github/hooks/dont-leak.json` | `~/.copilot/hooks/dont-leak.json` | `userPromptSubmitted` + `preToolUse` (VS Code & Copilot CLI) |
| **OpenAI Codex** | `.codex/hooks.json` | `~/.codex/hooks.json` | `UserPromptSubmit` + `PreToolUse` (exit code `2` block) |

</details>

### Local LLM HTTP proxy

For SDKs, scripts, or desktop chat clients without hook support, route requests through the local sanitizing reverse proxy:

```bash
npx -y dont-leak-mcp proxy --port 8787
```

Point your client base URLs to the local proxy (`127.0.0.1` only):

```bash
export OPENAI_BASE_URL="http://127.0.0.1:8787/openai/v1"
export ANTHROPIC_BASE_URL="http://127.0.0.1:8787/anthropic"
# Gemini route prefix: http://127.0.0.1:8787/gemini
```

Multi-turn `messages[]` within one request share a consistent token table, and payloads matching a `block` rule stop locally with HTTP `422` before reaching the provider.

---

## Detectors

| Module | What it catches | Validation & safety |
|---|---|---|
| **PII (`pii`)** | Email, phone (`+62`/`08xx`, US NANP, E.164), Indonesian NIK & NPWP, US SSN, EU IBAN, payment cards, IPv4 & IPv6 | Checksum and structure checks (Kemendagri province/date for NIK, Luhn for cards, ISO 13616 MOD-97 for IBAN) |
| **Secrets (`secret`)** | AWS, GitHub, GitLab, Slack, Stripe, OpenAI/Anthropic, Google API keys, JWTs, PEM/SSH private keys, Bearer tokens, DB URLs, and high-entropy credentials | Contextual Shannon entropy skips UUIDs, SHA/Git hashes, file paths, and `PUBLIC_KEY` names |
| **Custom Regex (`custom_regex`)** | User-defined patterns such as `EMP-[0-9]{6}` or internal ticket IDs, with optional custom replacement text | Compiled through `re2-wasm` (linear-time `O(n)`, immune to catastrophic ReDoS backtracking) |
| **Blocked Words (`blocked_words`)** | Confidential codenames, client names, or restricted phrases (`exact`, `whole_word`, or `phrase` matching) | NFKC Unicode normalization; rules with `action: block` always override allowlist exclusions |

Country profiles (`id`, `us`, `eu`, `intl`) can be toggled independently in `config.yaml` or the Web Dashboard.

---

## MCP tools and Web Dashboard

The local Web Dashboard (`npx -y dont-leak-mcp dashboard`) binds to `127.0.0.1`, supports **Bahasa Indonesia (`ID`)** and **English (`EN`)**, and protects state-changing endpoints with `scrypt` password hashing, `HttpOnly` session cookies, and CSRF tokens.

<details>
<summary><strong>Click to view all 9 MCP tools and access levels</strong></summary>

<br>

| MCP Tool | Access | Purpose |
|---|---|---|
| `sanitize_text` | Default | Redacts, masks, or blocks sensitive spans according to active policy |
| `inspect_text` | Default | Returns structured finding metadata (labels, offsets, severity) without modifying input |
| `read_sanitized_file` | Default | Reads `.env`, logs, or configs locally and returns only sanitized text to the agent |
| `test_regex` | Default | Tests a custom RE2 pattern against sample text safely |
| `get_protection_status` | Default | Reports active policy, enabled detectors, country profiles, and scan counts |
| `add_custom_rule` | `--allow-admin` | Adds or updates a validated RE2 custom rule (creates automatic config backup) |
| `remove_custom_rule` | `--allow-admin` | Removes a custom regex rule by ID |
| `add_blocked_word` | `--allow-admin` | Adds a blocked word or phrase |
| `remove_blocked_word` | `--allow-admin` | Removes a blocked word or phrase |

</details>

### Encrypted Token Vault (optional)

Need to restore redacted values in an AI response? Initialize the local hybrid `RSA-OAEP-256` + `AES-256-GCM` vault:

```bash
npx -y dont-leak-mcp vault init
npx -y dont-leak-mcp detokenize ./ai-output.md
```

MCP, hooks, and the HTTP proxy only ever read the public key to seal `<LABEL_VXXXXXX>` tokens. The private key stays wrapped with your `scrypt` admin password and is never exposed as an MCP tool.

---

## Update

When a new release ships updated detectors or agent plugin schemas, one command upgrades your global install (if present), cleans stale `_npx` cache slots so hooks do not run an older cached version, regenerates every installed hook/plugin across your project and home folder, and reloads OpenCode's background service:

```bash
npx -y dont-leak-mcp@latest update
```

To inspect your current version and list detected hooks without changing any files:

```bash
npx -y dont-leak-mcp update --check
```

---

## Self-hosted deployment

<details>
<summary><strong>Docker Compose & GHCR container</strong></summary>

<br>

```bash
git clone https://github.com/ItsAxware/DontLeak.git
cd DontLeak
docker compose up -d --build
```

Prebuilt image: `ghcr.io/itsaxware/dontleak:latest`.
- Web Dashboard listens on `http://127.0.0.1:3000`.
- Persistent `config.yaml`, snapshots, and SQLite WAL files live in the `privacy-data` volume (`/data`).
- Connect a host MCP client to the running container:
  ```json
  {
    "mcpServers": {
      "dont-leak": {
        "command": "docker",
        "args": ["exec", "-i", "dont-leak", "node", "/app/apps/mcp-server/dist/server.js"]
      }
    }
  }
  ```

</details>

<details>
<summary><strong>Linux <code>systemd</code> service</strong></summary>

<br>

```bash
git clone https://github.com/ItsAxware/DontLeak.git
cd DontLeak
pnpm install --frozen-lockfile
pnpm -r build
sudo ./deployment/scripts/install.sh --from-dir .
```

- Runs under a dedicated `dont-leak` system user with `NoNewPrivileges=true`, `PrivateTmp=true`, `ProtectSystem=strict`, and `ProtectHome=true`.
- Stores config in `/etc/dont-leak/config.yaml` and SQLite/backups in `/var/lib/dont-leak`.
- Upgrade with automatic snapshot: `sudo ./deployment/scripts/update.sh --from-dir .`
- Uninstall while keeping config and audit data: `sudo ./deployment/scripts/uninstall.sh`

</details>

<details>
<summary><strong><code>config.yaml</code> reference</strong></summary>

<br>

```yaml
policy:
  name: default
  failMode: closed
  maxInputBytes: 1000000
  entropyDetection: true
  reversibleTokenization: false
  countryProfiles: [id, us, eu, intl]
  enabled:
    pii: true
    secret: true
    custom_regex: true
    blocked_words: true
  actions:
    pii: redact
    secret: redact
    custom_regex: redact
    blocked_words: block

rules:
  - id: employee-id
    label: EMPLOYEE_ID
    pattern: \bEMP-[0-9]{6}\b
    case_insensitive: false
    severity: medium
    action: redact
    replacement: "[EMPLOYEE_ID]"
    enabled: true

blocked_words:
  - value: project phoenix
    group: internal_project
    match: phrase
    action: block

allowlist:
  - value: "@example.com"
    kind: literal
    description: Synthetic test domain
```

Allowlist entries (`literal`, `@domain` suffix, or RE2 `regex`) skip `warn`, `mask`, and `redact` findings. Rules or words with `action: block` always override the allowlist.

</details>

---

## Measured performance

Benchmarked on Node.js `>= 22.13` (x64) across 46 structured positive and hard-negative lookalike cases (including contextual Shannon entropy) plus a `1.00 MB` mixed sanitization and output-validation payload:

| Metric | Measured value |
|---|---|
| Precision | `1.0000` (`FP = 0`) |
| Recall | `1.0000` (`FN = 0`) |
| False-positive rate (lookalike negatives) | `0.0000` |
| `1 MB` sanitize + output validation | `~312 ms` (`~3.21 MB/s`) |
| Heap delta during `1 MB` pass | `~6.88 MB` |

---

## FAQ

**Why did my agent still see a secret when I only configured MCP?**
MCP tools are passive: the model only calls `sanitize_text` when it decides to. Install [automatic hooks](#automatic-interception) (`npx -y dont-leak-mcp setup-hooks`) or use the [local HTTP proxy](#local-llm-http-proxy) so prompts and `.env` reads are intercepted before the model runs.

**How is this different from an agent's built-in secret redaction?**
Built-in agent filters usually only mask a few known API key prefixes in terminal output and vary across vendors. Don't Leak gives you one consistent policy across all 10 agents, adds country-specific PII checksums (NIK, NPWP, SSN, IBAN, Luhn cards), linear-time RE2 custom rules, company blocked words, a human-only reversible vault, and local metadata-only audit stats.

**Can an AI agent decrypt `<LABEL_VXXXXXX>` vault tokens?**
No. No MCP tool accepts a detokenization request, and the private key is encrypted at rest with your `scrypt` admin password. Only you can run `dont-leak-mcp detokenize` or enter your admin password in the Web Dashboard Vault tab.

**What does Don't Leak intentionally not claim to catch?**
Unstructured free-text person names and street addresses have no deterministic format; Don't Leak does not claim regex-only coverage for them to avoid a false sense of security. For specific client or project names, add them to `blocked_words` or `rules`.

---

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=ItsAxware/DontLeak&type=Date)](https://star-history.com/#ItsAxware/DontLeak&Date)

## Contributors

Thanks to everyone reporting detector edge cases, agent hook changes, and fixes. See the [contributors graph](https://github.com/ItsAxware/DontLeak/graphs/contributors) or open an [issue](https://github.com/ItsAxware/DontLeak/issues) if a pattern slipped through or flagged a false positive. Full setup, update, and troubleshooting documentation lives in [GUIDE.md](GUIDE.md).

<hr>

<p align="center"><em>"AI agents work best with context.<br>
Your raw credentials, customer IDs, and internal codenames do not belong in it."</em></p>

<hr>

## Disclaimer

Get Don't Leak only from [ItsAxware/DontLeak](https://github.com/ItsAxware/DontLeak), the [dont-leak-mcp npm package](https://www.npmjs.com/package/dont-leak-mcp), or `ghcr.io/itsaxware/dontleak`. For LAN or remote Dashboard deployments, place Don't Leak behind a TLS reverse proxy and set `DASHBOARD_ALLOWED_HOSTS`.

## License

MIT: [LICENSE](LICENSE)