dsh-privacy-gateway 0.1.8 → 0.2.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/README.en.md +18 -15
- package/README.md +18 -15
- package/docs/assets/screenshots/0-banner-en.png +0 -0
- package/docs/details/DETAIL.en.md +3 -3
- package/docs/details/DETAIL.md +3 -3
- package/lib/client.js +7 -6
- package/lib/index.d.ts +12 -4
- package/lib/index.js +206 -76
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -3
package/README.en.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[简体中文](README.md) | English
|
|
4
4
|
|
|
5
|
-

|
|
6
6
|
|
|
7
|
-
A redaction gateway on the host process's undici global dispatcher. Secrets in outgoing model request bodies are replaced with placeholders
|
|
7
|
+
A redaction gateway on the host process's undici global dispatcher. Secrets in outgoing model request bodies are replaced with placeholders; by default the placeholders in the replies go into the session log as they are, so no plaintext reaches it, and `restoreLog` puts them back with the real values on request. Adapters and providers don't notice it; by default the agent gets placeholders, and with `restoreLog` on it gets the real values as before. One interception point covers every provider that goes through `fetch()`, including adapters that plugins provide.
|
|
8
8
|
|
|
9
9
|
If you are using an **API relay**, or you are working with **sensitive information** or **production data**, please be sure to protect information security.
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@ If you are using an **API relay**, or you are working with **sensitive informati
|
|
|
15
15
|
dsh plugin --profile web add dsh-privacy-gateway@latest
|
|
16
16
|
|
|
17
17
|
# The same version as a GitHub Release asset (prereleases get one too)
|
|
18
|
-
dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.
|
|
18
|
+
dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.2.0/dsh-privacy-gateway-0.2.0.tgz
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
A prerelease version has a `-` in it and goes to GitHub Releases only, never to npm. The repository does not commit `lib/`, so `dsh plugin add github:…` cannot load the plugin ([ADR-0006](docs/adr/0006-distribution-and-build-artifacts.md)).
|
|
@@ -26,6 +26,7 @@ In the default web profile the first install works at once, with no restart of t
|
|
|
26
26
|
|
|
27
27
|
- **What is masked**: keys, tokens, passwords, private keys, cookies, email addresses, phone numbers, ID card and bank card numbers, and your own words — each with its own switch.
|
|
28
28
|
- **Actions**: pick `mask` / `warn` / `block` per kind; a key can be sent as a made-up key of its own form (`shape`).
|
|
29
|
+
- **No plaintext in the session log**: restore is off by default, so a reply's placeholders go into the session log as they are; turn `restoreLog` on to put the real values back, and the agent gets them too.
|
|
29
30
|
- **Records and statistics**: records written to disk by the day, a statistics card, and the session's 「隐私保护」 (Privacy) tab; a record holds placeholders, never a value.
|
|
30
31
|
- **The `/privacy` command**: status, a temporary on / off, and `test` to preview how a text would go out.
|
|
31
32
|
- **Live configuration**: everyday items are changed on the plugin page and apply from the next call; when masking fails, the request is not sent.
|
|
@@ -42,9 +43,9 @@ In the default web profile the first install works at once, with no restart of t
|
|
|
42
43
|
| `EMAIL` / `PHONE` / `ID_CARD` / `BANK_CARD` | Email addresses, mainland China mobile numbers, ID card numbers (check digit), bank card numbers (Luhn) | `personal` |
|
|
43
44
|
| `TERM` | The words listed in the `words` config | whenever there are words |
|
|
44
45
|
|
|
45
|
-
A value masked once is masked with the same placeholder wherever else the request has it (its finder is `known`). History sent to the same host again keeps the bytes it went with before, so the prompt cache still hits.
|
|
46
|
+
A value masked once is masked with the same placeholder wherever else the request has it (its finder is `known`), `url` / `image_url` included; a signed URL (an S3 presigned one, say) goes as it is, since masking one character breaks it ([ADR-0004](docs/adr/0004-protected-regions.md)). History sent to the same host again keeps the bytes it went with before, so the prompt cache still hits.
|
|
46
47
|
|
|
47
|
-
To try it: every line below is a **fake** value; paste one into a session and the matching record on the card shows the placeholder it became. Neither the records, the stats
|
|
48
|
+
To try it: every line below is a **fake** value; paste one into a session and the matching record on the card shows the placeholder it became. Neither the records, the stats nor the vendorView copy holds the value, just the placeholder and a few characters at each end; the session log holds no value either while `restoreLog` is off (the default), and does once it is on ([ADR-0003](docs/adr/0003-restore-before-session-log.md)).
|
|
48
49
|
|
|
49
50
|
```text
|
|
50
51
|
sk-proj-Zq7Lr2Vt9mK1Px3aB5cD8eF0gH4jN6wY → API_KEY
|
|
@@ -69,7 +70,7 @@ someone@gmail.com → EMAIL
|
|
|
69
70
|
- A secret shorter than 8 characters (`abc123`, `666666`, `888888`: a short password) is no value: it goes as written and makes no record. It is guessed in no time, so masking it only promises a protection that is not there — and the value table never matched anything that short as known anyway ([ADR-0031](docs/adr/0031-no-short-or-template-values.md)).
|
|
70
71
|
- A value typed to stand for a key is no value: eight or more of one character in a row (`sk-proj-xxxx…`, `AKIA0000…`), or one that says what it is (`your_api_key`, `example`, `changeme`, `placeholder`, `dummy`, `***`). A random key has such a run with a chance below one in a billion, and a vendor's real test key (`sk_test_…`) is still masked ([ADR-0031](docs/adr/0031-no-short-or-template-values.md)).
|
|
71
72
|
- The name of a cryptographic algorithm is no value: names like `SCRAM-SHA-512` and `PBKDF2WithHmacSHA256` are published in a spec for anyone to read, so masking one hides nothing; they go as they are ([ADR-0033](docs/adr/0033-algorithm-names.md)).
|
|
72
|
-
- A key is masked the way a value is: the key in `{"metadata": {"sk-…": …}}` goes as a placeholder and comes back in the reply. The protocol's own keys (`model`, `role`, `type`, `name`, `id` and so on), the tool definitions and a tool call's argument names are never touched ([ADR-0029](docs/adr/0029-mask-json-keys.md)).
|
|
73
|
+
- A key is masked the way a value is: the key in `{"metadata": {"sk-…": …}}` goes as a placeholder and comes back in the reply when `restoreLog` is on. The protocol's own keys (`model`, `role`, `type`, `name`, `id` and so on), the tool definitions and a tool call's argument names are never touched ([ADR-0029](docs/adr/0029-mask-json-keys.md)).
|
|
73
74
|
|
|
74
75
|
## Screens
|
|
75
76
|
|
|
@@ -81,7 +82,7 @@ The screenshots show the Chinese interface.
|
|
|
81
82
|
|
|
82
83
|
## Configuration
|
|
83
84
|
|
|
84
|
-
The everyday settings can be changed on the Configure page of this plugin's row on the plugin page: `enabled`, `secrets`, `personal`, `shape`, `toolGuard`, `maskKeys`, `words`, `allow`, `record`, `keepDays`, `recordContext`, `vendorView`, `showPanel`, `excludeProviders`. A change is saved at once and applies from the next model call, with no restart ([ADR-0021](docs/adr/0021-live-settings.md)). The others are changed in the profile's `~/.dsh/profiles/<profile>/cordis.patch.yml`, under `config` of the `id: dsh-privacy-gateway` row; the `cordis.patch.yml` shipped in the package is replaced on upgrade, so do not edit it.
|
|
85
|
+
The everyday settings can be changed on the Configure page of this plugin's row on the plugin page: `enabled`, `secrets`, `personal`, `shape`, `toolGuard`, `restoreLog`, `maskKeys`, `words`, `allow`, `record`, `keepDays`, `recordContext`, `vendorView`, `showPanel`, `excludeProviders`. A change is saved at once and applies from the next model call, with no restart ([ADR-0021](docs/adr/0021-live-settings.md)). The others are changed in the profile's `~/.dsh/profiles/<profile>/cordis.patch.yml`, under `config` of the `id: dsh-privacy-gateway` row; the `cordis.patch.yml` shipped in the package is replaced on upgrade, so do not edit it.
|
|
85
86
|
|
|
86
87
|
| Key | Default | Description |
|
|
87
88
|
| --- | --- | --- |
|
|
@@ -92,11 +93,12 @@ The everyday settings can be changed on the Configure page of this plugin's row
|
|
|
92
93
|
| `allow` | `[]` | Values never masked: whole values, in any case |
|
|
93
94
|
| `actions` | `{}` | An action per kind: `mask` (the default, a placeholder), `warn` (sent as written and recorded) or `block` (the whole request is not sent). For example `{ PRIVATE_KEY: block, EMAIL: warn }` ([ADR-0013](docs/adr/0013-actions.md)) |
|
|
94
95
|
| `maskKeys` | `true` | A **JSON key** that reads like a secret or personal data goes as a placeholder too (`{"sk-…": …}`). The protocol's own keys (`model`, `role`, `type`, `name`, `id` and so on), the tool definitions and a tool call's argument names are never touched, or the vendor could not read the request. When off, such keys go as they are ([ADR-0029](docs/adr/0029-mask-json-keys.md)) |
|
|
95
|
-
| `toolGuard` | `off` | When a tool call's arguments would have a value restored and name a host off this machine: `off` only counts it, `warn` logs and records it, `block` leaves the placeholders in that call's arguments, so the tool gets the placeholder ([ADR-0014](docs/adr/0014-tool-guard.md)) |
|
|
96
|
-
| `
|
|
96
|
+
| `toolGuard` | `off` | When a tool call's arguments would have a value restored and name a host off this machine: `off` only counts it, `warn` logs and records it, `block` leaves the placeholders in that call's arguments, so the tool gets the placeholder. A reply holds a restored value only with `restoreLog` on; with it off this guard never runs ([ADR-0014](docs/adr/0014-tool-guard.md)) |
|
|
97
|
+
| `restoreLog` | `false` | Whether a reply's placeholders are put back before the session log is written. Off (the default): the placeholders go into the log as they are, no plaintext reaches it, and the agent sees placeholders too; on, the log and the agent both hold the real values, and session sync, backups, shares and exports carry them too ([ADR-0003](docs/adr/0003-restore-before-session-log.md)) |
|
|
98
|
+
| `shape` | `false` | Send a key as a made-up key of its own form (same prefix, length and kinds of character) instead of a `{{…}}` placeholder; a value under 8 characters, or holding anything but letters, digits, `-`, `_` and `.`, keeps the placeholder; with `restoreLog` on, replies put it back the same way ([ADR-0015](docs/adr/0015-shape.md)) |
|
|
97
99
|
| `cookieNames` | `[]` | More cookie names to mask |
|
|
98
100
|
| `cookieKeep` | `['lang', 'locale', 'theme', 'tz']` | Cookie names never masked |
|
|
99
|
-
| `protectEnvBlock` | `true` | Send `<env>` … `</env>` blocks as written, for providers that check them ([ADR-0004](docs/adr/0004-protected-regions.md)) |
|
|
101
|
+
| `protectEnvBlock` | `true` | Send `<env>` … `</env>` blocks as written, for providers that check them; only in text the host writes (the system prompt, `system`, `instructions`, `systemInstruction`), never in a user message or a tool result ([ADR-0004](docs/adr/0004-protected-regions.md) supplement) |
|
|
100
102
|
| `protectTools` | `true` | Send the request's `tools` array as written |
|
|
101
103
|
| `excludeHosts` | `[]` | `host` or `host:port` entries that are never rewritten |
|
|
102
104
|
| `excludeProviders` | `[]` | Provider ids whose requests are not masked; checked on the Configure page from the providers registered now. Their requests go out as they are, replies are not restored, nothing is recorded, and the log says so once for each provider ([ADR-0018](docs/adr/0018-exclude-providers.md), [ADR-0034](docs/adr/0034-log-excluded-provider.md)) |
|
|
@@ -122,7 +124,7 @@ No answer of the command has a value in it.
|
|
|
122
124
|
|
|
123
125
|
## Records and statistics
|
|
124
126
|
|
|
125
|
-
Only a model request that had something masked or restored makes a record, one each: its time and duration, host, model, session with its workspace and title, places replaced, each value's placeholder / kind / finder / head / length / every place it was at, the turn and step the request went out in, the turn and step the value was first sent in this run, the places restored in the reply (those in tool arguments counted apart), and the placeholders the value table does not know. A record never holds a value, nor a URL's query ([ADR-0008](docs/adr/0008-masking-records.md), [ADR-0020](docs/adr/0020-record-attribution.md)).
|
|
127
|
+
Only a model request that had something masked or restored makes a record (with `restoreLog` off nothing is restored, so only a masked one does), one each: its time and duration, host, model, session with its workspace and title, places replaced, each value's placeholder / kind / finder / head / length / every place it was at (up to 8 per value, the rest counted), the turn and step the request went out in, the turn and step the value was first sent in this run, the places restored in the reply (those in tool arguments counted apart; always 0 with `restoreLog` off), and the placeholders the value table does not know. A record never holds a value, nor a URL's query ([ADR-0008](docs/adr/0008-masking-records.md), [ADR-0020](docs/adr/0020-record-attribution.md)).
|
|
126
128
|
|
|
127
129
|
The head keeps a few characters to recognize it by: a key with a prefix keeps the prefix and the 4 characters after it, one without keeps its first 4, and a long value also keeps its last 2 (`sk-proj-g6sx…3QaZ`); shorter values keep fewer, and personal data and your words keep one ([ADR-0019](docs/adr/0019-hint.md)).
|
|
128
130
|
|
|
@@ -134,11 +136,12 @@ With `vendorView` on (「保留发出内容,供对照查看」 on the config p
|
|
|
134
136
|
|
|
135
137
|
## Notes
|
|
136
138
|
|
|
137
|
-
-
|
|
138
|
-
-
|
|
139
|
-
-
|
|
139
|
+
- Upgrading from 0.1.x: replies are no longer restored by default, so the agent gets placeholders. For the old behaviour (the agent and the log both hold the real values), turn `restoreLog` on in the config page.
|
|
140
|
+
- By default the session log holds placeholders: with `restoreLog` off (the default), a reply's placeholders go into the log as they are, no plaintext reaches it, and the agent sees placeholders too; with it on, replies are restored before the log is written, so the log and the agent both hold the real values, and session sync, backups, shares and exports carry them too ([ADR-0003](docs/adr/0003-restore-before-session-log.md)).
|
|
141
|
+
- Only traffic through the global `fetch()` is covered; direct `node:http`, worker threads and separate processes bypass the gateway ([ADR-0001](docs/adr/0001-intercept-at-undici-global-dispatcher.md)). Only JSON model requests it recognizes are rewritten (array `messages`, array or string `input`, `contents`, string `prompt`); multipart, forms and non-JSON bodies go as written and leave no record ([ADR-0001](docs/adr/0001-intercept-at-undici-global-dispatcher.md)).
|
|
142
|
+
- Compressed requests are decompressed before they are masked; with `restoreLog` on, a compressed reply is decoded before it is restored, and with it off the reply passes through the gateway compressed, so an adapter reading it with `undici.request` must decompress it itself (`fetch` does it for the caller). A request's `content-encoding` with no decoder fails the request ([ADR-0025](docs/adr/0025-compression-and-upgrades.md)). An upgrade (the WebSocket handshake) or a `CONNECT` tunnel inside a model call is refused as well: Codex falls back to SSE the first time and takes SSE from then on in that session. One opened by a plugin outside a model call (dsh-im-infoflow's inbound, say) is let through, its messages unmasked, with one warning per host ([ADR-0032](docs/adr/0032-upgrade-scoped-to-masked-calls.md)) — a fail-closed to fail-open trade whose cost the ADR records; a host that needs a transparent link can still go into `excludeHosts`.
|
|
140
143
|
- The value table is in memory only ([ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md)). After a restart, a value no rule finds, masked only because it was remembered, goes as written the first time it is sent again.
|
|
141
|
-
-
|
|
144
|
+
- With `restoreLog` on, replies are restored everywhere, tool call arguments included: a model led into writing a placeholder into a command such as `curl` runs the tool with the real value. The plugin counts these places (the tool-argument count on the card and in `/privacy status`) and does not block them ([ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md)); with it off, no reply holds a real value and this path does not exist.
|
|
142
145
|
- When masking fails, the request is not sent and fails with `dsh-privacy-gateway: masking failed, request not sent` ([ADR-0005](docs/adr/0005-fail-closed.md)). To recover, run `/privacy off`, or disable the plugin on the Plugins page or set `enabled` to `false`.
|
|
143
146
|
|
|
144
147
|
## Development
|
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.en.md) | 简体中文
|
|
4
4
|
|
|
5
|
-

