leakshield 0.0.0-stage â 0.1.0
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/LICENSE +21 -0
- package/README.md +546 -2
- package/README.zh-TW.md +565 -0
- package/dist/cli.js +61 -0
- package/dist/config/loader.js +94 -0
- package/dist/decision/deidentify.js +195 -0
- package/dist/decision/ingress.js +136 -0
- package/dist/decision/mapping-key.js +318 -0
- package/dist/decision/mapping-store.js +555 -0
- package/dist/decision/model.js +76 -0
- package/dist/decision/pseudonymization.js +1230 -0
- package/dist/decision/redaction.js +185 -0
- package/dist/decision/schema-strings.js +42 -0
- package/dist/doctor.js +438 -0
- package/dist/env-queries.js +584 -0
- package/dist/forget.js +56 -0
- package/dist/help.js +37 -0
- package/dist/i18n/en.js +71 -0
- package/dist/i18n/index.js +28 -0
- package/dist/i18n/zh-TW.js +71 -0
- package/dist/index.js +12 -0
- package/dist/opencode-env-tools.js +243 -0
- package/dist/opencode-hooks.js +84 -0
- package/dist/opencode-transparent-aisdk.js +100 -0
- package/dist/opencode-transparent-http.js +2315 -0
- package/dist/opencode-transparent-stream.js +192 -0
- package/dist/opencode-transparent-ws.js +298 -0
- package/dist/opencode-transparent.js +1492 -0
- package/dist/opencode-v2.js +216 -0
- package/dist/opencode.js +175 -0
- package/dist/plugin-options.js +100 -0
- package/dist/rules/builtin.js +283 -0
- package/dist/rules/dynamic.js +68 -0
- package/dist/scanner/encoding.js +274 -0
- package/dist/scanner/engine.js +321 -0
- package/dist/scanner/exact-values.js +99 -0
- package/dist/scanner/redaction-verifier.js +82 -0
- package/dist/scanner/unicode.js +157 -0
- package/dist/scanner/utils.js +60 -0
- package/dist/transports/cli.js +447 -0
- package/dist/transports/web-ui.js +540 -0
- package/dist/transports/web.js +200 -0
- package/dist/types.js +23 -0
- package/dist/utils/files.js +36 -0
- package/dist/utils/path-security.js +30 -0
- package/dist/utils/win-encoding.js +45 -0
- package/package.json +71 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jared Wang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,547 @@
|
|
|
1
|
-
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="./icon.svg">
|
|
3
|
+
<img alt="leakshield" src="./icon.svg" width="64">
|
|
4
|
+
</picture>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
# leakshield
|
|
7
|
+
|
|
8
|
+
> đ English | [çšéŤä¸ć](./README.zh-TW.md)
|
|
9
|
+
|
|
10
|
+
**A gatekeeper that scans for sensitive content before you feed code, documents, or data to AI services.**
|
|
11
|
+
|
|
12
|
+
Three supported modes:
|
|
13
|
+
- **OpenCode Plugin**: The enforced ingress gate for OpenCode. Use this when OpenCode sends content to a model.
|
|
14
|
+
- **CLI**: Manual or CI scanning of text, files, and directories; supports redaction.
|
|
15
|
+
- **Web UI**: Local browser interface and REST endpoint for manual scanning.
|
|
16
|
+
|
|
17
|
+
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 the plugin's security boundary.
|
|
18
|
+
|
|
19
|
+
| Mode | Start it with | Use it for |
|
|
20
|
+
|------|---------------|------------|
|
|
21
|
+
| OpenCode Plugin | Add the `dist` directory (v2) or `dist/opencode.js` (v1) to `opencode.json` | Automatic, fail-closed protection for OpenCode model inputs and tool outputs |
|
|
22
|
+
| 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 |
|
|
23
|
+
| Web UI | `npm run web` | Manual browser scans at `http://localhost:3000` |
|
|
24
|
+
|
|
25
|
+
## Project status
|
|
26
|
+
|
|
27
|
+
**Experimental, pre-release.** Nothing is published to npm yet: build locally (`npm ci && npm run build`) and point OpenCode at the `dist` directory.
|
|
28
|
+
|
|
29
|
+
- Transparent mode has been verified on OpenCode v2.0.28 with local loopback providers, and once against a real OpenAI model. It is **not** a guarantee that nothing sensitive reaches a model: the recommended 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.
|
|
30
|
+
- Not yet verified: OS-keychain persistence, a real Anthropic provider, long histories on other providers, long-running use ([#26](https://github.com/jwcrystal/leakshield/issues/26)).
|
|
31
|
+
- Defaults may still change before the first tagged release ([#24](https://github.com/jwcrystal/leakshield/issues/24), [#27](https://github.com/jwcrystal/leakshield/issues/27)); see the [changelog](CHANGELOG.md).
|
|
32
|
+
- Verification records: [docs/evidence](docs/evidence/README.md). Report vulnerabilities privately: [SECURITY.md](SECURITY.md). License: [MIT](LICENSE).
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Detection Coverage
|
|
37
|
+
|
|
38
|
+
| Type | Description | Severity |
|
|
39
|
+
|------|-------------|----------|
|
|
40
|
+
| API Key | OpenAI, Anthropic, Google, AWS | đ´ HIGH |
|
|
41
|
+
| Secret / Password | Generic password assignments, AWS Secret | đ´ HIGH |
|
|
42
|
+
| Token | GitHub PAT, JWT, Bearer Token | đ´ HIGH |
|
|
43
|
+
| DB Connection String | MongoDB, PostgreSQL, MySQL, Redis, etc. | đ´ HIGH |
|
|
44
|
+
| Taiwan National ID | Format validation | đ´ HIGH |
|
|
45
|
+
| Credit Card Number | 13â19 digits, Luhn checksum required | đ´ HIGH |
|
|
46
|
+
| IBAN | Compact or 4-char groups, mod-97 checksum required | đ´ HIGH |
|
|
47
|
+
| Public IPv4 Address | Private/loopback/CGNAT/reserved ranges excluded | đĄ MEDIUM |
|
|
48
|
+
| Email Address | All email formats | đĄ MEDIUM |
|
|
49
|
+
| Taiwan Mobile Number | **Opt-in** â disabled by default (`rule_overrides["phone-tw"]: true`); digit runs are a measured false-positive source | đĄ MEDIUM |
|
|
50
|
+
| International Phone | **Opt-in** â disabled by default (`rule_overrides["phone-intl"]: true`); same trade-off as above | đ˘ LOW |
|
|
51
|
+
| HTTP(S) URL | **Opt-in** â disabled by default (`rule_overrides.url: true`) | đ˘ LOW |
|
|
52
|
+
| NDA Keywords | Custom (see `config/guard.config.yaml`) | đ´ HIGH |
|
|
53
|
+
| Private Domains | Custom (see `config/guard.config.yaml`) | đĄ MEDIUM |
|
|
54
|
+
|
|
55
|
+
> **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. Credit card and IBAN matches require a valid checksum; IP matches cover only public/routable IPv4. Not covered by any rule: street/postal addresses, dates, IPv6, and values below the 8-character minimum. 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`.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Decision Model
|
|
60
|
+
|
|
61
|
+
Every scan produces a **decision** that tells the caller how to handle the content:
|
|
62
|
+
|
|
63
|
+
| Decision | When | Risk Level | Meaning |
|
|
64
|
+
|----------|------|-----------|---------|
|
|
65
|
+
| `ALLOW` | No findings | LOW | Content is clean â safe to send |
|
|
66
|
+
| `WARN` | LOW-severity findings only | MEDIUM | Minor items detected â reminder shown, content can be sent |
|
|
67
|
+
| `CONFIRM` | MEDIUM or HIGH findings | HIGH / CRITICAL | Sensitive content detected â user must explicitly confirm |
|
|
68
|
+
|
|
69
|
+
### CONFIRM Handling
|
|
70
|
+
|
|
71
|
+
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.
|
|
72
|
+
|
|
73
|
+
The `CONFIRM` decision includes:
|
|
74
|
+
- `recommendedAction`: `REVIEW` (MEDIUM findings) or `BLOCK` (HIGH findings)
|
|
75
|
+
- `safePreview`: a masked excerpt around the first finding
|
|
76
|
+
- `redactedContent`: the full content with all sensitive spans replaced
|
|
77
|
+
|
|
78
|
+
### JSON Output Fields
|
|
79
|
+
|
|
80
|
+
When using `--format json`, the output includes these decision-oriented fields:
|
|
81
|
+
|
|
82
|
+
| Field | Description |
|
|
83
|
+
|-------|-------------|
|
|
84
|
+
| `decision` | `ALLOW`, `WARN`, or `CONFIRM` |
|
|
85
|
+
| `riskLevel` | `LOW`, `MEDIUM`, `HIGH`, or `CRITICAL` |
|
|
86
|
+
| `recommendedAction` | `REVIEW` or `BLOCK` (CONFIRM only) |
|
|
87
|
+
| `findings` | Array of sanitized findings (no internal metadata) |
|
|
88
|
+
| `safePreview` | Masked excerpt (CONFIRM only) |
|
|
89
|
+
| `redactedContent` | Full redacted text (CONFIRM only) |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Installation
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
git clone https://github.com/jwcrystal/leakshield.git
|
|
97
|
+
cd leakshield
|
|
98
|
+
npm install
|
|
99
|
+
npm run build
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Nothing is published to npm yet, so `npx leakshield` only works after you
|
|
103
|
+
install the build globally or `npm link` it; then use `leakshield`
|
|
104
|
+
directly. `npm run scan -- ...` works from this repository without installing.
|
|
105
|
+
|
|
106
|
+
### npm Scripts
|
|
107
|
+
|
|
108
|
+
| Command | Description |
|
|
109
|
+
|---------|-------------|
|
|
110
|
+
| `npm run build` | Clean, then compile TypeScript â `dist/` |
|
|
111
|
+
| `npm run clean` | Remove `dist/` |
|
|
112
|
+
| `npm start` | Run the built CLI (`node dist/cli.js --cli`) |
|
|
113
|
+
| `npm run dev` | CLI mode (no build needed) |
|
|
114
|
+
| `npm run scan` | CLI scan (no build needed) |
|
|
115
|
+
| `npm run web` | Start the local Web UI (no build needed) |
|
|
116
|
+
| `npm test` | Run unit tests |
|
|
117
|
+
| `npm run test:watch` | Run tests in watch mode |
|
|
118
|
+
| `npm run binary` | Build standalone binary for current platform (macOS ARM) |
|
|
119
|
+
| `npm run binary:win` | Cross-compile for Windows x64 |
|
|
120
|
+
| `npm run binary:linux` | Cross-compile for Linux x64 |
|
|
121
|
+
| `npm run binary:mac-intel` | Cross-compile for macOS Intel |
|
|
122
|
+
| `npm run binary:win-icon` | Build the Windows binary with the app icon (`scripts/build-win.js`) |
|
|
123
|
+
| `npm run binary:all` | Build all platforms at once |
|
|
124
|
+
| `npm run bundle:mac` | Build the binary and package a macOS bundle (`scripts/bundle-mac.sh`) |
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Standalone Binary
|
|
129
|
+
|
|
130
|
+
Can't use Node.js or npm? Build a standalone binary with [Bun](https://bun.sh) â no runtime needed on the target machine.
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# One-command build for current platform
|
|
134
|
+
npm run binary
|
|
135
|
+
|
|
136
|
+
# Cross-compile for other platforms
|
|
137
|
+
npm run binary:win # Windows x64 â leakshield.exe
|
|
138
|
+
npm run binary:linux # Linux x64 â leakshield-linux
|
|
139
|
+
npm run binary:all # All platforms
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Or directly with Bun:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
bun build --compile --target=bun-windows-x64 ./src/cli.ts --outfile=leakshield.exe
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The output is a single executable â hand it to anyone, no dependencies required.
|
|
149
|
+
|
|
150
|
+
### Configuration for binary users
|
|
151
|
+
|
|
152
|
+
The binary works out of the box with built-in defaults. To customize rules (NDA keywords, private domains, custom regex patterns), place `config/guard.config.yaml` in one of these locations:
|
|
153
|
+
|
|
154
|
+
| Location | Scope |
|
|
155
|
+
|----------|-------|
|
|
156
|
+
| `./config/guard.config.yaml` | Current working directory |
|
|
157
|
+
| `~/.leakshield/guard.config.yaml` | All sessions (user home) |
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Quick start with custom config
|
|
161
|
+
mkdir -p ~/.leakshield
|
|
162
|
+
cp config/guard.config.yaml ~/.leakshield/
|
|
163
|
+
|
|
164
|
+
# Or per-project
|
|
165
|
+
mkdir -p ./config
|
|
166
|
+
# Create/edit ./config/guard.config.yaml as needed
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
See [Configuration](#configuration) section for available options.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Usage
|
|
174
|
+
|
|
175
|
+
### CLI
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Scan text
|
|
179
|
+
npm run scan -- --text 'sk-proj-test1234567890abcdef my_password="super_secret"'
|
|
180
|
+
|
|
181
|
+
# Scan a single file
|
|
182
|
+
npm run scan -- --file ./src/config.ts
|
|
183
|
+
|
|
184
|
+
# Scan an entire directory
|
|
185
|
+
npm run scan -- --dir ./src
|
|
186
|
+
|
|
187
|
+
# Scan specific file extensions only
|
|
188
|
+
npm run scan -- --dir ./src --ext .ts .env .json
|
|
189
|
+
|
|
190
|
+
# Read from stdin
|
|
191
|
+
cat .env | npm run scan -- --stdin
|
|
192
|
+
|
|
193
|
+
# Global installation
|
|
194
|
+
leakshield --file ./config.ts
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Exit codes: `0` = safe (ALLOW), `1` = findings detected (WARN or CONFIRM), `2` = file not found
|
|
198
|
+
|
|
199
|
+
#### Redaction Mode
|
|
200
|
+
|
|
201
|
+
Replace sensitive content with `[REDACTED_TYPE]` placeholders instead of just reporting it:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Redact stdin and print to stdout
|
|
205
|
+
echo 'token=sk-proj-test1234567890abcdef' | npm run scan -- --redact --stdin
|
|
206
|
+
|
|
207
|
+
# Redact a file and write result to a new file
|
|
208
|
+
npm run scan -- --redact --file .env --out .env.redacted
|
|
209
|
+
|
|
210
|
+
# Dry-run: preview what would be redacted without producing any output
|
|
211
|
+
npm run scan -- --redact --dry-run --file .env
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Redacted output goes to **stdout**; the findings summary goes to **stderr** so they can be separated in pipelines.
|
|
215
|
+
|
|
216
|
+
| Flag | Behaviour |
|
|
217
|
+
|------|-----------|
|
|
218
|
+
| `--redact` | Replace findings with `[REDACTED_TYPE]`, write to stdout |
|
|
219
|
+
| `--redact --dry-run` | Preview findings only, no output; exit `1` if any found |
|
|
220
|
+
| `--redact --out <path>` | Write redacted text to file instead of stdout |
|
|
221
|
+
| `--redact --format json` | Return JSON with `redacted`, `findings`, and `summary` fields |
|
|
222
|
+
|
|
223
|
+
#### CLI Options
|
|
224
|
+
|
|
225
|
+
| Option | Description |
|
|
226
|
+
|--------|-------------|
|
|
227
|
+
| `--format json` | JSON output (CI/CD friendly) |
|
|
228
|
+
| `--min-severity high` | Only report HIGH (or `medium` / `low`) |
|
|
229
|
+
| `--allow-outside` | Allow scanning paths outside the current working directory (disabled by default) |
|
|
230
|
+
|
|
231
|
+
#### Workspace Path Restriction
|
|
232
|
+
|
|
233
|
+
By default, `--file` and `--dir` only accept paths **inside the current working directory**. Attempts to scan outside (e.g. `../shared.env` or `/etc/passwd`) will be rejected with an error.
|
|
234
|
+
|
|
235
|
+
To intentionally scan a path outside the workspace, pass `--allow-outside`:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
npm run scan -- --file ../shared.env --allow-outside
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
> â ď¸ Outside-workspace scanning is opt-in. Only use it when you explicitly need to scan a file that lives outside the project root.
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
### Web UI
|
|
246
|
+
|
|
247
|
+
Start a local web server and use it in your browser:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Default port 3000
|
|
251
|
+
npx tsx src/cli.ts --web
|
|
252
|
+
|
|
253
|
+
# Custom port
|
|
254
|
+
npx tsx src/cli.ts --web --port 3001
|
|
255
|
+
|
|
256
|
+
# Built version
|
|
257
|
+
node dist/cli.js --web --port 3001
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Open `http://localhost:3001` in your browser, paste content, and press **Scan** or `Ctrl+Enter`.
|
|
261
|
+
|
|
262
|
+
#### REST API
|
|
263
|
+
|
|
264
|
+
You can also call the API directly:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Scan text
|
|
268
|
+
curl -s -X POST http://localhost:3001/scan \
|
|
269
|
+
-H 'Content-Type: application/json' \
|
|
270
|
+
-d '{"content": "sk-proj-abc123 secret_key=test"}' | jq
|
|
271
|
+
|
|
272
|
+
# Response format
|
|
273
|
+
{
|
|
274
|
+
"safe": false,
|
|
275
|
+
"total_findings": 2,
|
|
276
|
+
"findings": [
|
|
277
|
+
{ "type": "API_KEY", "severity": "HIGH", "line": 1, "preview": "****", "description": "OpenAI API Key" }
|
|
278
|
+
],
|
|
279
|
+
"summary": "...",
|
|
280
|
+
"recommendation": "..."
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
| Endpoint | Method | Description |
|
|
285
|
+
|----------|--------|-------------|
|
|
286
|
+
| `/` | GET | Web UI HTML |
|
|
287
|
+
| `/scan` | POST | Scan `{ "content": string }`, returns JSON |
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### OpenCode Plugin (recommended)
|
|
292
|
+
|
|
293
|
+
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. It always enables encoded-content detection. Invalid plugin options or scanner configuration make every protected hook fail closed and abort the model request. A bounded SHA-256 decision cache avoids repeatedly scanning unchanged history without retaining original or redacted content. In transparent mode, schema annotation prose (a `description`/`title` value inside a tool input schema) that trips a scanner rule is masked to a pseudonym token like any other content; identifier positions (tool names, property keys, enum/const values, regex patterns) still refuse the whole request rather than being renamed.
|
|
294
|
+
|
|
295
|
+
The same compiled plugin supports both OpenCode major versions: v2 hosts load the package `id` + `setup(ctx)` definition, while v1 hosts (1.18.29+) call the legacy `server()` factory.
|
|
296
|
+
|
|
297
|
+
**OpenCode v2** â build the project, then point `plugins` at the `dist` directory (or use the package name after publishing to npm):
|
|
298
|
+
|
|
299
|
+
```jsonc
|
|
300
|
+
{
|
|
301
|
+
"$schema": "https://opencode.ai/config.json",
|
|
302
|
+
"plugins": [
|
|
303
|
+
{
|
|
304
|
+
"package": "/absolute/path/to/leakshield/dist"
|
|
305
|
+
// No options: mode defaults to "transparent" on v2.
|
|
306
|
+
// Add "options": { "mode": "block" } to refuse instead of pseudonymize.
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Note that v2 only accepts plugin *directories* (it resolves `dist/index.js`) or package names; a `file://` URL to a single `.js` file is rejected with `configured plugin path must be a directory`.
|
|
313
|
+
|
|
314
|
+
**OpenCode v1 (1.18.29+)** â use the legacy `plugin` array with the compiled plugin file:
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
{
|
|
318
|
+
"plugin": [
|
|
319
|
+
[
|
|
320
|
+
"file:///absolute/path/to/leakshield/dist/opencode.js",
|
|
321
|
+
{ "mode": "block" }
|
|
322
|
+
]
|
|
323
|
+
]
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
The default `mode` depends on the host: **`transparent` on OpenCode v2** (described below) and **`block` on v1**, since transparent is v2-only. `block` replaces unsafe content with a disclosure-free notice; set `"mode": "block"` on v2 to keep that behavior. 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.
|
|
328
|
+
|
|
329
|
+
**OpenCode v2 only â transparent pseudonymization (the v2 default):** omit `mode` or set `"mode": "transparent"` to replace detected sensitive values in model-request snapshots with stable opaque placeholders â category-labelled `[SGP2:<TYPE>-xxxx-xxxx-xxxx]` since W1 (2026-10-07; the legacy `[SGP1:âŚ]` shape stays recognized for restoring pre-upgrade in-session mappings). Reverse mappings are scoped to the OpenCode session and stay in process memory by default; encrypted persistence is opt-in below. Known placeholders are restored in tool inputs before execution and in supported assistant response text. Supported HTTP protocols are selected by URL path shape: Chat Completions, Anthropic Messages, and Responses, including streaming. Native Responses-family WebSocket is also supported as described below. Wire-mode SDKs honoring injected fetch use the same request-scoped HTTP hooks. Hook-only protects content snapshots without transport admission; it does not add adapters for unknown protocols. Transparent mode has been verified against loopback providers and one real OpenAI model; real OS keychains, a real Anthropic provider and long-history replay on other providers are not verified yet ([#26](https://github.com/jwcrystal/leakshield/issues/26)). Routes it cannot protect are refused, not forwarded.
|
|
330
|
+
|
|
331
|
+
**Hook-only for new transparent installs:** use [the hook-first configuration example](config/opencode.hook-first.example.json), which explicitly sets `wireProtection: false`. Content hooks protect system/messages/options/tools and the tool gate restores safe known arguments. SG registers **no outbound HTTP request, WS handshake/send, or AI SDK admission hooks**, does not inspect transport metadata, and does not change provider transport settings. Unknown routes and private SDK transports do not incur SG transport refusals. Optional incoming HTTP/WS hooks restore supported display text using successful preparation for the same session/kind/model; missing hooks or restoration failures leave placeholders literal without disabling input protection. Later-added content or attachments may leave unmasked, even with `attachments: "block"`. The doctor reports `PARTIAL`, not full-wire protection. **Content-hook masking failures still refuse the affected call**, now including a safe `[stage=prepare.mask reason=âŚ]` code; hook-only does not silently forward unprotectable raw content. See [hook-only verification](docs/evidence/2026-10-11-pure-hook-only-verification.md).
|
|
332
|
+
|
|
333
|
+
**Final wire protection:** set `wireProtection: true` to additionally validate/remask the final HTTP request body or supported WS outbound frame content; unknown routes and unknown/mixed body shapes refuse before dispatch. Tool safety and reply-side recovery are identical in both levels. For compatibility, **omitting `wireProtection` retains this stronger legacy behavior**. With the v2 default (`mode: "transparent"`, `wireProtection` omitted) this stronger level is on; only the hook-first example chooses false explicitly. The option is valid only in transparent mode.
|
|
334
|
+
|
|
335
|
+
**AI SDK providers:** with `wireProtection: true`, providers must honor OpenCode's injected `options.fetch`; request-scoped HTTP hooks provide attribution and wire enforcement without a provider-brand allowlist. The wrapper checks HTTP/HTTPS and supported paths; missing/accessor/nonwritable fetch options refuse. With false, SG installs no SDK wrapper and imposes none of those transport requirements; only content/tool hooks and optional ingress restoration apply. Bypass transports are **outside final-wire coverage**, not guaranteed blocked. Commandcode `/alpha/generate`, including Go/403 fallback, is untouched in false and refused in true; there is no legacy response adapter. Arguments, abort signals and real provider failures remain host-owned.
|
|
336
|
+
|
|
337
|
+
In wire mode, the wrapper represents its route/content refusals as a **local HTTP 400 error response**, with `error.code: "leakshield_transport_refusal"` and a content-free WARN. Rejected requests do not reach the network. Hook-only has no such wrapper or transport admission. SDKs can distinguish a refusal from a retryable network failure; genuine network errors, aborts and provider responses remain unchanged. Responses easy-input messages may omit `type: "message"`; recognized roles and supported content are masked without inserting a type into their wire body.
|
|
338
|
+
|
|
339
|
+
**Reply-side recovery in both levels:** SG attribution or JSON/SSE/WS restoration failures stop SG rewriting rather than interrupting the host's response. Unattributed replies stay original; no session/model mapping is guessed. SSE keeps a bounded transaction of undelivered original events, releases them in order on failure, then passes subsequent bytes through without duplicates or dropped tails. Provider error events are released immediately; upstream errors and consumer cancellation still propagate. This can show literal placeholders, and invalid provider data may still fail in OpenCode. Tool arguments still pass the unchanged safety gate. WS can replace only one frame, not replay multiple held channels; see the documented WS limitations and [recovery evidence](docs/evidence/2026-10-11-experience-first-verification.md).
|
|
340
|
+
|
|
341
|
+
**Native WebSocket (experimental, Responses-family):** `/responses` over `ws:`/`wss:` accepts flat `response.create` frames, regardless of provider brand, and restores supported display deltas split across frames. Request masking reuses the HTTP Responses masker; function-call argument frames remain tokenized until the local tool gate, and encrypted reasoning stays opaque. Continuation IDs are preserved, not remasked. Different dialects/extensions are not automatically supported. OpenCode exposes no connection ID: state is isolated by session, request kind and model, then response ID and content channel. New handshakes/model switches, HTTP fallback, rejected frames and disposal invalidate old state; terminal frames release buffers. Frames, channels and aggregate buffering are bounded. A provider that omits the final text delta leaves a static warning: the complete `.done` text is restored without replacing that event with a synthetic delta, so delta-only consumers may show an incomplete reply. Unknown display tokens remain literal; unsafe or unknown write-tool mappings still refuse. The existing native OpenAI HTTP preference is retained for compatibility; explicit WS settings now work on supported routes. This is not a system network firewall or support for every WS provider. See [verification and limitations](docs/evidence/2026-10-11-responses-ws-verification.md).
|
|
342
|
+
|
|
343
|
+
**Shell argument restoration:** on macOS/Linux POSIX shells, a known placeholder may occupy a complete unquoted, single-quoted, or double-quoted argument. Existing quotes are preserved, and originals must be safe in that quote context; quoted space-containing values remain one argument. A single trailing `>`/`>>` redirect to a static literal filename is supported. Command/assignment positions, tokenized redirect filenames, expansions, quote concatenation, pipelines, inline scripts, quote-breaking originals, and leading-option values still refuse the affected tool call before mutation. Token-free commands are unchanged. The new quoting/redirect support is not enabled on Windows; it is not a general shell parser. Neither `wireProtection` setting changes this tool gate.
|
|
344
|
+
|
|
345
|
+
**Opt-in mapping persistence (W2, 2026-10-07):** set `"persistence": { "enabled": true }` in transparent mode to survive restarts â mappings persist encrypted (per-entry AES-256-GCM, AAD-bound) in a SQLite store (default `~/.local/share/leakshield/SGP.db`) and rehydrate on a session's first touch, so previously saved placeholders in resumed sessions keep restoring. Requires Node.js 22.13+ (built-in `node:sqlite`); on an older runtime the store cannot open and mappings stay memory-only with a WARN. Options: `ttlDays` (default 7; 0 = manual erasure only), `path` (store location), `keyFile`/`keyfilePath` (weaker fallback when no OS keychain exists). Key custody resolves down a ladder â OS keychain (macOS Keychain / Windows DPAPI / Linux libsecret) â explicit keyfile â memory-only degrade. Runtime logs report `persistence: active; key=os-keychain|keyfile` when the store opens successfully; later degradation emits a WARN. Missing keys do not directly refuse conversations, but an unsaved old token can still fail the tool gate. `--doctor` reports configuration/store readability as **unverified**, not runtime activation or decryptability, and never touches the real keychain. TTL cleanup runs when a writer opens the store, not on a timer; saving a changed mapping snapshot extends expiry, while reads do not. Seven days is not a hard deletion deadline. Persistence cannot recover mappings already lost before activation. Active erasure: `leakshield --forget --all` (or `--session <id>`) deletes persisted mappings, counts only in output. Erasure is logical plus in-file best effort (`secure_delete` zeroes freed pages, `forget --all` also vacuums and truncates the WAL); physical-media and backup residue (SSD wear leveling, snapshots, restores) are out of scope. Switching the key source after enabling (keychain â keyfile) refuses to open the store â it degrades memory-only until `forget --all` resets â rather than silently re-keying history.
|
|
346
|
+
|
|
347
|
+
**Persistence risk notes (read before enabling):** the design is dual-secret â the DB file alone or the key alone exposes nothing; both together do. 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. 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. 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.
|
|
348
|
+
|
|
349
|
+
**Restart limitation in both levels:** replayed originals can establish new mappings, but old tokens cannot be reconstructed from token text. Some provider tool-call arguments remain tokenized when published to history, even though the local execution gate restores them before execution. Thus complete token-free history and seamless restart recovery are not established; an unresolved write/execute argument still refuses with no side effects. Local originals may remain in history, logs, and generated files â this protects the model boundary, not your disk.
|
|
350
|
+
|
|
351
|
+
**Transparent capacity and lifecycle:** the guard uses an 8 Mi UTF-16-unit combined input/output budget and 100,000 value nodes per protect/restore operation, rather than applying the standalone core's 1 Mi-unit budget to an entire history. HTTP bodies and WS frames retain their 4 MiB limits; scanner `max_chars`, depth 32, mapping-entry and aggregate mapping-memory caps remain enforced. Up to 4,096 sessions can be retained per guard instance; live mappings are never LRU-evicted to admit another session. The public V2 `session.deleted` event releases only that session's RAM, prepared-response proof and WS buffers. Idle, completed and interrupted sessions retain mappings for resume. Missing/failed lifecycle subscriptions retain mappings until unload, so capacity remains finite, not an unlimited-lifetime guarantee. Deletion does not erase encrypted persisted rows: TTL/explicit `forget` remain their retention policy. [Local verification and remaining live-test gap](docs/evidence/2026-10-14-transparent-capacity-verification.md).
|
|
352
|
+
|
|
353
|
+
**Native OpenAI transport:** wire mode retains an HTTP preference for native OpenAI providers; explicit provider configuration has higher precedence. Hook-only makes no provider transport transformation. Supported Responses-family WS ingress can restore display deltas without SG handshake/send registrations, starting from a validated `response.created` in a prepared session/kind/model scope. No endpoint, credential, or persisted configuration is changed. Real subscription authentication and complete restart recovery remain separate from local capture evidence.
|
|
354
|
+
|
|
355
|
+
**OpenCode v2 only â email de-identification trial:** the opt-in `deidentify` option (valid only together with `mode: "redact"`) additionally replaces repeated MEDIUM email findings with stable, opaque `[SG-EMAIL-âŚ]` placeholders so an agent can correlate records without seeing the addresses. The mapping key is generated once per plugin setup (one OpenCode session), held in memory only, and never persisted â placeholders are stable within a live session but change after a restart, and no reverse mapping exists. Everything else keeps its existing disposition: HIGH credentials are still redacted/blocked, and truncated, encoded, or unverifiable content blocks the whole unit.
|
|
356
|
+
|
|
357
|
+
```jsonc
|
|
358
|
+
{ "package": "/absolute/path/to/leakshield/dist", "options": { "mode": "redact", "deidentify": true } }
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Opt-in readonly env queries (both versions):** the `envQueries` option (default `false`) exposes three read-only tools over the files listed in `settings.env_files`, so an agent can answer configuration questions without ever seeing values. It does not work with transparent mode, so on v2 set `mode` to `block` or `redact` explicitly:
|
|
362
|
+
|
|
363
|
+
| Tool | Contract |
|
|
364
|
+
|---|---|
|
|
365
|
+
| `guard_env_list` | Opaque session-local file ids plus key names â never paths, values, lengths, or previews. |
|
|
366
|
+
| `guard_env_inspect(file_id, key)` | `missing` \| `empty` \| `nonempty`; when nonempty, a coarse lexical shape `boolean_like` \| `number_like` \| `multiline_text` \| `text`. A shape is a lexical hint, never a claim the value is a valid boolean or number. |
|
|
367
|
+
| `guard_env_compare(left_file_id, left_key, right_file_id, right_key)` | `equal` \| `different` \| `unavailable` for key-to-key, same- or cross-file equality. Missing keys and unreadable files are `unavailable`. |
|
|
368
|
+
|
|
369
|
+
```jsonc
|
|
370
|
+
{ "package": "/absolute/path/to/leakshield/dist", "options": { "mode": "block", "envQueries": true } }
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Ground rules: only `settings.env_files` entries are queryable (at most 16 files, 1 MiB each). File ids are only valid in the session that listed them. Files are re-read on every call, and a comparison reads both operands in one per-call snapshot. Raw values, value lengths, previews, fingerprints, and reverse mappings never appear in any output. If the guard configuration file changes after setup, the tools return a fixed restart-required error until OpenCode restarts â they never silently fall back to the old or new authorization.
|
|
374
|
+
|
|
375
|
+
File access is best-effort pathname identity validation, not a sandbox. The workspace root is frozen at setup (resolved path plus device/inode identity); every query re-stats the root and each ancestor directory before opening and again after reading, rejects symlinks on any path component â including ancestor directories that resolve elsewhere, even inside the workspace â requires regular files, opens the fully resolved canonical path with `O_NOFOLLOW` and `O_NONBLOCK`, and binds the opened descriptor to the statted inode with pre- and post-read size and mtime checks. Limitations, stated honestly: malicious concurrent filesystem mutation by the same owner is outside this threat model â a substitution that is reverted between two checks (an ABA race on the root, an ancestor directory, or the file) is not detectable by pathname checks, hardlinks are not distinguished from the original file (provenance is not checked), in-place rewrites that preserve size and mtime are not distinguishable, and the agent can modify env files through other tools â so results describe the current file state, not a trusted baseline. Key names themselves are returned as-is and pass through the normal output/history protection. On OpenCode v1 the tools are registered through the standard v1 tool API (`@opencode-ai/plugin`), which the v1 host provides.
|
|
376
|
+
|
|
377
|
+
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 above; 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.
|
|
378
|
+
|
|
379
|
+
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.
|
|
380
|
+
|
|
381
|
+
#### Isolated smoke test (OpenCode v2)
|
|
382
|
+
|
|
383
|
+
Run this from the project root. It uses a temporary working directory and a synthetic value, not a real credential:
|
|
384
|
+
|
|
385
|
+
```bash
|
|
386
|
+
npm run build
|
|
387
|
+
SMOKE_DIR="$(mktemp -d)"
|
|
388
|
+
PROJECT_DIR="$(pwd)"
|
|
389
|
+
cat > "$SMOKE_DIR/opencode.json" <<EOF
|
|
390
|
+
{
|
|
391
|
+
"$schema": "https://opencode.ai/config.json",
|
|
392
|
+
"plugins": [
|
|
393
|
+
{ "package": "$PROJECT_DIR/dist", "options": { "mode": "block" } }
|
|
394
|
+
]
|
|
395
|
+
}
|
|
396
|
+
EOF
|
|
397
|
+
(cd "$SMOKE_DIR" && opencode run --standalone \
|
|
398
|
+
"Smoke test only. Do not reveal or use this token: sk-AAAAAAAAAAAAAAAAAAAA")
|
|
399
|
+
rm -rf "$SMOKE_DIR"
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
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.
|
|
403
|
+
|
|
404
|
+
After publishing to npm, the same plugin can be configured as `"leakshield"` instead of the local `dist` path.
|
|
405
|
+
|
|
406
|
+
#### Automated install check: `--doctor`
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
npm run scan -- --doctor # or: leakshield --doctor after global install
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
The doctor verifies the install without sending anything anywhere: it checks the OpenCode host version, finds `opencode.json` (workspace then global), confirms LeakShield is registered with options that the plugin itself would accept, verifies a local `dist` entry point actually exists (a missing one makes OpenCode silently log-and-skip the plugin â sessions look normal but are unprotected), loads the guard config, and runs the synthetic-canary smoke scan locally. Exit code 0 means `PROTECTED` (v2) or `PARTIAL` (v1: session hooks only); any other status prints the failing check with a concrete fix, including a copy-paste registration snippet when the plugin is missing.
|
|
413
|
+
|
|
414
|
+
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`.
|
|
415
|
+
|
|
416
|
+
### What this protects â and what it does not
|
|
417
|
+
|
|
418
|
+
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.
|
|
419
|
+
|
|
420
|
+
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).
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## Configuration
|
|
425
|
+
|
|
426
|
+
Edit `config/guard.config.yaml`:
|
|
427
|
+
|
|
428
|
+
### Exact `.env` Value Detection
|
|
429
|
+
|
|
430
|
+
Enable this only for files whose values should never enter an LLM context:
|
|
431
|
+
|
|
432
|
+
```yaml
|
|
433
|
+
settings:
|
|
434
|
+
env_files:
|
|
435
|
+
- .env
|
|
436
|
+
- .env.local
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
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 OpenCode Plugin) query these same files and never return their values.
|
|
440
|
+
|
|
441
|
+
```yaml
|
|
442
|
+
# NDA keywords (case-insensitive)
|
|
443
|
+
nda_keywords:
|
|
444
|
+
- "CONFIDENTIAL"
|
|
445
|
+
- "INTERNAL ONLY"
|
|
446
|
+
- "DO NOT SHARE"
|
|
447
|
+
- "NDA"
|
|
448
|
+
- "PROPRIETARY"
|
|
449
|
+
# Add your own internal keywords:
|
|
450
|
+
# - "Project Phoenix"
|
|
451
|
+
# - "MyCompany Internal"
|
|
452
|
+
|
|
453
|
+
# Private domains
|
|
454
|
+
private_domains:
|
|
455
|
+
- "internal.mycompany.com"
|
|
456
|
+
# - "dev.yourcompany.io"
|
|
457
|
+
|
|
458
|
+
settings:
|
|
459
|
+
max_chars: 200000 # Truncate if exceeded to avoid long scans
|
|
460
|
+
show_line_numbers: true
|
|
461
|
+
preview_length: 60
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
After editing:
|
|
465
|
+
- **CLI**: Reloaded automatically on next run
|
|
466
|
+
- **OpenCode Plugin**: Restart OpenCode to reload the plugin configuration
|
|
467
|
+
- **Web UI**: Restart the local server
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## Practical Examples
|
|
472
|
+
|
|
473
|
+
### Scenario 1: Asking OpenCode to review a config file
|
|
474
|
+
|
|
475
|
+
```
|
|
476
|
+
You (to OpenCode): Please review this config.ts for issues
|
|
477
|
+
OpenCode: [reads config.ts]
|
|
478
|
+
â Tool output contains an API_KEY
|
|
479
|
+
â Plugin replaces it before the next model turn
|
|
480
|
+
â OpenCode receives a block notice instead of the secret
|
|
481
|
+
You: Replace line 12 with a dummy key, then continue
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Scenario 2: CLI scan before submitting a project
|
|
485
|
+
|
|
486
|
+
```bash
|
|
487
|
+
npm run scan -- --dir ./my-project
|
|
488
|
+
# If exit code = 1, there are findings â fix them before sharing with AI
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### Scenario 3: CI/CD integration (block sensitive prompts from the pipeline)
|
|
492
|
+
|
|
493
|
+
```bash
|
|
494
|
+
# Add to your CI script
|
|
495
|
+
node dist/cli.js --cli --dir ./prompts
|
|
496
|
+
if [ $? -ne 0 ]; then
|
|
497
|
+
echo "â Sensitive content detected â stopping pipeline"
|
|
498
|
+
exit 1
|
|
499
|
+
fi
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## Configuration Validation
|
|
505
|
+
|
|
506
|
+
Input lengths for dynamic rules are validated when the config is loaded:
|
|
507
|
+
|
|
508
|
+
| Field | Max length |
|
|
509
|
+
|-------|-----------|
|
|
510
|
+
| `nda_keywords` entries | 200 characters |
|
|
511
|
+
| `private_domains` entries | 255 characters |
|
|
512
|
+
|
|
513
|
+
Values exceeding these limits will cause `loadConfig()` to throw a Zod validation error, preventing oversized patterns from entering the scanner.
|
|
514
|
+
|
|
515
|
+
## Secret Preview Behavior
|
|
516
|
+
|
|
517
|
+
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.
|
|
518
|
+
|
|
519
|
+
## Internationalization (i18n)
|
|
520
|
+
|
|
521
|
+
CLI output language is controlled by the `LEAKSHIELD_LANG` environment variable.
|
|
522
|
+
|
|
523
|
+
| Value | Language |
|
|
524
|
+
|-------|----------|
|
|
525
|
+
| `en` (default) | English |
|
|
526
|
+
| `zh-TW` or `zh` | Traditional Chinese |
|
|
527
|
+
|
|
528
|
+
```bash
|
|
529
|
+
# English output (default)
|
|
530
|
+
npm run scan -- --text "your content"
|
|
531
|
+
|
|
532
|
+
# Traditional Chinese output
|
|
533
|
+
LEAKSHIELD_LANG=zh-TW npm run scan -- --text "ä˝ çĺ
§ĺŽš"
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
You can also set it persistently in your shell profile:
|
|
537
|
+
|
|
538
|
+
```bash
|
|
539
|
+
export LEAKSHIELD_LANG=zh-TW
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
## Notes
|
|
543
|
+
|
|
544
|
+
- This tool performs **static pattern matching** and cannot guarantee 100% coverage
|
|
545
|
+
- **Common false positives**: test/dummy keys (e.g. `sk-test123456`), placeholder values in example code
|
|
546
|
+
- The tool is meant to **warn**, not guarantee â final judgment is always yours
|
|
547
|
+
- Keep NDA keywords focused on truly confidential terms to avoid excessive false positives
|