leakshield 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +141 -572
- package/README.zh-TW.md +140 -545
- package/dist/adapters/opencode/doctor.js +10 -2
- package/dist/adapters/opencode/plugin.js +37 -8
- package/dist/adapters/opencode/transparent.d.ts +5 -1
- package/dist/adapters/opencode/transparent.js +8 -3
- package/dist/adapters/opencode/v2.d.ts +5 -2
- package/dist/adapters/opencode/v2.js +10 -5
- package/dist/config/loader.js +8 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/session-guard.d.ts +1 -0
- package/dist/core/session-guard.js +1 -0
- package/dist/core/wire.d.ts +6 -1
- package/dist/core/wire.js +100 -13
- package/dist/decision/redaction.js +3 -0
- package/dist/guard-options.js +4 -5
- package/dist/rules/builtin.js +75 -2
- package/dist/types.d.ts +1 -1
- package/dist/types.js +3 -0
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -9,45 +9,55 @@
|
|
|
9
9
|
|
|
10
10
|
**A gatekeeper that scans for sensitive content before you feed code, documents, or data to AI services.**
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
> **Design principles:** Invisible by default. Observable on demand. Fail-closed at the model boundary.
|
|
13
|
+
> New adapter work is built and accepted against these ([ADR 0008](docs/adr/0008-transparent-protection-and-native-ux.md)). They are a contract for adapter work, not a claim that every host meets them today; see [host capabilities](docs/host-capabilities.md) for current status.
|
|
14
|
+
|
|
15
|
+
Five entry points share one scanner and decision model:
|
|
16
|
+
- **OpenCode plugin**: The enforced ingress gate for OpenCode v2, at its content hooks and, in transparent mode, the final provider body.
|
|
17
|
+
- **pi extension**: An in-process pi extension that guards the agent's provider requests through the shared wire core and restores local tool arguments.
|
|
18
|
+
- **Claude Code proxy** (experimental): A local proxy behind `ANTHROPIC_BASE_URL` that masks Anthropic Messages requests and restores assistant text.
|
|
15
19
|
- **CLI**: Manual or CI scanning of text, files, and directories; supports redaction.
|
|
16
20
|
- **Web UI**: Local browser interface and REST endpoint for manual scanning.
|
|
17
21
|
|
|
18
|
-
MCP server mode has been removed. It depended on the model voluntarily calling a scan tool after it had already received the relevant context, so it cannot provide
|
|
22
|
+
MCP server mode has been removed. It depended on the model voluntarily calling a scan tool after it had already received the relevant context, so it cannot provide a model-boundary guarantee.
|
|
19
23
|
|
|
20
|
-
|
|
|
24
|
+
| Entry point | Start it with | Use it for |
|
|
21
25
|
|------|---------------|------------|
|
|
22
|
-
| OpenCode
|
|
23
|
-
| pi
|
|
26
|
+
| OpenCode plugin | Add the `leakshield` package or the `dist` directory to `opencode.json` (OpenCode v2; [guide](docs/opencode.md)) | Automatic, fail-closed protection for OpenCode model inputs and tool outputs |
|
|
27
|
+
| pi extension | `pi install npm:leakshield` (0.4.0+, or `pi install /absolute/path/to/built/leakshield` for a local build; [guide](docs/pi.md)) | Masked pi provider requests and restored read/write/edit/bash arguments |
|
|
28
|
+
| Claude Code proxy | `leakshield --claude-code-proxy`, then `ANTHROPIC_BASE_URL=http://127.0.0.1:8787` ([guide](docs/claude-code.md)) | Masked Claude Code model requests and restored assistant text; tool arguments are not restored yet |
|
|
24
29
|
| CLI | `npm run scan -- --file ./path` (or `leakshield --file ./path` after a global install / `npm link`) | Explicit local or CI scans; it never sends content to a model |
|
|
25
30
|
| Web UI | `npm run web` | Manual browser scans at `http://localhost:3000` |
|
|
26
31
|
|
|
27
32
|
## Project status
|
|
28
33
|
|
|
29
|
-
**Experimental, `0.x`.** Published to npm as `leakshield`: run `npx leakshield --help` to see the commands, or build locally (`npm ci && npm run build`) and point
|
|
34
|
+
**Experimental, `0.x`.** Published to npm as `leakshield`: run `npx leakshield --help` to see the commands, or build locally (`npm ci && npm run build`) and point a host at the build. Run without arguments in a terminal, the CLI prints usage. When stdin is not a terminal (a pipe, CI or a script), it reads stdin until EOF, so close or redirect stdin there.
|
|
35
|
+
|
|
36
|
+
None of the hosts is a guarantee that nothing sensitive reaches a model. `leakshield --doctor <host>` prints each host's declared coverage and residuals; the [host capability matrix](docs/host-capabilities.md) summarizes them.
|
|
30
37
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
38
|
+
- **OpenCode**: transparent mode verified on OpenCode v2.0.28 with local loopback providers, and once against a real OpenAI model. The 0.3.0 tool restoration was rechecked on OpenCode v2.2.5 with a loopback provider, the OpenChamber render tool and `rtk` ([record](docs/evidence/2026-11-06-opencode-2.2.5-tool-restoration.md)). The hook-first setup is reported as `PARTIAL` by `--doctor`, and content added after the plugin's hooks or sent by permitted tools (curl, remote MCP) is outside its coverage. See [OpenCode plugin](docs/opencode.md).
|
|
39
|
+
- **pi**: an in-process extension wraps the agent's `fetch`, masks the three wire APIs it supports, and restores read/write/edit/bash arguments locally. Verified against pi 1.6.0 with a recording stub upstream ([record](docs/evidence/2026-11-23-pi-extension.md)); providers whose transport bypasses fetch (Codex WebSocket, Bedrock) are refused, and OAuth-only accounts are not supported. See [pi adapter](docs/pi.md).
|
|
40
|
+
- **Claude Code** (experimental): a local proxy (`leakshield --claude-code-proxy`, then `ANTHROPIC_BASE_URL`), verified with Claude Code 2.1.321 against a loopback stub upstream ([record](docs/evidence/2026-11-21-claude-code-proxy.md)). It masks model requests and restores assistant text, but does not restore placeholders at tool execution yet. See [Claude Code](docs/claude-code.md).
|
|
34
41
|
- Not yet verified: OS-keychain custody on Windows and Linux (macOS verified 2026-10-20), a real Anthropic provider, long histories on other providers, long-running use ([#26](https://github.com/jwcrystal/leakshield/issues/26)).
|
|
35
42
|
- Defaults may still change during `0.x`; see the [changelog](CHANGELOG.md).
|
|
43
|
+
- Planned work: [Roadmap](docs/ROADMAP.md) (Traditional Chinese; priorities, candidates and research, separate from current support claims).
|
|
36
44
|
- Verification records: [docs/evidence](docs/evidence/README.md). Report vulnerabilities privately: [SECURITY.md](SECURITY.md). License: [Apache-2.0](LICENSE).
|
|
37
45
|
|
|
38
46
|
---
|
|
39
47
|
|
|
40
48
|
## Quickstart
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
Install once (Node.js 20 or later; the pi extension needs Node.js 22.19 or later):
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install -g leakshield
|
|
54
|
+
```
|
|
43
55
|
|
|
44
|
-
|
|
56
|
+
Then connect the host you use and check it with `leakshield --doctor <host>`. Exit code 0 means `PROTECTED` or `PARTIAL`. The doctor checks the install outside the host and cannot see inside a live session, so finish with a synthetic-value test before using real data. Never use a real credential for that test.
|
|
45
57
|
|
|
46
|
-
|
|
47
|
-
npm install -g leakshield
|
|
48
|
-
```
|
|
58
|
+
### OpenCode v2
|
|
49
59
|
|
|
50
|
-
|
|
60
|
+
1. Register the plugin in your project's `opencode.json`. With no options, `mode` defaults to `transparent`:
|
|
51
61
|
|
|
52
62
|
```jsonc
|
|
53
63
|
{
|
|
@@ -56,30 +66,74 @@ Needs OpenCode v2 and Node.js 20 or later.
|
|
|
56
66
|
}
|
|
57
67
|
```
|
|
58
68
|
|
|
59
|
-
|
|
69
|
+
2. Check the install; see [what `PARTIAL` means](docs/opencode.md#what-partial-means):
|
|
60
70
|
|
|
61
71
|
```bash
|
|
62
|
-
leakshield --doctor
|
|
72
|
+
leakshield --doctor opencode
|
|
63
73
|
```
|
|
64
74
|
|
|
65
|
-
|
|
75
|
+
3. Run the smoke test. It uses a temporary directory and a synthetic value:
|
|
66
76
|
|
|
67
77
|
```bash
|
|
68
78
|
SMOKE_DIR="$(mktemp -d)"
|
|
69
|
-
cat > "$SMOKE_DIR/opencode.json" <<'
|
|
79
|
+
cat > "$SMOKE_DIR/opencode.json" <<'JSON'
|
|
70
80
|
{
|
|
71
81
|
"$schema": "https://opencode.ai/config.json",
|
|
72
82
|
"plugins": [{ "package": "leakshield", "options": { "mode": "block" } }]
|
|
73
83
|
}
|
|
74
|
-
|
|
84
|
+
JSON
|
|
75
85
|
(cd "$SMOKE_DIR" && opencode run --standalone \
|
|
76
86
|
"Smoke test only. Do not reveal or use this token: sk-AAAAAAAAAAAAAAAAAAAA")
|
|
77
87
|
rm -rf "$SMOKE_DIR"
|
|
78
88
|
```
|
|
79
89
|
|
|
80
|
-
The model-facing message must contain the LeakShield block notice and must not contain the synthetic token.
|
|
90
|
+
The model-facing message must contain the LeakShield block notice and must not contain the synthetic token.
|
|
91
|
+
|
|
92
|
+
### pi
|
|
93
|
+
|
|
94
|
+
1. Install the pi package (it registers the extension in `settings.packages`):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pi install npm:leakshield
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
2. Check the install. A package install reports `PARTIAL` because pi's load order cannot be verified; for `PROTECTED`, register the extension first in `settings.extensions` instead ([explicit path](docs/pi.md#explicit-extension-path)):
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
leakshield --doctor pi
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
3. Send pi a synthetic value such as `sk-AAAAAAAAAAAAAAAAAAAA` and confirm the provider receives a placeholder. See [pi adapter](docs/pi.md) for the provider APIs it supports.
|
|
107
|
+
|
|
108
|
+
### Claude Code (experimental)
|
|
109
|
+
|
|
110
|
+
1. Start the proxy and leave it running:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
leakshield --claude-code-proxy # listens on 127.0.0.1:8787
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
2. Point Claude Code at it, in the shell or in the `env` block of `~/.claude/settings.json`:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
export ANTHROPIC_BASE_URL=http://127.0.0.1:8787
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
3. Check the wiring:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
leakshield --doctor claude-code
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Tool-call arguments are not restored yet, and traffic that bypasses the base URL is not covered; see [Claude Code](docs/claude-code.md).
|
|
129
|
+
|
|
130
|
+
### CLI only
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
leakshield --file ./path/to/file
|
|
134
|
+
```
|
|
81
135
|
|
|
82
|
-
Before relying on
|
|
136
|
+
Before relying on any host, read [what this protects — and what it does not](#what-this-protects--and-what-it-does-not). For source builds and other options, see [Installation](#installation). New contributors: [3-minute onboarding](docs/ONBOARDING.zh-TW.md) (Traditional Chinese only).
|
|
83
137
|
|
|
84
138
|
---
|
|
85
139
|
|
|
@@ -93,61 +147,28 @@ Before relying on it, read [what this protects — and what it does not](#what-t
|
|
|
93
147
|
| Private Key | PEM private key blocks | 🔴 HIGH |
|
|
94
148
|
| DB Connection String | MongoDB, PostgreSQL, MySQL, Redis, ADO format, etc. | 🔴 HIGH |
|
|
95
149
|
| Taiwan National ID | Format validation | 🔴 HIGH |
|
|
150
|
+
| Passport (MRZ) | TD3 line 2 only: 44 uppercase characters plus four ICAO 9303 check digits | 🔴 HIGH |
|
|
151
|
+
| US SSN | **Opt-in** — `rule_overrides["ssn-us"]: true`; hyphenated form only, invalid areas, groups and serials excluded | 🔴 HIGH |
|
|
152
|
+
| Taiwan Business No | **Opt-in** — `rule_overrides["tw-business-no"]: true`; 8 digits, divisible-by-5 checksum (2023 rule); about one in five random numbers passes, so dates can match | 🟡 MEDIUM |
|
|
96
153
|
| Credit Card Number | 13–19 digits, Luhn checksum required | 🔴 HIGH |
|
|
97
154
|
| IBAN | Compact or 4-char groups, mod-97 checksum required | 🔴 HIGH |
|
|
98
155
|
| Public IPv4 Address | Private/loopback/CGNAT/reserved ranges excluded; runs longer than four groups are reported whole | 🟡 MEDIUM |
|
|
99
156
|
| Private IPv4 / VPN CIDR | **Opt-in** — disabled by default (`rule_overrides["private-ipv4"]: true`); networks from `settings.private_cidrs`, default RFC 1918 + CGNAT + link-local | 🟡 MEDIUM |
|
|
100
157
|
| Email Address | All email formats | 🟡 MEDIUM |
|
|
101
158
|
| URL Embedded Credential | `scheme://user:password@host` — only the userinfo span is masked | 🔴 HIGH |
|
|
102
|
-
| Taiwan Mobile Number | **Opt-in** — disabled by default (`rule_overrides["phone-tw"]: true`); digit runs are a measured false-positive source | 🟡 MEDIUM |
|
|
103
|
-
| International Phone | **Opt-in** — disabled by default (`rule_overrides["phone-intl"]: true`); same trade-off as above | 🟢 LOW |
|
|
159
|
+
| Taiwan Mobile Number | **Opt-in** — disabled by default (`rule_overrides["phone-tw"]: true`); `09xx` or `+886 9xx`, with optional spaces or hyphens; digit runs are a measured false-positive source | 🟡 MEDIUM |
|
|
160
|
+
| International Phone | **Opt-in** — disabled by default (`rule_overrides["phone-intl"]: true`); `+` and 7–15 digits, one space or hyphen allowed between digits; same trade-off as above | 🟢 LOW |
|
|
104
161
|
| HTTP(S) URL | **Opt-in** — disabled by default (`rule_overrides.url: true`) | 🟢 LOW |
|
|
105
|
-
| NDA Keywords |
|
|
106
|
-
| Private Domains |
|
|
107
|
-
|
|
108
|
-
> **Detection boundaries** (per `src/rules/builtin.ts`): the generic secret rule matches only the keywords `password`, `passwd`, `secret`, `private_key`, `client_secret` with a value of **8+ characters** — generic `api_key=`/`token=` assignments are not matched unless the value itself matches a vendor pattern. It also skips an unquoted value that is a code expression, such as `process.env.DB_PASSWORD` or `z.string().min(6)`; a call whose arguments hold another string literal is still reported. Credit card and IBAN matches require a valid checksum, and the credit card rule skips a run of one repeated digit and digits inside a UUID. The URL credential and DB connection rules skip a password that is a `${…}`, `{{…}}` or `<…>` placeholder. IP matches cover only public/routable IPv4, and a dotted run longer than four groups is reported whole so an address embedded in it is masked instead of left behind (dotted dates such as `2026.10.21.14.32.59` therefore report as an IP run too). Not covered by any rule: street/postal addresses, dates, IPv6, and values below the 8-character minimum for generic secret assignments. SSH remote authorities (`user@host:path`, `ssh://user@host/…`) are not reported as email; private domains and path keywords still apply inside them, and the password half of `scheme://user:password@host` is reported as a URL credential instead. Private IPv4 is opt-in because the literal also matches version numbers and timestamps; `settings.private_cidrs` narrows it to the organisation's own ranges, and an entry that does not parse fails the config load. Every built-in rule has a stable id and can be toggled via `settings.rule_overrides` in `config/guard.config.yaml` (unknown ids fail config load); the URL rule ships disabled because always-on URL masking would flag provider endpoints. The same rule set (built-in + `config/guard.config.yaml`) applies to every mode — `block`, `redact`, and `transparent`.
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## Decision Model
|
|
113
|
-
|
|
114
|
-
Every scan produces a **decision** that tells the caller how to handle the content:
|
|
115
|
-
|
|
116
|
-
| Decision | When | Risk Level | Meaning |
|
|
117
|
-
|----------|------|-----------|---------|
|
|
118
|
-
| `ALLOW` | No findings | LOW | Content is clean — safe to send |
|
|
119
|
-
| `WARN` | LOW-severity findings only | MEDIUM | Minor items detected — reminder shown, content can be sent |
|
|
120
|
-
| `CONFIRM` | MEDIUM or HIGH findings | HIGH / CRITICAL | Sensitive content detected — user must explicitly confirm |
|
|
121
|
-
|
|
122
|
-
### CONFIRM Handling
|
|
123
|
-
|
|
124
|
-
When the decision is `CONFIRM`, the CLI is non-interactive: it prints a warning card and a next-step hint, and does not prompt you to choose. The hint points to `--format json` (read `redactedContent`) or `--redact` (sanitized output). Exit code `1` means the content was blocked.
|
|
125
|
-
|
|
126
|
-
The `CONFIRM` decision includes:
|
|
127
|
-
- `recommendedAction`: `REVIEW` (MEDIUM findings) or `BLOCK` (HIGH findings)
|
|
128
|
-
- `safePreview`: a masked excerpt around the first finding
|
|
129
|
-
- `redactedContent`: the full content with all sensitive spans replaced
|
|
162
|
+
| NDA Keywords | Defaults plus your own (see [Configuration](#configuration)) | 🔴 HIGH |
|
|
163
|
+
| Private Domains | Your own (see [Configuration](#configuration)) | 🟡 MEDIUM |
|
|
130
164
|
|
|
131
|
-
`
|
|
132
|
-
|
|
133
|
-
### JSON Output Fields
|
|
134
|
-
|
|
135
|
-
When using `--format json`, the output includes these decision-oriented fields:
|
|
136
|
-
|
|
137
|
-
| Field | Description |
|
|
138
|
-
|-------|-------------|
|
|
139
|
-
| `decision` | `ALLOW`, `WARN`, or `CONFIRM` |
|
|
140
|
-
| `riskLevel` | `LOW`, `MEDIUM`, `HIGH`, or `CRITICAL` |
|
|
141
|
-
| `recommendedAction` | `REVIEW` or `BLOCK` (CONFIRM only) |
|
|
142
|
-
| `findings` | Array of sanitized findings (no internal metadata) |
|
|
143
|
-
| `safePreview` | Masked excerpt (CONFIRM only; can be absent) |
|
|
144
|
-
| `redactedContent` | Full redacted text (CONFIRM only; can be absent) |
|
|
165
|
+
> **Detection boundaries** (per `src/rules/builtin.ts`): the generic secret rule matches only the keywords `password`, `passwd`, `secret`, `private_key`, `client_secret` with a value of **8+ characters** — generic `api_key=`/`token=` assignments are not matched unless the value itself matches a vendor pattern. It also skips an unquoted value that is a code expression, such as `process.env.DB_PASSWORD` or `z.string().min(6)`; a call whose arguments hold another string literal is still reported. Credit card and IBAN matches require a valid checksum, and the credit card rule skips a run of one repeated digit and digits inside a UUID. The URL credential and DB connection rules skip a password that is a `${…}`, `{{…}}` or `<…>` placeholder. IP matches cover only public/routable IPv4, and a dotted run longer than four groups is reported whole so an address embedded in it is masked instead of left behind (dotted dates such as `2026.10.21.14.32.59` therefore report as an IP run too). Passport detection reads the MRZ line only, so a bare passport number beside a label needs a custom rule, and SSN detection requires the hyphenated 3-2-4 form. Not covered by any rule: street/postal addresses, dates, IPv6, and values below the 8-character minimum for generic secret assignments. SSH remote authorities (`user@host:path`, `ssh://user@host/…`) are not reported as email; private domains and path keywords still apply inside them, and the password half of `scheme://user:password@host` is reported as a URL credential instead. Private IPv4 is opt-in because the literal also matches version numbers and timestamps; `settings.private_cidrs` replaces its default networks, for example with your organisation's own ranges, and an entry that does not parse fails the config load. Every built-in rule has a stable id and can be toggled via `settings.rule_overrides` in your config file ([ids](docs/configuration.md#built-in-rule-ids); unknown ids fail config load); the URL rule ships disabled because always-on URL masking would flag provider endpoints. The same rule set (built-in rules plus your config) applies to every mode — `block`, `redact`, and `transparent` — and every host.
|
|
145
166
|
|
|
146
167
|
---
|
|
147
168
|
|
|
148
169
|
## Installation
|
|
149
170
|
|
|
150
|
-
Requires Node.js 20 or later. Mapping persistence needs 22.13 or later.
|
|
171
|
+
Requires Node.js 20 or later. Mapping persistence needs 22.13 or later, and the pi extension needs 22.19 or later.
|
|
151
172
|
|
|
152
173
|
```bash
|
|
153
174
|
npm install -g leakshield
|
|
@@ -171,85 +192,25 @@ For local development, install the build globally or `npm link` it, then use
|
|
|
171
192
|
`leakshield` directly. `npm run scan -- ...` works from this repository without
|
|
172
193
|
installing.
|
|
173
194
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
| Command | Description |
|
|
177
|
-
|---------|-------------|
|
|
178
|
-
| `npm run build` | Clean, then compile TypeScript → `dist/` |
|
|
179
|
-
| `npm run clean` | Remove `dist/` |
|
|
180
|
-
| `npm start` | Run the built CLI (`node dist/cli.js --cli`) |
|
|
181
|
-
| `npm run dev` | CLI mode (no build needed) |
|
|
182
|
-
| `npm run scan` | CLI scan (no build needed) |
|
|
183
|
-
| `npm run web` | Start the local Web UI (no build needed) |
|
|
184
|
-
| `npm test` | Run unit tests |
|
|
185
|
-
| `npm run test:watch` | Run tests in watch mode |
|
|
186
|
-
| `npm run binary` | Build standalone binary for current platform (macOS ARM) |
|
|
187
|
-
| `npm run binary:win` | Cross-compile for Windows x64 |
|
|
188
|
-
| `npm run binary:linux` | Cross-compile for Linux x64 |
|
|
189
|
-
| `npm run binary:mac-intel` | Cross-compile for macOS Intel |
|
|
190
|
-
| `npm run binary:win-icon` | Build the Windows binary with the app icon (`scripts/build-win.js`) |
|
|
191
|
-
| `npm run binary:all` | Build all platforms at once |
|
|
192
|
-
| `npm run bundle:mac` | Build the binary and package a macOS bundle (`scripts/bundle-mac.sh`) |
|
|
195
|
+
To run without Node.js, build a standalone binary of the CLI with Bun: see [Build it yourself](BINARY-GUIDE.md#build-it-yourself). Development scripts are listed in [CONTRIBUTING](CONTRIBUTING.md#npm-scripts).
|
|
193
196
|
|
|
194
197
|
---
|
|
195
198
|
|
|
196
|
-
##
|
|
197
|
-
|
|
198
|
-
Can't use Node.js or npm? Build a standalone binary with [Bun](https://bun.sh) — no runtime needed on the target machine.
|
|
199
|
-
|
|
200
|
-
```bash
|
|
201
|
-
# One-command build for current platform
|
|
202
|
-
npm run binary
|
|
203
|
-
|
|
204
|
-
# Cross-compile for other platforms
|
|
205
|
-
npm run binary:win # Windows x64 → leakshield.exe
|
|
206
|
-
npm run binary:linux # Linux x64 → leakshield-linux
|
|
207
|
-
npm run binary:all # All platforms
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
Or directly with Bun:
|
|
211
|
-
|
|
212
|
-
```bash
|
|
213
|
-
bun build --compile --target=bun-windows-x64 ./src/cli.ts --outfile=leakshield.exe
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
The output is a single executable — hand it to anyone, no dependencies required.
|
|
217
|
-
|
|
218
|
-
### Configuration for binary and npm users
|
|
219
|
-
|
|
220
|
-
The binary and the npm package work out of the box with built-in defaults. To customize rules (NDA keywords, private domains, custom regex patterns), place a config file in one of these locations:
|
|
199
|
+
## Usage
|
|
221
200
|
|
|
222
|
-
|
|
223
|
-
|----------|-------|
|
|
224
|
-
| `./config/guard.config.yaml` | Current working directory |
|
|
225
|
-
| `~/.leakshield/guard.config.yaml` | All sessions (user home) |
|
|
201
|
+
### What this protects — and what it does not
|
|
226
202
|
|
|
227
|
-
|
|
228
|
-
# Quick start: copy config/guard.config.example.yaml from this repository,
|
|
229
|
-
# then replace its sample keywords and domains
|
|
230
|
-
mkdir -p ~/.leakshield
|
|
231
|
-
cp config/guard.config.example.yaml ~/.leakshield/guard.config.yaml
|
|
203
|
+
LeakShield protects model-conversation content: prompts, replayed history, tool outputs, and provider-bound request bodies whose shape it can parse. How much of that each host covers differs; `leakshield --doctor <host>` and the [host capability matrix](docs/host-capabilities.md) list it. It is **not** a tool-egress firewall: a permitted local tool can still transmit originals over the network via `curl`, a remote MCP server, or any other channel. Controlling tool destinations requires a separate permission layer outside LeakShield. Since 0.3.0, `curl` and `http` may also hold a placeholder inside an argument, so a tool can call an API with the protected value; the original then leaves the machine by design. Traffic the host or its dependencies send on their own, such as telemetry, analytics and error or crash reports, is likewise out of reach: it does not pass the model boundary, so LeakShield cannot see it, even with a zero-data-retention (ZDR) provider. Restricting that traffic is a job for the host's own settings or an OS-level sandbox or firewall.
|
|
232
204
|
|
|
233
|
-
|
|
234
|
-
mkdir -p ./config
|
|
235
|
-
# Create/edit ./config/guard.config.yaml as needed
|
|
236
|
-
```
|
|
205
|
+
Detection also has known gaps: street/postal addresses, dates, IPv6, and generic assignments outside the keyword list or below the 8-character minimum pass through undetected. Credit card and IBAN numbers are detected only when the checksum validates; IP detection covers public IPv4 only; passport detection reads the MRZ line only; United States SSN, Taiwan business-number, phone and URL detection are opt-in — see [Detection Coverage](#detection-coverage).
|
|
237
206
|
|
|
238
|
-
|
|
207
|
+
Local originals may remain in history, logs, and generated files — this protects the model boundary, not your disk.
|
|
239
208
|
|
|
240
209
|
---
|
|
241
210
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
### OpenCode Plugin (recommended)
|
|
211
|
+
### OpenCode plugin
|
|
245
212
|
|
|
246
|
-
When loaded successfully, the OpenCode plugin is the enforced integration. It scans and blocks user text before OpenCode persists or sends it to a model, sanitizes system prompts and tool definitions, protects tool output before the next model turn, and re-scans history before replay.
|
|
247
|
-
|
|
248
|
-
Transparent mode details: [Encoded content and tool schemas](docs/plugin/transparent-mode.md#encoded-content-and-tool-schemas).
|
|
249
|
-
|
|
250
|
-
LeakShield supports OpenCode v2 only. v2 hosts load the package `id` + `setup(ctx)` definition. OpenCode v1 is no longer supported: a v1 host that loads the package gets hooks that fail closed and abort every model request, and `leakshield --doctor` reports `BROKEN`. Upgrade to OpenCode v2.
|
|
251
|
-
|
|
252
|
-
**OpenCode v2** — point `plugins` at the published package, or at the `dist` directory of a local build:
|
|
213
|
+
When loaded successfully, the OpenCode plugin is the enforced integration. It scans and blocks user text before OpenCode persists or sends it to a model, sanitizes system prompts and tool definitions, protects tool output before the next model turn, and re-scans history before replay. In transparent mode (the default) it also validates the final provider body. Invalid plugin options or scanner configuration make every protected hook fail closed and abort the model request. OpenCode v2 only.
|
|
253
214
|
|
|
254
215
|
```jsonc
|
|
255
216
|
{
|
|
@@ -257,496 +218,104 @@ LeakShield supports OpenCode v2 only. v2 hosts load the package `id` + `setup(ct
|
|
|
257
218
|
"plugins": [
|
|
258
219
|
{
|
|
259
220
|
"package": "leakshield" // or "/absolute/path/to/leakshield/dist"
|
|
260
|
-
// No options: mode defaults to "transparent" on v2.
|
|
261
221
|
// Add "options": { "mode": "block" } to refuse instead of pseudonymize.
|
|
262
222
|
}
|
|
263
223
|
]
|
|
264
224
|
}
|
|
265
225
|
```
|
|
266
226
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
The default `mode` is **`transparent`** (see [Transparent mode](docs/plugin/transparent-mode.md)). `block` replaces unsafe content with a disclosure-free notice; set `"mode": "block"` to use it. Set `mode` to `redact` only when you explicitly want recognized direct matches replaced with `[REDACTED_TYPE]` placeholders. `--doctor` shows the mode in effect and marks it `(default)` when the options omit it.
|
|
270
|
-
|
|
271
|
-
#### What `PARTIAL` means
|
|
272
|
-
|
|
273
|
-
`leakshield --doctor` exits 0 for two statuses. They are install-level results, not a guarantee that nothing sensitive reaches a model. Pass `--doctor opencode`, `--doctor claude-code` or `--doctor pi` (also `--doctor=<host>`) to check one host with its own exit code.
|
|
274
|
-
|
|
275
|
-
| Status | Setup | Meaning |
|
|
276
|
-
|--------|-------|---------|
|
|
277
|
-
| `PROTECTED` | `block` or `redact`, or transparent with `wireProtection` omitted or `true` (the v2 default), and every declared capability row covered | Install-level checks pass. In transparent mode, the final HTTP body or supported WS frame is validated too |
|
|
278
|
-
| `PARTIAL` | Transparent with `wireProtection: false` ([hook-first example](config/opencode.hook-first.example.json)), or a host whose [declared capability rows](docs/host-capabilities.md) include `unknown` or `outside` | Final outbound HTTP bodies are not inspected, or a declared egress is not covered; the doctor names the row and the issue that closes it |
|
|
279
|
-
|
|
280
|
-
Doctor prints `Configuration status` and `Wire protection` separately from host-wide `Coverage`. `Wire protection: enabled` describes the validated configuration, not proof of interception in a live session; block mode reports `not-applicable`, and an unknown configuration reports `unknown`. A `PARTIAL` verdict lists configuration and host-coverage reasons separately, including both when both apply. Host coverage is not filtered to your selected provider/model. Each host section also prints its declared credential handling, mapping-persistence policy and complete residual list; `opt-in` describes persistence support, not whether it is enabled in your install.
|
|
281
|
-
|
|
282
|
-
With `PARTIAL`:
|
|
283
|
-
|
|
284
|
-
- Later-added content or attachments may leave unmasked, even with `attachments: "block"`.
|
|
285
|
-
- **Content-hook masking failures still refuse the affected call**; hook-only does not silently forward unprotectable raw content.
|
|
286
|
-
|
|
287
|
-
See [Wire protection](docs/plugin/wire-protection.md) for both levels.
|
|
288
|
-
|
|
289
|
-
#### Detailed guides
|
|
290
|
-
|
|
291
|
-
- [Transparent mode](docs/plugin/transparent-mode.md): placeholders, supported protocols, tool argument restoration (per field, `code`/`script` fields, Code Mode, `curl`, `rtk`), restart limitation
|
|
292
|
-
- [Wire protection](docs/plugin/wire-protection.md): hook-only and final wire levels, AI SDK providers, refusals, reply-side recovery
|
|
293
|
-
- [Native WebSocket](docs/plugin/websocket.md): experimental Responses-family support and its limits
|
|
294
|
-
- [Mapping persistence](docs/plugin/persistence.md): opt-in encrypted storage, key custody, erasure
|
|
295
|
-
- [Capacity and lifecycle](docs/plugin/capacity.md): budgets, session limits, retention
|
|
296
|
-
- [Readonly env queries](docs/plugin/env-queries.md): opt-in tools that answer configuration questions without returning values
|
|
297
|
-
- [Host capability matrix](docs/host-capabilities.md): per-host declaration of which model egress and surfaces are protected, refused, absent, or outside interception, and the invariants a new adapter must satisfy
|
|
298
|
-
|
|
299
|
-
#### Persistence risk notes (read before enabling)
|
|
300
|
-
|
|
301
|
-
Mapping persistence is opt-in; see [Mapping persistence](docs/plugin/persistence.md).
|
|
302
|
-
|
|
303
|
-
- The design is dual-secret — the DB file alone or the key alone exposes nothing; both together do.
|
|
304
|
-
- Backups (Time Machine, cloud sync) copy `SGP.db`: `forget` cannot reclaim what a backup already captured, and a restored backup plus a surviving key can re-identify old sessions — treat backup retention accordingly.
|
|
305
|
-
- The keychain defends offline file theft (stolen disk, stolen backups, a copied `SGP.db`); it does not defend malware already running inside your login session.
|
|
306
|
-
- The keyfile option lowers the bar to "both files from the same directory tree" and is intended for headless/server environments without a keychain service.
|
|
227
|
+
Modes, `PARTIAL`, attachments, email de-identification, the isolated smoke test and what `--doctor` checks: [OpenCode plugin](docs/opencode.md). Feature guides: [transparent mode](docs/plugin/transparent-mode.md), [wire protection](docs/plugin/wire-protection.md), [native WebSocket](docs/plugin/websocket.md), [mapping persistence](docs/plugin/persistence.md), [capacity](docs/plugin/capacity.md), [readonly env queries](docs/plugin/env-queries.md).
|
|
307
228
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
```jsonc
|
|
311
|
-
{ "package": "/absolute/path/to/leakshield/dist", "options": { "mode": "redact", "deidentify": true } }
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
Attachments: transparent mode supports an `attachments` policy (plural; `attachment` is not recognized). **`"block"` (default)** omits media/file parts at content hooks and replaces them with a notice; the model cannot read those omitted images. Final wire protection also refuses residual wire attachment parts; hook-first does not inspect late-added attachments. **`"allow"`** sends attachments through unscanned and appends a visible notice part — an explicit decision that you vouch for their content (`"allow"` requires `mode: "transparent"`). In block/redact modes attachments are blocked as before. Existing conversations can replay originals, subject to the [restart limitations](docs/plugin/transparent-mode.md#restart-limitation); starting a new conversation is not a substitute for verifying recovery. The plugin protects OpenCode model requests only, not other AI clients or local tools.
|
|
315
|
-
|
|
316
|
-
OpenCode currently logs and skips modules that fail before their plugin factory can run, such as a missing package or JavaScript syntax error. After installation or upgrade, run a smoke test with a synthetic key matching `sk-` followed by at least 20 letters or digits and verify that LeakShield replaces the message before using real sensitive data.
|
|
317
|
-
|
|
318
|
-
#### Isolated smoke test (OpenCode v2)
|
|
319
|
-
|
|
320
|
-
Run this from the project root. It uses a temporary working directory and a synthetic value, not a real credential:
|
|
321
|
-
|
|
322
|
-
```bash
|
|
323
|
-
npm run build
|
|
324
|
-
SMOKE_DIR="$(mktemp -d)"
|
|
325
|
-
PROJECT_DIR="$(pwd)"
|
|
326
|
-
cat > "$SMOKE_DIR/opencode.json" <<EOF
|
|
327
|
-
{
|
|
328
|
-
"$schema": "https://opencode.ai/config.json",
|
|
329
|
-
"plugins": [
|
|
330
|
-
{ "package": "$PROJECT_DIR/dist", "options": { "mode": "block" } }
|
|
331
|
-
]
|
|
332
|
-
}
|
|
333
|
-
EOF
|
|
334
|
-
(cd "$SMOKE_DIR" && opencode run --standalone \
|
|
335
|
-
"Smoke test only. Do not reveal or use this token: sk-AAAAAAAAAAAAAAAAAAAA")
|
|
336
|
-
rm -rf "$SMOKE_DIR"
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
The model-facing message must contain the LeakShield block notice and must not contain the synthetic token. Do not use a real credential for this test.
|
|
340
|
-
|
|
341
|
-
To test the published package, use `"leakshield"` instead of the local `dist` path.
|
|
229
|
+
---
|
|
342
230
|
|
|
343
|
-
|
|
231
|
+
### pi (in-process extension)
|
|
344
232
|
|
|
345
233
|
```bash
|
|
346
|
-
|
|
234
|
+
pi install npm:leakshield # or: pi -e /path/to/leakshield/dist/adapters/pi/extension.js
|
|
235
|
+
leakshield --doctor pi # checks registration, order and wire API
|
|
347
236
|
```
|
|
348
237
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
Doctor is an install-level check that runs outside the host — it cannot see inside a live session. Runtime proof comes from the smoke test above or `scripts/e2e/run-boundary.mjs`.
|
|
352
|
-
|
|
353
|
-
### What this protects — and what it does not
|
|
354
|
-
|
|
355
|
-
LeakShield protects model-conversation content: prompts, replayed history, tool outputs, and (in transparent mode) provider-bound request bodies whose shape it can parse. It is **not** a tool-egress firewall: a permitted local tool can still transmit originals over the network via `curl`, a remote MCP server, or any other channel. Controlling tool destinations requires a separate permission layer outside this plugin. Since 0.3.0, `curl` and `http` may also hold a placeholder inside an argument, so a tool can call an API with the protected value; the original then leaves the machine by design.
|
|
356
|
-
|
|
357
|
-
Detection also has known gaps: street/postal addresses, dates, IPv6, and generic assignments outside the keyword list or below the 8-character minimum pass through undetected. Credit card and IBAN numbers are detected only when the checksum validates; IP detection covers public IPv4 only; URL detection exists but is opt-in — see [Detection Coverage](#detection-coverage).
|
|
358
|
-
|
|
359
|
-
Local originals may remain in history, logs, and generated files — this protects the model boundary, not your disk.
|
|
238
|
+
pi resolves `fetch` when it builds a provider client, including compaction and branch summaries, so an extension that wraps `globalThis.fetch` covers the same traffic the OpenCode plugin covers through its wire hook. Every provider request is masked in-process; assistant text is restored in the reply, and `read`, `write`, `edit`, `bash` and `powershell` arguments are restored at the local execution boundary. Session files stay with pi, so `--continue`, `--resume` and `--session` keep working. Verified against pi 1.6.0 with a recording stub; providers that bypass fetch (Codex WebSocket, Bedrock, Google auth) are refused, OAuth-only accounts are not supported, and loading the extension first keeps other extensions from holding the raw fetch. See [pi adapter](docs/pi.md).
|
|
360
239
|
|
|
361
240
|
---
|
|
362
241
|
|
|
363
|
-
### Claude Code (local proxy)
|
|
242
|
+
### Claude Code (local proxy, experimental)
|
|
364
243
|
|
|
365
244
|
```bash
|
|
366
245
|
leakshield --claude-code-proxy # listens on 127.0.0.1:8787
|
|
367
246
|
export ANTHROPIC_BASE_URL=http://127.0.0.1:8787 # or the "env" block of ~/.claude/settings.json
|
|
368
|
-
leakshield --doctor
|
|
247
|
+
leakshield --doctor claude-code # checks the wiring
|
|
369
248
|
```
|
|
370
249
|
|
|
371
250
|
The proxy masks every Anthropic Messages request Claude Code sends (and `count_tokens`), restores placeholders in the assistant's JSON or streamed text, and blocks anything it cannot mask instead of forwarding it. It is verified with an API key; Claude Code documents that the base URL also applies to a claude.ai login, which has not been tested here. It does not restore placeholders inside tool calls, and it cannot see traffic that bypasses the base URL, such as WebFetch's domain check, which sends the hostname to Anthropic. Setup and the full list of gaps: [docs/claude-code.md](docs/claude-code.md).
|
|
372
251
|
|
|
373
252
|
---
|
|
374
253
|
|
|
375
|
-
###
|
|
254
|
+
### Across hosts
|
|
376
255
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
leakshield --doctor pi # checks registration, order and wire API
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
pi resolves `fetch` when it builds a provider client, including compaction and branch summaries, so an extension that wraps `globalThis.fetch` covers the same traffic the OpenCode plugin covers through its wire hook. Every provider request is masked in-process; assistant text is restored in the reply, and `read`, `write`, `edit`, `bash` and `powershell` arguments are restored at the local execution boundary. Session files stay with pi, so `--continue`, `--resume` and `--session` keep working. Verified against pi 1.6.0 with a recording stub; providers that bypass fetch (Codex WebSocket, Bedrock, Google auth) are refused, OAuth-only accounts are not supported, and the extension has to load first. See [pi adapter](docs/pi.md).
|
|
383
|
-
|
|
384
|
-
---
|
|
385
|
-
|
|
386
|
-
### CLI
|
|
387
|
-
|
|
388
|
-
```bash
|
|
389
|
-
# Scan text
|
|
390
|
-
npm run scan -- --text 'sk-proj-test1234567890abcdef my_password="super_secret"'
|
|
391
|
-
|
|
392
|
-
# Scan a single file
|
|
393
|
-
npm run scan -- --file ./src/config.ts
|
|
394
|
-
|
|
395
|
-
# Scan an entire directory
|
|
396
|
-
npm run scan -- --dir ./src
|
|
397
|
-
|
|
398
|
-
# Scan specific file extensions only
|
|
399
|
-
npm run scan -- --dir ./src --ext .ts .env .json
|
|
400
|
-
|
|
401
|
-
# Read from stdin
|
|
402
|
-
cat .env | npm run scan -- --stdin
|
|
403
|
-
|
|
404
|
-
# Global installation
|
|
405
|
-
leakshield --file ./config.ts
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
Exit codes: `0` = safe (ALLOW), `1` = findings detected (WARN or CONFIRM), `2` = file not found
|
|
409
|
-
|
|
410
|
-
#### Redaction Mode
|
|
411
|
-
|
|
412
|
-
Replace sensitive content with `[REDACTED_TYPE]` placeholders instead of just reporting it:
|
|
413
|
-
|
|
414
|
-
```bash
|
|
415
|
-
# Redact stdin and print to stdout
|
|
416
|
-
echo 'token=sk-proj-test1234567890abcdef' | npm run scan -- --redact --stdin
|
|
417
|
-
|
|
418
|
-
# Redact a file and write result to a new file
|
|
419
|
-
npm run scan -- --redact --file .env --out .env.redacted
|
|
420
|
-
|
|
421
|
-
# Dry-run: preview what would be redacted without producing any output
|
|
422
|
-
npm run scan -- --redact --dry-run --file .env
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
Redacted output goes to **stdout**; the findings summary goes to **stderr** so they can be separated in pipelines.
|
|
426
|
-
|
|
427
|
-
| Flag | Behaviour |
|
|
428
|
-
|------|-----------|
|
|
429
|
-
| `--redact` | Replace findings with `[REDACTED_TYPE]`, write to stdout; output is suppressed if findings remain after redaction |
|
|
430
|
-
| `--redact --dry-run` | Preview findings only, no output; exit `1` if any found |
|
|
431
|
-
| `--redact --out <path>` | Write redacted text to file instead of stdout |
|
|
432
|
-
| `--redact --format json` | Return JSON with `redacted`, `findings`, and `summary` fields |
|
|
433
|
-
|
|
434
|
-
#### CLI Options
|
|
435
|
-
|
|
436
|
-
| Option | Description |
|
|
437
|
-
|--------|-------------|
|
|
438
|
-
| `--format json` | JSON output (CI/CD friendly) |
|
|
439
|
-
| `--min-severity high` | Only report HIGH (or `medium` / `low`) |
|
|
440
|
-
| `--allow-outside` | Allow scanning paths outside the current working directory (disabled by default) |
|
|
441
|
-
| `--enable-encoding-detection` | Also decode Base64, URL-encoded and hex content before scanning (disabled by default) |
|
|
442
|
-
|
|
443
|
-
#### Encoding Detection
|
|
444
|
-
|
|
445
|
-
**Why encoding detection?**
|
|
446
|
-
|
|
447
|
-
Encoding tricks can bypass sensitive-data detection:
|
|
448
|
-
- **Base64 encoding**: an API key or password is encoded before it is sent
|
|
449
|
-
- **URL encoding**: formats such as `%20` hide keywords
|
|
450
|
-
- **Hex encoding**: hexadecimal encoding evades pattern matching
|
|
451
|
-
|
|
452
|
-
**Enabling**
|
|
453
|
-
|
|
454
|
-
```bash
|
|
455
|
-
# Enable encoding detection
|
|
456
|
-
npm run scan -- --enable-encoding-detection --text "c2stcHJvai10ZXN0MTIzNDU2Nzg5MGFiY2RlZg=="
|
|
457
|
-
|
|
458
|
-
# Combine with other options
|
|
459
|
-
npm run scan -- --enable-encoding-detection --file ./config.yaml --format json
|
|
460
|
-
|
|
461
|
-
# Enable when scanning a directory
|
|
462
|
-
npm run scan -- --enable-encoding-detection --dir ./src --ext .ts .env
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
**Performance**
|
|
466
|
-
|
|
467
|
-
Decoding and rescanning can add 10-30% to scan time. Recommendations:
|
|
468
|
-
- **Off by default**: ordinary scans can use the default
|
|
469
|
-
- **Enable on demand**: turn it on for external or unknown content
|
|
470
|
-
- **CI/CD**: recommended in CI pipelines to catch encoding attacks
|
|
471
|
-
|
|
472
|
-
**Examples**
|
|
473
|
-
|
|
474
|
-
```bash
|
|
475
|
-
# Base64-encoded API key
|
|
476
|
-
echo "c2stcHJvai10ZXN0MTIzNDU2Nzg5MGFiY2RlZg==" | npm run scan -- --enable-encoding-detection --stdin
|
|
477
|
-
# → Detects an OpenAI API Key (synthetic value)
|
|
478
|
-
|
|
479
|
-
# URL-encoded sensitive content
|
|
480
|
-
echo "password%3Dsecret123" | npm run scan -- --enable-encoding-detection --stdin
|
|
481
|
-
# → Detects the password keyword
|
|
256
|
+
- [Host capability matrix](docs/host-capabilities.md): per-host declaration of which model egress and surfaces are protected, refused, absent, or outside interception, and the invariants a new adapter must satisfy
|
|
257
|
+
- [Agent hook coverage](docs/hooks.md): how OpenCode, pi and Claude Code expose hooks, and which hook points can mask a request or restore a placeholder
|
|
482
258
|
|
|
483
|
-
|
|
484
|
-
echo "This is safe content" | npm run scan -- --enable-encoding-detection --stdin
|
|
485
|
-
# → Safe, no sensitive content
|
|
486
|
-
```
|
|
259
|
+
#### Persistence risk notes (read before enabling)
|
|
487
260
|
|
|
488
|
-
|
|
261
|
+
Mapping persistence is opt-in for the OpenCode plugin ([setup](docs/plugin/persistence.md)) and pi (`LEAKSHIELD_PI_PERSIST`, [setup](docs/pi.md#sessions-and-persistence)). The Claude Code proxy keeps mappings in memory only.
|
|
489
262
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
#### Workspace Path Restriction
|
|
263
|
+
- The design is dual-secret — the DB file alone or the key alone exposes nothing; both together do.
|
|
264
|
+
- Backups (Time Machine, cloud sync) copy `SGP.db`: `forget` cannot reclaim what a backup already captured, and a restored backup plus a surviving key can re-identify old sessions — treat backup retention accordingly.
|
|
265
|
+
- The keychain defends offline file theft (stolen disk, stolen backups, a copied `SGP.db`); it does not defend malware already running inside your login session.
|
|
266
|
+
- The keyfile option lowers the bar to "both files from the same directory tree" and is intended for headless/server environments without a keychain service.
|
|
495
267
|
|
|
496
|
-
|
|
268
|
+
---
|
|
497
269
|
|
|
498
|
-
|
|
270
|
+
### CLI and Web UI
|
|
499
271
|
|
|
500
272
|
```bash
|
|
501
|
-
|
|
273
|
+
leakshield --file ./src/config.ts # scan a file (also --text, --dir, --stdin)
|
|
274
|
+
leakshield --redact --file .env --out .env.redacted
|
|
275
|
+
leakshield --web # local browser UI at http://localhost:3000
|
|
502
276
|
```
|
|
503
277
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
#### Ignore Directives
|
|
507
|
-
|
|
508
|
-
The CLI and Web UI skip any line containing `leakshield-ignore`, `guard:skip`, `guard:ignore`, `sg-ignore`, `no-scan` or `skip-guard` (case-insensitive). A real secret on that line reports as `ALLOW`.
|
|
509
|
-
|
|
510
|
-
> ⚠️ Anyone who can edit a scanned file can add a directive, so a CLI scan is not a gate against untrusted changes. The OpenCode plugin does not honor directives.
|
|
278
|
+
Exit codes: `0` = safe, `1` = findings, `2` = path error. Options, redaction, encoding detection, ignore directives, the REST API, the decision model and JSON fields: [CLI and Web UI](docs/cli.md).
|
|
511
279
|
|
|
512
280
|
---
|
|
513
281
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
Start a local web server and use it in your browser:
|
|
517
|
-
|
|
518
|
-
```bash
|
|
519
|
-
# Default port 3000
|
|
520
|
-
npx tsx src/cli.ts --web
|
|
521
|
-
|
|
522
|
-
# Custom port
|
|
523
|
-
npx tsx src/cli.ts --web --port 3001
|
|
524
|
-
|
|
525
|
-
# Built version
|
|
526
|
-
node dist/cli.js --web --port 3001
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
Open `http://localhost:3001` in your browser, paste content, and press **Scan** or `Ctrl+Enter`.
|
|
282
|
+
## Configuration
|
|
530
283
|
|
|
531
|
-
|
|
284
|
+
LeakShield loads the first config file it finds: `./config/guard.config.yaml`, then `config/guard.config.yaml` in the LeakShield directory (source builds only), then `~/.leakshield/guard.config.yaml`. With no file, the built-in defaults apply. The OpenCode plugin also accepts a `configPath` option. The repository does not ship a `config/guard.config.yaml`, and Git ignores one you create there, so your keywords stay local. To start a new file, copy [`config/guard.config.example.yaml`](config/guard.config.example.yaml) and add your own keywords and domains. Listing `nda_keywords` replaces the four defaults (`CONFIDENTIAL`, `INTERNAL ONLY`, `DO NOT SHARE`, `NDA`); the example keeps them.
|
|
532
285
|
|
|
533
|
-
|
|
286
|
+
Without a checkout (npm or binary install), download the example into your home directory:
|
|
534
287
|
|
|
535
288
|
```bash
|
|
536
|
-
|
|
537
|
-
curl -
|
|
538
|
-
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
# Response format
|
|
542
|
-
{
|
|
543
|
-
"decision": "CONFIRM",
|
|
544
|
-
"riskLevel": "CRITICAL",
|
|
545
|
-
"summary": "...",
|
|
546
|
-
"findings": [
|
|
547
|
-
{ "type": "API_KEY", "severity": "HIGH", "description": "OpenAI API Key", "preview": "****", "line": 1 },
|
|
548
|
-
{ "type": "SECRET", "severity": "HIGH", "description": "...", "preview": "****", "line": 1 }
|
|
549
|
-
],
|
|
550
|
-
"recommendedAction": "BLOCK",
|
|
551
|
-
"redactedContent": "[REDACTED_API_KEY] my_[REDACTED_SECRET]",
|
|
552
|
-
"redactionVerified": true,
|
|
553
|
-
"residualFindings": 0,
|
|
554
|
-
"wasTruncated": false
|
|
555
|
-
}
|
|
556
|
-
```
|
|
557
|
-
|
|
558
|
-
`redactedContent` is omitted when `redactionVerified` is `false`.
|
|
559
|
-
|
|
560
|
-
| Endpoint | Method | Description |
|
|
561
|
-
|----------|--------|-------------|
|
|
562
|
-
| `/` | GET | Web UI HTML |
|
|
563
|
-
| `/scan` | POST | Scan `{ "content": string }`, returns JSON |
|
|
564
|
-
|
|
565
|
-
---
|
|
566
|
-
|
|
567
|
-
## Configuration
|
|
568
|
-
|
|
569
|
-
LeakShield loads the first config file it finds: `./config/guard.config.yaml`, then `config/guard.config.yaml` in the LeakShield directory (source builds only), then `~/.leakshield/guard.config.yaml`. With no file, the built-in defaults apply. The OpenCode plugin also accepts a `configPath` option. To start a new file, copy [`config/guard.config.example.yaml`](config/guard.config.example.yaml) and replace its sample keywords and domains.
|
|
570
|
-
|
|
571
|
-
```yaml
|
|
572
|
-
# NDA keywords (case-insensitive)
|
|
573
|
-
nda_keywords:
|
|
574
|
-
- "CONFIDENTIAL"
|
|
575
|
-
- "INTERNAL ONLY"
|
|
576
|
-
- "DO NOT SHARE"
|
|
577
|
-
- "NDA"
|
|
578
|
-
- "PROPRIETARY"
|
|
579
|
-
# Add your own internal keywords:
|
|
580
|
-
# - "Project Phoenix"
|
|
581
|
-
# - "MyCompany Internal"
|
|
582
|
-
|
|
583
|
-
# Private domains
|
|
584
|
-
private_domains:
|
|
585
|
-
- "internal.mycompany.com"
|
|
586
|
-
# - "dev.yourcompany.io"
|
|
587
|
-
|
|
588
|
-
settings:
|
|
589
|
-
max_chars: 200000 # scan bound; transparent mode refuses past it instead of truncating
|
|
590
|
-
show_line_numbers: true
|
|
591
|
-
preview_length: 60
|
|
592
|
-
encoding_detection: false # Base64/URL/Hex decoding; off by default
|
|
289
|
+
mkdir -p ~/.leakshield
|
|
290
|
+
curl -fsSL https://raw.githubusercontent.com/jwcrystal/leakshield/main/config/guard.config.example.yaml \
|
|
291
|
+
-o ~/.leakshield/guard.config.yaml
|
|
292
|
+
leakshield --doctor # confirms the file loads
|
|
593
293
|
```
|
|
594
294
|
|
|
595
295
|
After editing:
|
|
596
296
|
- **CLI**: Reloaded automatically on next run
|
|
597
297
|
- **OpenCode Plugin**: Restart OpenCode to reload the plugin configuration
|
|
298
|
+
- **pi extension**: Restart pi (`LEAKSHIELD_CONFIG` selects another file)
|
|
299
|
+
- **Claude Code proxy**: Restart the proxy (`--config` selects another file)
|
|
598
300
|
- **Web UI**: Restart the local server
|
|
599
301
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
Enable this only for files whose values should never enter an LLM context:
|
|
603
|
-
|
|
604
|
-
```yaml
|
|
605
|
-
settings:
|
|
606
|
-
env_files:
|
|
607
|
-
- .env
|
|
608
|
-
- .env.local
|
|
609
|
-
```
|
|
610
|
-
|
|
611
|
-
Paths are relative to the workspace root and must remain inside it. LeakShield reads non-empty values of at least eight characters, then detects exact occurrences in text sent to the model. It does not automatically read `.env`, process environment variables, or send, log, or serialize the loaded values. Restart OpenCode after changing an enabled env file. The opt-in `envQueries` plugin tools (see [Readonly env queries](docs/plugin/env-queries.md)) query these same files and never return their values.
|
|
612
|
-
|
|
613
|
-
### Custom Rules
|
|
614
|
-
|
|
615
|
-
```yaml
|
|
616
|
-
custom_rules:
|
|
617
|
-
- description: "Company token"
|
|
618
|
-
pattern: "MYCO_[A-Z0-9]{32}"
|
|
619
|
-
severity: HIGH
|
|
620
|
-
flags: "i" # subset of gimsuy; g is always implied
|
|
621
|
-
word_boundary: true # \b only at literal ASCII word edges
|
|
622
|
-
allow: # exact strings this rule never reports
|
|
623
|
-
- "MYCO_EXAMPLE0000000000000000000000000"
|
|
624
|
-
# path: ["src/**"] # accepted, but NOT implemented (see below)
|
|
625
|
-
|
|
626
|
-
settings:
|
|
627
|
-
allowlist: # exact strings no rule reports (see the bypass warning)
|
|
628
|
-
- "qa@example.com"
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
- **`flags`** — any subset of `gimsuy`; `g` is always added. The default is `i`, so
|
|
632
|
-
existing rules keep matching case-insensitively. An unknown flag (such as `x`)
|
|
633
|
-
fails the config load, and the pattern is compiled with the final flags, so a
|
|
634
|
-
pattern that is only invalid under `u` also fails the load.
|
|
635
|
-
Zero-length matches are skipped (they contain no value to report or redact);
|
|
636
|
-
scanning continues to later nonempty matches, including under Unicode flags.
|
|
637
|
-
- **`word_boundary`** — adds `\b` where the pattern's edge is a literal ASCII word
|
|
638
|
-
character. A CJK edge (「機密」) is left alone: `\b` never holds between two
|
|
639
|
-
non-word characters, and wrapping it would stop the rule matching. An edge that
|
|
640
|
-
is a group, character class, quantifier or escape cannot take a boundary safely,
|
|
641
|
-
so none is added and `--doctor` warns that the rule is looser than it looks —
|
|
642
|
-
write `\b` in the pattern yourself, e.g. `\bEMP-\d{6}\b`. A top-level alternation
|
|
643
|
-
(`a|b`) is a config error; group it as `(?:a|b)`.
|
|
644
|
-
- **`allow` / `settings.allowlist`** — exact matches against the matched text, not
|
|
645
|
-
substrings and not regexes. `allow` applies to that rule; `settings.allowlist`
|
|
646
|
-
applies to every rule, including the built-in ones and exact `.env` values.
|
|
647
|
-
Caps: 32 entries per rule, 64 globally, 200 characters each.
|
|
648
|
-
**Allowlisting a live secret is a real bypass**: the value still leaves the
|
|
649
|
-
machine unmasked, and LeakShield will not report that value as a rule or
|
|
650
|
-
`.env` finding. Use it only for values you have decided are not sensitive.
|
|
651
|
-
Unicode evasion diagnostics are separate: a zero-width or look-alike-letter
|
|
652
|
-
warning means removing those characters exposes a finding the raw text hides,
|
|
653
|
-
and an allowlist on the raw text does not silence it. Cyrillic or Greek text
|
|
654
|
-
on its own is not flagged. `--doctor` reports how many entries exist, exercises up to eight
|
|
655
|
-
of them, and reports how many it could not exercise (a context-dependent
|
|
656
|
-
pattern can only be judged in place). Suppressions are counted rather than
|
|
657
|
-
silent.
|
|
658
|
-
- **`path`** — accepted and validated, but path scoping is **not implemented**: the
|
|
659
|
-
scanner has no source path for prompts or tool output. These rules currently
|
|
660
|
-
apply to every scanned text, and `--doctor` warns when `path` is set.
|
|
661
|
-
|
|
662
|
-
Allowlist entries are part of the config file, so they change its fingerprint
|
|
663
|
-
(sha256 of the file), which is what authorizations compare against.
|
|
302
|
+
Every key, the built-in rule ids, `.env` value detection, custom rules and limits: [Configuration reference](docs/configuration.md).
|
|
664
303
|
|
|
665
304
|
---
|
|
666
305
|
|
|
667
|
-
##
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
```
|
|
681
|
-
|
|
682
|
-
### Scenario 2: CLI scan before submitting a project
|
|
683
|
-
|
|
684
|
-
```bash
|
|
685
|
-
npm run scan -- --dir ./my-project
|
|
686
|
-
# If exit code = 1, there are findings — fix them before sharing with AI
|
|
687
|
-
```
|
|
688
|
-
|
|
689
|
-
### Scenario 3: CI/CD integration (block sensitive prompts from the pipeline)
|
|
690
|
-
|
|
691
|
-
```bash
|
|
692
|
-
# Add to your CI script
|
|
693
|
-
node dist/cli.js --cli --dir ./prompts
|
|
694
|
-
if [ $? -ne 0 ]; then
|
|
695
|
-
echo "❌ Sensitive content detected — stopping pipeline"
|
|
696
|
-
exit 1
|
|
697
|
-
fi
|
|
698
|
-
```
|
|
699
|
-
|
|
700
|
-
---
|
|
701
|
-
|
|
702
|
-
## Configuration Validation
|
|
703
|
-
|
|
704
|
-
Input lengths for dynamic rules are validated when the config is loaded:
|
|
705
|
-
|
|
706
|
-
| Field | Max length |
|
|
707
|
-
|-------|-----------|
|
|
708
|
-
| `nda_keywords` entries | 200 characters |
|
|
709
|
-
| `private_domains` entries | 255 characters |
|
|
710
|
-
| `custom_rules` `description` / `pattern` | 200 characters |
|
|
711
|
-
|
|
712
|
-
Values exceeding these limits will cause `loadConfig()` to throw a Zod validation error, preventing oversized patterns from entering the scanner.
|
|
713
|
-
|
|
714
|
-
List sizes are capped too, and a config over a cap fails the load:
|
|
715
|
-
|
|
716
|
-
| Field | Max entries |
|
|
717
|
-
|-------|-------------|
|
|
718
|
-
| `nda_keywords` | 4096 |
|
|
719
|
-
| `private_domains` | 4096 |
|
|
720
|
-
| `custom_rules` | 1024 |
|
|
721
|
-
|
|
722
|
-
A `custom_rules` pattern that does not compile as a regular expression also makes `loadConfig()` throw, naming the rule's index and `description` (not the pattern): a rule that cannot be enforced must not load. A pattern that compiles but runs slowly on a fixed probe input is skipped as a ReDoS suspect, with a warning on stderr and a `custom-rules` warning in `leakshield --doctor`. That check is a timing heuristic, not a guarantee: it runs the pattern once and cannot interrupt it, so it cannot prove a pattern safe.
|
|
723
|
-
|
|
724
|
-
## Secret Preview Behavior
|
|
725
|
-
|
|
726
|
-
All secret previews in scan results are **fully masked** as `****`, regardless of the secret's length. No prefix or suffix characters from the original value are preserved. This eliminates partial secret exposure in logs, CI output, and Web UI responses.
|
|
727
|
-
|
|
728
|
-
## Internationalization (i18n)
|
|
729
|
-
|
|
730
|
-
CLI output language is controlled by the `LEAKSHIELD_LANG` environment variable.
|
|
731
|
-
|
|
732
|
-
| Value | Language |
|
|
733
|
-
|-------|----------|
|
|
734
|
-
| `en` (default) | English |
|
|
735
|
-
| `zh-TW` or `zh` | Traditional Chinese |
|
|
736
|
-
|
|
737
|
-
```bash
|
|
738
|
-
# English output (default)
|
|
739
|
-
npm run scan -- --text "your content"
|
|
740
|
-
|
|
741
|
-
# Traditional Chinese output
|
|
742
|
-
LEAKSHIELD_LANG=zh-TW npm run scan -- --text "你的內容"
|
|
743
|
-
```
|
|
744
|
-
|
|
745
|
-
You can also set it persistently in your shell profile:
|
|
746
|
-
|
|
747
|
-
```bash
|
|
748
|
-
export LEAKSHIELD_LANG=zh-TW
|
|
749
|
-
```
|
|
306
|
+
## Documentation
|
|
307
|
+
|
|
308
|
+
| Topic | Page |
|
|
309
|
+
|-------|------|
|
|
310
|
+
| OpenCode plugin | [docs/opencode.md](docs/opencode.md) |
|
|
311
|
+
| pi extension | [docs/pi.md](docs/pi.md) |
|
|
312
|
+
| Claude Code proxy | [docs/claude-code.md](docs/claude-code.md) |
|
|
313
|
+
| CLI and Web UI | [docs/cli.md](docs/cli.md) |
|
|
314
|
+
| Configuration reference | [docs/configuration.md](docs/configuration.md) |
|
|
315
|
+
| Host capability matrix | [docs/host-capabilities.md](docs/host-capabilities.md) |
|
|
316
|
+
| Standalone binary | [BINARY-GUIDE.md](BINARY-GUIDE.md) |
|
|
317
|
+
| Verification records | [docs/evidence](docs/evidence/README.md) |
|
|
318
|
+
| Contributing | [CONTRIBUTING.md](CONTRIBUTING.md) |
|
|
750
319
|
|
|
751
320
|
## Notes
|
|
752
321
|
|