|
|
6
6
|
|
|
7
|
-
在宿主进程的 undici 全局 dispatcher
|
|
7
|
+
在宿主进程的 undici 全局 dispatcher 上装一层脱敏网关。出站把模型请求体里的密钥换成占位符;入站默认让回流里的占位符原样进会话日志,明文不进日志,打开 `restoreLog` 才换回真值。对 adapter、provider 无感;agent 在默认关闭时拿到的是占位符,打开 `restoreLog` 后与以前一样拿到真值。一处拦截覆盖所有走 `fetch()` 的 provider,包括插件提供的 adapter。
|
|
8
8
|
|
|
9
9
|
如果你在用**中转站**或者在处理**敏感信息**、**线上数据**,请务必注意保护信息安全。
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
dsh plugin --profile web add dsh-privacy-gateway@latest
|
|
16
16
|
|
|
17
17
|
# 同一版本的 GitHub Release 附件(预发布也发在这里)
|
|
18
|
-
dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.
|
|
18
|
+
dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.2.0/dsh-privacy-gateway-0.2.0.tgz
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
预发布版本号带 `-`,只发 GitHub Release、不发 npm。仓库不提交 `lib/`,`dsh plugin add github:…` 拿到的树加载不了([ADR-0006](docs/adr/0006-distribution-and-build-artifacts.md))。
|
|
@@ -26,6 +26,7 @@ dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/rele
|
|
|
26
26
|
|
|
27
27
|
- **脱敏范围**:密钥、token、密码、私钥、cookie、邮箱、手机号、身份证、银行卡、自定义敏感词,各有开关。
|
|
28
28
|
- **动作可选**:按 kind 选 `mask` / `warn` / `block`,密钥可换成同形的假 key(`shape`)。
|
|
29
|
+
- **日志不写真值**:默认不还原,回复里的占位符原样进会话日志,明文不进日志;打开 `restoreLog` 才把真值写回,agent 同时拿到真值。
|
|
29
30
|
- **记录与统计**:按天落盘的脱敏记录、统计卡、会话「隐私保护」标签页;记录里只有占位符,没有真值。
|
|
30
31
|
- **`/privacy` 命令**:查状态、临时开关、`test` 预览一段文本会怎样发出。
|
|
31
32
|
- **配置热更新**:日常项在插件页上改,下一次调用即生效;脱敏出错时请求不发出。
|
|
@@ -42,9 +43,9 @@ dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/rele
|
|
|
42
43
|
| `EMAIL` / `PHONE` / `ID_CARD` / `BANK_CARD` | 邮箱、大陆手机号、身份证号(校验位)、银行卡号(Luhn) | `personal` |
|
|
43
44
|
| `TERM` | 配置里 `words` 列出的词 | 有词就脱敏 |
|
|
44
45
|
|
|
45
|
-
脱敏过的值在请求的其它地方再出现,也按同一个占位符脱敏(finder 记为 `known
|
|
46
|
+
脱敏过的值在请求的其它地方再出现,也按同一个占位符脱敏(finder 记为 `known`),`url` / `image_url` 里的也算;带签名的 URL(S3 预签名等)原样发出,改了会失效([ADR-0004](docs/adr/0004-protected-regions.md))。同一个 host 重发的历史保持原来的字节,prompt cache 照样命中。
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
照着试:下面每行都是**假值**,复制进会话发出去,统计卡的对应记录里就会出现替换后的占位符。记录、统计和 vendorView 副本里都没有原值;会话日志在 `restoreLog` 关闭(默认)时也没有,只有占位符,打开后才有真值([ADR-0003](docs/adr/0003-restore-before-session-log.md))。
|
|
48
49
|
|
|
49
50
|
```text
|
|
50
51
|
sk-proj-Zq7Lr2Vt9mK1Px3aB5cD8eF0gH4jN6wY → API_KEY
|
|
@@ -69,7 +70,7 @@ someone@gmail.com → EMAIL
|
|
|
69
70
|
- 短于 8 个字符的秘密(`abc123`、`666666`、`888888` 这类口令)不算值:照原样发出,也不进记录。它们随时能被爆破,遮住只是给人一种并不存在的保护;值表本来也不把这么短的值当作已知值([ADR-0031](docs/adr/0031-no-short-or-template-values.md))。
|
|
70
71
|
- 明显是占位写法的值不算值:8 个以上相同字符连排(`sk-proj-xxxx…`、`AKIA0000…`),或自带「这是占位」说明(`your_api_key`、`example`、`changeme`、`placeholder`、`dummy`、`***`)。随机 key 出现 8 连排的概率低于十亿分之一,`sk_test_…` 这种真测试 key 照旧脱敏([ADR-0031](docs/adr/0031-no-short-or-template-values.md))。
|
|
71
72
|
- 加密算法的名字不算值:`SCRAM-SHA-512`、`PBKDF2WithHmacSHA256` 这类名字写在规范里、人人可读,遮住什么都不保护,原样发出([ADR-0033](docs/adr/0033-algorithm-names.md))。
|
|
72
|
-
- 键名和值一样脱敏:`{"metadata": {"sk-…": …}}`
|
|
73
|
+
- 键名和值一样脱敏:`{"metadata": {"sk-…": …}}` 里的键名也换成占位符,`restoreLog` 打开时回复里再换回来;协议自身的键(`model`、`role`、`type`、`name`、`id` 等)、工具定义和工具调用的参数名不动([ADR-0029](docs/adr/0029-mask-json-keys.md))。
|
|
73
74
|
|
|
74
75
|
## 界面
|
|
75
76
|
|
|
@@ -79,7 +80,7 @@ someone@gmail.com → EMAIL
|
|
|
79
80
|
|
|
80
81
|
## 配置
|
|
81
82
|
|
|
82
|
-
插件页面里本插件那一行的「配置」页上可以直接改日常项:`enabled`、`secrets`、`personal`、`shape`、`toolGuard`、`maskKeys`、`words`、`allow`、`record`、`keepDays`、`recordContext`、`vendorView`、`showPanel`、`excludeProviders`。改了即时保存,从下一次模型调用起生效,不用重启([ADR-0021](docs/adr/0021-live-settings.md))。其余项在 profile 的 `~/.dsh/profiles/<profile>/cordis.patch.yml` 里改,写在 `id: dsh-privacy-gateway` 那一行的 `config` 下;插件包自带的 `cordis.patch.yml` 升级时会被覆盖,不要改它。
|
|
83
|
+
插件页面里本插件那一行的「配置」页上可以直接改日常项:`enabled`、`secrets`、`personal`、`shape`、`toolGuard`、`restoreLog`、`maskKeys`、`words`、`allow`、`record`、`keepDays`、`recordContext`、`vendorView`、`showPanel`、`excludeProviders`。改了即时保存,从下一次模型调用起生效,不用重启([ADR-0021](docs/adr/0021-live-settings.md))。其余项在 profile 的 `~/.dsh/profiles/<profile>/cordis.patch.yml` 里改,写在 `id: dsh-privacy-gateway` 那一行的 `config` 下;插件包自带的 `cordis.patch.yml` 升级时会被覆盖,不要改它。
|
|
83
84
|
|
|
84
85
|
| 键 | 默认 | 说明 |
|
|
85
86
|
| --- | --- | --- |
|
|
@@ -90,11 +91,12 @@ someone@gmail.com → EMAIL
|
|
|
90
91
|
| `allow` | `[]` | 永不脱敏的值:整值匹配,不分大小写 |
|
|
91
92
|
| `actions` | `{}` | 按 kind 选动作:`mask`(默认,换成占位符)、`warn`(照发并记一条)、`block`(整个请求不发)。例:`{ PRIVATE_KEY: block, EMAIL: warn }`([ADR-0013](docs/adr/0013-actions.md)) |
|
|
92
93
|
| `maskKeys` | `true` | 读起来像密钥或个人信息的 **JSON 键名**也换成占位符(`{"sk-…": …}`);协议自身的键(`model`、`role`、`type`、`name`、`id` 等)、工具定义和工具调用的参数名永不动,否则供应商读不懂请求。关闭后这类键名原样发出([ADR-0029](docs/adr/0029-mask-json-keys.md)) |
|
|
93
|
-
| `toolGuard` | `off` | 工具调用参数里还原出值、又指向本机以外的 host 时怎么办:`off` 只计数,`warn` 告警并记一条,`block`
|
|
94
|
-
| `
|
|
94
|
+
| `toolGuard` | `off` | 工具调用参数里还原出值、又指向本机以外的 host 时怎么办:`off` 只计数,`warn` 告警并记一条,`block` 这次调用的参数里不还原,工具拿到占位符。只有 `restoreLog` 打开时回复里才会有还原值,关闭时这一项不会生效([ADR-0014](docs/adr/0014-tool-guard.md)) |
|
|
95
|
+
| `restoreLog` | `false` | 回复里的占位符在写入会话日志前是否换回真值。默认关闭:占位符原样进日志,明文不进日志,agent 拿到的也是占位符;打开后日志与 agent 都拿到真值,会话同步、备份、分享、导出带走的也是真值([ADR-0003](docs/adr/0003-restore-before-session-log.md)) |
|
|
96
|
+
| `shape` | `false` | 密钥换成同形的假 key(前缀、长度、字符类别不变),而不是 `{{…}}` 占位符;不足 8 个字符、或含字母数字与 `-` `_` `.` 以外字符的值仍用占位符;`restoreLog` 打开时回复里照样还原([ADR-0015](docs/adr/0015-shape.md)) |
|
|
95
97
|
| `cookieNames` | `[]` | 追加要脱敏的 cookie 名 |
|
|
96
98
|
| `cookieKeep` | `['lang', 'locale', 'theme', 'tz']` | 永不脱敏的 cookie 名 |
|
|
97
|
-
| `protectEnvBlock` | `true` | `<env>` … `</env>` 块原样发出,供会校验它的 provider
|
|
99
|
+
| `protectEnvBlock` | `true` | `<env>` … `</env>` 块原样发出,供会校验它的 provider 使用;只保护宿主生成的文本(系统提示词、`system`、`instructions`、`systemInstruction`),用户消息和工具结果里的 `<env>` 不算([ADR-0004](docs/adr/0004-protected-regions.md) 补充) |
|
|
98
100
|
| `protectTools` | `true` | 请求的 `tools` 数组原样发出 |
|
|
99
101
|
| `excludeHosts` | `[]` | 不改写的 `host` 或 `host:port` |
|
|
100
102
|
| `excludeProviders` | `[]` | 不脱敏的 provider id;「配置」页里从当前注册的 provider 中勾选。放行的请求原样发出、回复不还原、不留记录,有请求发出时日志里每个 provider 提示一次([ADR-0018](docs/adr/0018-exclude-providers.md)、[ADR-0034](docs/adr/0034-log-excluded-provider.md)) |
|
|
@@ -120,7 +122,7 @@ someone@gmail.com → EMAIL
|
|
|
120
122
|
|
|
121
123
|
## 记录与统计
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
只记有脱敏或还原的模型请求(`restoreLog` 关闭时没有还原,只记有脱敏的),一条请求一条:时间与耗时、host、model、会话及其工作区与标题、替换处数、每个值的占位符 / kind / finder / 开头 / 长度 / 出现过的每一处(每值最多 8 处,其余只计数)、请求所在的轮次与步数、值首次被发出的轮次与步数、回复里还原的处数(工具参数里的另计,`restoreLog` 关闭时恒为 0),以及值表里没有的占位符数。记录里不写值本身,也不记 URL 的 query([ADR-0008](docs/adr/0008-masking-records.md)、[ADR-0020](docs/adr/0020-record-attribution.md))。
|
|
124
126
|
|
|
125
127
|
「开头」只留辨识用的几个字符:有前缀的留下前缀和其后 4 个,没有的留前 4 个,长值再加末尾 2 个(`sk-proj-g6sx…3QaZ`),短值更少;个人信息和自定义词只留 1 个([ADR-0019](docs/adr/0019-hint.md))。
|
|
126
128
|
|
|
@@ -132,11 +134,12 @@ someone@gmail.com → EMAIL
|
|
|
132
134
|
|
|
133
135
|
## 须知
|
|
134
136
|
|
|
135
|
-
-
|
|
136
|
-
-
|
|
137
|
-
-
|
|
137
|
+
- 从 0.1.x 升级上来:默认不再还原,agent 拿到的是占位符。需要旧行为(agent 与日志都拿到真值)时,在配置页打开 `restoreLog`(「会话日志写入真值」)。
|
|
138
|
+
- 会话日志默认是占位符:`restoreLog` 关闭(默认)时,回复里的占位符原样进日志,明文不进日志,agent 拿到的也是占位符;打开后还原发生在日志落盘之前,日志与 agent 都是真值,会话同步、备份、分享、导出带走的也是真值([ADR-0003](docs/adr/0003-restore-before-session-log.md))。
|
|
139
|
+
- 覆盖面只有走全局 `fetch()` 的流量;`node:http` 直连、worker 线程、独立进程不经过网关([ADR-0001](docs/adr/0001-intercept-at-undici-global-dispatcher.md))。只改写识别得出的 JSON 模型请求(数组 `messages`、数组或字符串 `input`、`contents`、字符串 `prompt`);multipart、表单、非 JSON body 原样发出,也不留记录([ADR-0001](docs/adr/0001-intercept-at-undici-global-dispatcher.md))。
|
|
140
|
+
- 压缩的请求先解压再脱敏;`restoreLog` 打开时压缩的回复也先解码再还原,关闭时压缩的回复原样穿过网关、由适配器按 `content-encoding` 自己解压(用 `undici.request` 直连的 adapter 要自己解压,`fetch` 会自动解)。请求里认不出的 `content-encoding` 不发([ADR-0025](docs/adr/0025-compression-and-upgrades.md))。模型调用里的 `upgrade` 握手(WebSocket)与 `CONNECT` 隧道也不发:Codex 第一次被拒后回落到 SSE,之后同一会话直接走 SSE;模型调用之外的升级与隧道(别的插件自己的连接,如 dsh-im-infoflow 的入站)放行,消息不脱敏,每个 host 提示一次([ADR-0032](docs/adr/0032-upgrade-scoped-to-masked-calls.md))——这是 fail-closed 往 fail-open 的取舍,代价见 ADR;需要整条链路放行的 host 仍可加进 `excludeHosts`。
|
|
138
141
|
- 值表只在内存里([ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md))。重启后,规则命不中、只靠记忆兜住的值第一次出站会按原文发出。
|
|
139
|
-
-
|
|
142
|
+
- `restoreLog` 打开时,还原发生在回复里,包括工具调用参数:模型被诱导把占位符写进 `curl` 之类的命令时,工具执行时用的是真值。插件只记账(统计卡与 `/privacy status` 里的「工具参数」计数),不拦截([ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md));关闭时回复里没有真值,这条路径不存在。
|
|
140
143
|
- 脱敏出错时请求不会发出,报错 `dsh-privacy-gateway: masking failed, request not sent`([ADR-0005](docs/adr/0005-fail-closed.md))。止血办法是 `/privacy off`,或在插件页停用本插件、把配置 `enabled` 设为 `false`。
|
|
141
144
|
|
|
142
145
|
## 开发
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Privacy Gateway
|
|
2
2
|
|
|
3
|
-
Adds a redaction gateway to the dsh process. When a request to a model has a secret in it, such as an API key, a token or a cookie, the value goes out as a placeholder; placeholders in the model's reply are
|
|
3
|
+
Adds a redaction gateway to the dsh process. When a request to a model has a secret in it, such as an API key, a token or a cookie, the value goes out as a placeholder; by default the placeholders in the model's reply reach the agent and the session log as they are, so no plaintext reaches the log, and `restoreLog` puts them back with the real values before the log is written.
|
|
4
4
|
|
|
5
5
|
## Repository
|
|
6
6
|
|
|
@@ -11,10 +11,10 @@ If this project helps you, please give it a star 🌟
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
13
|
- **Masking**: API keys (OpenAI, Anthropic, GitHub, AWS, Alibaba Cloud, Tencent Cloud and other prefixes), JWTs, PEM private keys, passwords in URLs and fields, and cookies; optionally email addresses, phone numbers, ID card and bank card numbers, and your own words.
|
|
14
|
-
- **
|
|
14
|
+
- **No plaintext in the session log**: restore is off by default, so a reply's placeholders reach the agent and the session log as they are; with `restoreLog` on, JSON replies are restored whole and SSE replies event by event, including a placeholder split between two events.
|
|
15
15
|
- **Cache-friendly**: one value is the same placeholder every turn, so the prompt cache still hits.
|
|
16
16
|
- **An action per kind**: mask, send as written and record (warn), or not send the request at all (block).
|
|
17
|
-
- **Exfiltration guard**: when a tool call's arguments would get a real value back and name a host off this machine, warn, or leave the placeholder in.
|
|
17
|
+
- **Exfiltration guard**: with `restoreLog` on, when a tool call's arguments would get a real value back and name a host off this machine, warn, or leave the placeholder in.
|
|
18
18
|
- **Look-alike keys**: optionally send a key as a made-up one with the same prefix, length and kinds of character, so the model cannot tell it was masked; a value under 8 characters, or with unusual characters, keeps the placeholder.
|
|
19
19
|
- **Records and statistics**: only requests with something masked or restored are recorded, and a record never holds a value. The `/privacy` command shows the state and a preview; the plugin's detail page has a statistics card, and a Privacy tab can be turned on at the top of the session.
|
|
20
20
|
- **Fails closed**: when masking fails, the request is not sent; `/privacy off` turns masking off for the moment.
|
package/docs/details/DETAIL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 隐私网关
|
|
2
2
|
|
|
3
|
-
在 dsh 的进程里装一层脱敏网关:发给模型的请求里出现密钥、令牌、cookie
|
|
3
|
+
在 dsh 的进程里装一层脱敏网关:发给模型的请求里出现密钥、令牌、cookie 等敏感值时,先换成占位符再发出;模型回复里的占位符默认原样交给 agent、原样写进会话日志(明文不进日志),打开 `restoreLog` 才在落盘前换回真值。
|
|
4
4
|
|
|
5
5
|
## 项目仓库
|
|
6
6
|
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
## 功能
|
|
12
12
|
|
|
13
13
|
- **脱敏**:API key(OpenAI、Anthropic、GitHub、AWS、阿里云、腾讯云等前缀)、JWT、PEM 私钥、URL 和字段里的密码、cookie;可选脱敏邮箱、手机号、身份证号、银行卡号,以及自己配置的词。
|
|
14
|
-
-
|
|
14
|
+
- **日志不写真值**:默认不还原,回复里的占位符原样进会话日志和 agent;打开 `restoreLog` 后 JSON 回复整包还原,SSE 流式回复逐条事件还原,占位符被切在两条事件之间也能拼回。
|
|
15
15
|
- **保持缓存**:同一个值每轮都是同一个占位符,prompt cache 照常命中。
|
|
16
16
|
- **按 kind 选动作**:脱敏、照发并记录(warn),或整个请求不发(block)。
|
|
17
|
-
-
|
|
17
|
+
- **外带守卫**:`restoreLog` 打开时,工具调用参数里还原出真值、又指向本机以外的 host 时,告警,或者不还原。
|
|
18
18
|
- **同形伪装**:可选把密钥换成前缀、长度、字符类别都相同的假 key,模型看不出被脱敏过;不足 8 个字符或含特殊字符的值仍用占位符。
|
|
19
19
|
- **记录与统计**:只记脱敏和还原过的请求,记录里不写值本身;`/privacy` 命令查看状态和预览,插件详情页有统计卡,也可以在会话顶部打开「隐私保护」标签页。
|
|
20
20
|
- **失败不放行**:脱敏出错时请求不发出;`/privacy off` 可以临时关掉。
|