dsh-privacy-gateway 0.2.1 → 0.3.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.en.md +57 -11
- package/README.md +57 -11
- package/docs/assets/screenshots/0-banner-en.png +0 -0
- package/docs/assets/screenshots/0-banner.png +0 -0
- package/lib/client.js +2 -1
- package/lib/index.js +265 -123
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
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; by default the placeholders in the replies go into the session log as they are, so no
|
|
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 real value from a reply 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
|
|
|
11
|
+
**[Capability boundaries](#capability-boundaries)**:
|
|
12
|
+
|
|
13
|
+
- This is a lightweight implementation: only the text in a request body and in a reply is masked. Files attached to the conversation (Word, Excel and PowerPoint documents), images and archives are neither parsed nor masked; they go as they are.
|
|
14
|
+
- If a model is led into writing a script that sends data out, the gateway does not stop it: with `restoreLog` on, `toolGuard` (off by default) covers only the one case of a restored value plus a non-local host, so a bare domain or writing a file and pushing it later cannot be caught.
|
|
15
|
+
|
|
11
16
|
## Install
|
|
12
17
|
|
|
13
18
|
```bash
|
|
@@ -15,7 +20,7 @@ If you are using an **API relay**, or you are working with **sensitive informati
|
|
|
15
20
|
dsh plugin --profile web add dsh-privacy-gateway@latest
|
|
16
21
|
|
|
17
22
|
# 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.
|
|
23
|
+
dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.3.1/dsh-privacy-gateway-0.3.1.tgz
|
|
19
24
|
```
|
|
20
25
|
|
|
21
26
|
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,7 +31,7 @@ In the default web profile the first install works at once, with no restart of t
|
|
|
26
31
|
|
|
27
32
|
- **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
33
|
- **Actions**: pick `mask` / `warn` / `block` per kind; a key can be sent as a made-up key of its own form (`shape`).
|
|
29
|
-
- **No
|
|
34
|
+
- **No real value written back from a reply**: 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.
|
|
30
35
|
- **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.
|
|
31
36
|
- **The `/privacy` command**: status, a temporary on / off, and `test` to preview how a text would go out.
|
|
32
37
|
- **Live configuration**: everyday items are changed on the plugin page and apply from the next call; when masking fails, the request is not sent.
|
|
@@ -79,7 +84,7 @@ someone@gmail.com → EMAIL
|
|
|
79
84
|
11010519491231002X → ID_CARD
|
|
80
85
|
```
|
|
81
86
|
|
|
82
|
-
- The Chinese wordings 「密码:…」 and 「密钥是 …」, and a password in a URL, are recorded as
|
|
87
|
+
- The Chinese wordings 「密码:…」 and 「密钥是 …」, and a password in a URL, are recorded as `⟦DSH_REDACTED:PASSWORD_p7gqwtns⟧`, apart from `SECRET`.
|
|
83
88
|
- `EMAIL`, `PHONE`, `ID_CARD` and `BANK_CARD` are off until 「脱敏个人信息」 is on.
|
|
84
89
|
- A word in 「自定义敏感词」 is replaced where it appears and recorded as `TERM`; a value in 「永不脱敏的值」 or `allow` goes out as it is.
|
|
85
90
|
- A private key goes whole: `-----BEGIN` to `-----END`, or a truncated one with only the opening lines and base64.
|
|
@@ -91,6 +96,50 @@ someone@gmail.com → EMAIL
|
|
|
91
96
|
- 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)).
|
|
92
97
|
- 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)).
|
|
93
98
|
|
|
99
|
+
## Capability boundaries
|
|
100
|
+
|
|
101
|
+
The gateway acts at one point: **the moment a model request leaves**. It does not judge meaning, does not change how the host behaves, and does not rewrite what is already on disk. Here is what it covers and what it does not.
|
|
102
|
+
|
|
103
|
+
### What it covers
|
|
104
|
+
|
|
105
|
+
| Channel | Today |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| Model request body | POST JSON requests through the global `fetch()` (array `messages`, array or string `input`, `contents`, string `prompt`): matched values become placeholders, a compressed body is decompressed first ([ADR-0001](docs/adr/0001-intercept-at-undici-global-dispatcher.md), [ADR-0025](docs/adr/0025-compression-and-upgrades.md)) |
|
|
108
|
+
| Model reply | The response on the same connection: SSE streams and whole JSON, restored across chunks, compression and `\u27e6` escapes; written back into the log only with `restoreLog` on |
|
|
109
|
+
| Providers | Every adapter that goes through `fetch()`, ones a plugin provides included; `excludeHosts` / `excludeProviders` opt out |
|
|
110
|
+
| On failure | A masking error, an unknown `content-encoding`, or an `upgrade` / `CONNECT` on a model call is not sent ([ADR-0005](docs/adr/0005-fail-closed.md)) |
|
|
111
|
+
| Side channel | Records, statistics and Remote answers hold metadata only, never a value ([ADR-0008](docs/adr/0008-masking-records.md)) |
|
|
112
|
+
|
|
113
|
+
### What it does not cover
|
|
114
|
+
|
|
115
|
+
In the order a reader is most likely to assume otherwise:
|
|
116
|
+
|
|
117
|
+
| Case | Today | Consequence |
|
|
118
|
+
| --- | --- | --- |
|
|
119
|
+
| Your own words | Written when you send them, before the gateway | **The session log holds what you typed**; it becomes placeholders only as it leaves ([ADR-0003](docs/adr/0003-restore-before-session-log.md)) |
|
|
120
|
+
| Tool results | Written when the tool returns | **The session log holds the tool's output**; masked only on the next request out |
|
|
121
|
+
| Images, files, base64 attachments | No rule recognises them; sent as they are | Screenshots, scans and attachments reach the model service; `multipart`, forms and non-JSON bodies are always sent untouched and leave no record |
|
|
122
|
+
| Direct `node:http`, worker threads, separate processes | Do not pass through the gateway | Those requests get no placeholder and leave no record ([ADR-0001](docs/adr/0001-intercept-at-undici-global-dispatcher.md)) |
|
|
123
|
+
| Headers, URL, method | Only the body is rewritten, with the length and coding headers that follow | `Authorization` carries the provider's own credential and would fail if changed; query parameters are untouched |
|
|
124
|
+
| Other egress | Not handled | A plugin sending its own messages, writing files or reaching its own service does not pass through it; a `fetch()` that is no model request goes as it is |
|
|
125
|
+
| What is already on disk | Not rewritten | Content logged before the upgrade stays as it is |
|
|
126
|
+
|
|
127
|
+
### What it can recognise is limited
|
|
128
|
+
|
|
129
|
+
- A secret no rule matches is not masked: tokens of a custom shape, ciphertext, fragments split across places.
|
|
130
|
+
- Deliberately left alone: values shorter than 8 characters, values typed to stand for a key (`sk-…xxxx`, `changeme`), algorithm names (`SCRAM-SHA-512`), values that look like a file name ([ADR-0031](docs/adr/0031-no-short-or-template-values.md), [ADR-0033](docs/adr/0033-algorithm-names.md), [ADR-0026](docs/adr/0026-file-name-values.md)).
|
|
131
|
+
- There is no semantic judgement: rules and a word list only. Customer names, codenames and internal terms have to go into `words`; misses and false positives are both possible.
|
|
132
|
+
- A source constant whose field name contains a secret word may be judged a value when it is a name: a protocol-shaped slug (lower case, joined by `-`/`_`, each segment under 16 characters) under a field name ending in a container word (`header`, `id`, `file`, `name`…) is no longer mistaken for one ([ADR-0038](docs/adr/0038-container-field-slug-values.md)); put anything else confirmed not to be a secret into `allow`.
|
|
133
|
+
- Masking matches contiguous strings: hex and line-split encodings form no match and pass through by design, so the same file may read differently through a text tool and a hex tool.
|
|
134
|
+
- Images are not OCR'd; binary content goes out as it is.
|
|
135
|
+
|
|
136
|
+
### What it is not responsible for
|
|
137
|
+
|
|
138
|
+
- It does not stop what a tool does with a real value (`restoreLog` on): a model led into writing a placeholder into a command such as `curl` runs the tool with the real value; the plugin only counts, and `toolGuard` can warn or block that one call ([ADR-0014](docs/adr/0014-tool-guard.md), [ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md)).
|
|
139
|
+
- The value table is per process and cleared on restart; after a restart, a value no rule finds, masked only because it was remembered, goes as written the first time it is sent again ([ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md)).
|
|
140
|
+
- It is not a compliance control and keeps no egress audit: a record shows that a substitution happened, not that nothing was missed.
|
|
141
|
+
- It does not protect data at rest: it protects the copy going to the model, not the session log, backups or exports on disk.
|
|
142
|
+
|
|
94
143
|
## Screens
|
|
95
144
|
|
|
96
145
|
The screenshots show the Chinese interface.
|
|
@@ -114,7 +163,7 @@ The everyday settings can be changed on the Configure page of this plugin's row
|
|
|
114
163
|
| `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)) |
|
|
115
164
|
| `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)) |
|
|
116
165
|
| `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)) |
|
|
117
|
-
| `shape` | `false` | Send a key as a made-up key of its own form (same prefix, length and kinds of character) instead of a
|
|
166
|
+
| `shape` | `false` | Send a key as a made-up key of its own form (same prefix, length and kinds of character) instead of a `⟦DSH_REDACTED:…⟧` 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)) |
|
|
118
167
|
| `cookieNames` | `[]` | More cookie names to mask |
|
|
119
168
|
| `cookieKeep` | `['lang', 'locale', 'theme', 'tz']` | Cookie names never masked |
|
|
120
169
|
| `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) |
|
|
@@ -156,11 +205,8 @@ With `vendorView` on (「保留发出内容,供对照查看」 on the config p
|
|
|
156
205
|
## Notes
|
|
157
206
|
|
|
158
207
|
- 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.
|
|
159
|
-
- By default the session log holds placeholders: with `restoreLog` off (the default), a reply's placeholders go into the log as they are, no
|
|
160
|
-
-
|
|
161
|
-
- 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`.
|
|
162
|
-
- 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.
|
|
163
|
-
- 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.
|
|
208
|
+
- By default the session log holds placeholders: with `restoreLog` off (the default), a reply's placeholders go into the log as they are, no real value from a reply 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)).
|
|
209
|
+
- 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 something other than a model call 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`.
|
|
164
210
|
- 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`.
|
|
165
211
|
|
|
166
212
|
## Development
|
package/README.md
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
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
|
|
|
11
|
+
**[能力边界](#能力边界)**:
|
|
12
|
+
|
|
13
|
+
- 这是一个轻量级实现,只对请求体与回复里的文本做脱敏。对话附件里的文件(Word、Excel、PPT 这类文档)、图片、压缩包等都不解析、不脱敏,原样发出。
|
|
14
|
+
- 如果模型被诱导写出把数据外发的脚本,插件不拦:`restoreLog` 打开时 `toolGuard`(默认 `off`)也只覆盖「还原值 + 非本机 host」这一种外带,裸域名、先写文件再推送这些都拦不住。
|
|
15
|
+
|
|
11
16
|
## 安装
|
|
12
17
|
|
|
13
18
|
```bash
|
|
@@ -15,7 +20,7 @@
|
|
|
15
20
|
dsh plugin --profile web add dsh-privacy-gateway@latest
|
|
16
21
|
|
|
17
22
|
# 同一版本的 GitHub Release 附件(预发布也发在这里)
|
|
18
|
-
dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.
|
|
23
|
+
dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.3.1/dsh-privacy-gateway-0.3.1.tgz
|
|
19
24
|
```
|
|
20
25
|
|
|
21
26
|
预发布版本号带 `-`,只发 GitHub Release、不发 npm。仓库不提交 `lib/`,`dsh plugin add github:…` 拿到的树加载不了([ADR-0006](docs/adr/0006-distribution-and-build-artifacts.md))。
|
|
@@ -26,7 +31,7 @@ dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/rele
|
|
|
26
31
|
|
|
27
32
|
- **脱敏范围**:密钥、token、密码、私钥、cookie、邮箱、手机号、身份证、银行卡、自定义敏感词,各有开关。
|
|
28
33
|
- **动作可选**:按 kind 选 `mask` / `warn` / `block`,密钥可换成同形的假 key(`shape`)。
|
|
29
|
-
-
|
|
34
|
+
- **回复不写回真值**:默认不还原,回复里的占位符原样进会话日志,回复里的真值不进日志;打开 `restoreLog` 才把真值写回,agent 同时拿到真值。
|
|
30
35
|
- **记录与统计**:按天落盘的脱敏记录、统计卡、会话「隐私保护」标签页;记录里只有占位符,没有真值。
|
|
31
36
|
- **`/privacy` 命令**:查状态、临时开关、`test` 预览一段文本会怎样发出。
|
|
32
37
|
- **配置热更新**:日常项在插件页上改,下一次调用即生效;脱敏出错时请求不发出。
|
|
@@ -79,7 +84,7 @@ someone@gmail.com → EMAIL
|
|
|
79
84
|
11010519491231002X → ID_CARD
|
|
80
85
|
```
|
|
81
86
|
|
|
82
|
-
- 中文写法「密码:…」「密钥是 …」和 URL 里的密码记为
|
|
87
|
+
- 中文写法「密码:…」「密钥是 …」和 URL 里的密码记为 `⟦DSH_REDACTED:PASSWORD_p7gqwtns⟧`,和 `SECRET` 分开记。
|
|
83
88
|
- `EMAIL`、`PHONE`、`ID_CARD`、`BANK_CARD` 默认不换,打开「脱敏个人信息」才生效。
|
|
84
89
|
- 「自定义敏感词」里的词按词替换,记为 `TERM`;「永不脱敏的值」和 `allow` 里的原样发出。
|
|
85
90
|
- 私钥整段一起换:`-----BEGIN` 到 `-----END`,或只有开头一段 base64 的截断私钥。
|
|
@@ -91,6 +96,50 @@ someone@gmail.com → EMAIL
|
|
|
91
96
|
- 加密算法的名字不算值:`SCRAM-SHA-512`、`PBKDF2WithHmacSHA256` 这类名字写在规范里、人人可读,遮住什么都不保护,原样发出([ADR-0033](docs/adr/0033-algorithm-names.md))。
|
|
92
97
|
- 键名和值一样脱敏:`{"metadata": {"sk-…": …}}` 里的键名也换成占位符,`restoreLog` 打开时回复里再换回来;协议自身的键(`model`、`role`、`type`、`name`、`id` 等)、工具定义和工具调用的参数名不动([ADR-0029](docs/adr/0029-mask-json-keys.md))。
|
|
93
98
|
|
|
99
|
+
## 能力边界
|
|
100
|
+
|
|
101
|
+
网关只在一个位置动手:**模型请求出站的那一刻**。它不判断语义、不改宿主行为、不改已经落盘的内容。下面是它覆盖的与不覆盖的。
|
|
102
|
+
|
|
103
|
+
### 能做的
|
|
104
|
+
|
|
105
|
+
| 通道 | 现在 |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| 模型请求体 | 走全局 `fetch()` 的 POST JSON 请求(数组 `messages`、数组或字符串 `input`、`contents`、字符串 `prompt`):命中规则的值换成占位符,压缩的先解压([ADR-0001](docs/adr/0001-intercept-at-undici-global-dispatcher.md)、[ADR-0025](docs/adr/0025-compression-and-upgrades.md)) |
|
|
108
|
+
| 模型回复 | 同一条连接的响应:SSE 流与整段 JSON,跨分片、压缩、`\u27e6` 转义都能还原;`restoreLog` 打开时才写回日志 |
|
|
109
|
+
| 覆盖的 provider | 所有走 `fetch()` 的 adapter,包括插件提供的;`excludeHosts` / `excludeProviders` 可以放行 |
|
|
110
|
+
| 出错时 | 脱敏出错、认不出的 `content-encoding`、模型调用上的 `upgrade` / `CONNECT` 一律不发([ADR-0005](docs/adr/0005-fail-closed.md)) |
|
|
111
|
+
| 旁路 | 记录、统计、Remote 返回值只有元信息,没有真值([ADR-0008](docs/adr/0008-masking-records.md)) |
|
|
112
|
+
|
|
113
|
+
### 做不到的
|
|
114
|
+
|
|
115
|
+
按最容易被误以为做了的顺序排:
|
|
116
|
+
|
|
117
|
+
| 场景 | 现在 | 后果 |
|
|
118
|
+
| --- | --- | --- |
|
|
119
|
+
| 你自己发的话 | 发送时就落盘,早于网关 | **会话日志里是你输入的原文**;只有出站那一刻才换成占位符([ADR-0003](docs/adr/0003-restore-before-session-log.md)) |
|
|
120
|
+
| 工具结果 | 工具返回后落盘 | **会话日志里是工具输出的原文**;下一次出站才脱敏 |
|
|
121
|
+
| 图片、文件、base64 附件 | 没有规则认它,原样发出 | 截图、扫描件、附件内容会到模型服务;`multipart`、表单、非 JSON body 更是一律原样发出,也不留记录 |
|
|
122
|
+
| `node:http` 直连、worker 线程、独立进程 | 不经过网关 | 这些路径上的请求没有占位符,也没有记录([ADR-0001](docs/adr/0001-intercept-at-undici-global-dispatcher.md)) |
|
|
123
|
+
| 请求头、URL、方法 | 只改 body,以及随之变化的长度与编码头 | `Authorization` 这类头里是 provider 自己的凭据,改了会认证失败;query 参数同样不动 |
|
|
124
|
+
| 别的出站通道 | 不管 | 别的插件自己发消息、写文件、连自己的服务,都不经过它;走 `fetch()` 但不是模型请求的,原样放行 |
|
|
125
|
+
| 已经落盘的历史 | 不改 | 升级前写进日志的内容保持原样 |
|
|
126
|
+
|
|
127
|
+
### 认得出来的形态有限
|
|
128
|
+
|
|
129
|
+
- 规则没命中的密钥不脱敏:自定义格式的令牌、加密或编码后的密文、拆成多段的片段。
|
|
130
|
+
- 故意不脱敏的:短于 8 个字符的值、占位写法(`sk-…xxxx`、`changeme`)、算法名(`SCRAM-SHA-512`)、像文件名的值([ADR-0031](docs/adr/0031-no-short-or-template-values.md)、[ADR-0033](docs/adr/0033-algorithm-names.md)、[ADR-0026](docs/adr/0026-file-name-values.md))。
|
|
131
|
+
- 没有语义判断:只有规则和词表。客户名、项目代号、内部术语要自己加进 `words`;漏检和误伤都可能存在。
|
|
132
|
+
- 字段名里带 secret 词的源码常量可能被具名规则当成值脱敏(值其实是名字):末位是容器词(`header`、`id`、`file`、`name`…)的字段名下、小写且以 `-`/`_` 分段每段短于 16 字符的协议型 slug 已不再误判([ADR-0038](docs/adr/0038-container-field-slug-values.md)),其余的确认后放进 `allow`。
|
|
133
|
+
- 脱敏按连续字符串匹配:hex、分行的编码表示不形成连续匹配,天然旁路——同一份文件经文本工具和 hex 工具读到的内容可能不一致。
|
|
134
|
+
- 图片不做 OCR,二进制内容原样发出。
|
|
135
|
+
|
|
136
|
+
### 不负责的事
|
|
137
|
+
|
|
138
|
+
- 不拦截工具拿到真值之后的动作(`restoreLog` 打开时):模型被诱导把占位符写进 `curl` 之类的命令,工具执行时用的就是真值;插件只记账,`toolGuard` 可选告警或拦那一次调用([ADR-0014](docs/adr/0014-tool-guard.md)、[ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md))。
|
|
139
|
+
- 不跨进程共享值表:每个进程自己的值表,重启清空;重启后规则命不中、只靠记忆兜住的值第一次出站按原文发出([ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md))。
|
|
140
|
+
- 不做合规认证、不做出口审计:记录只能说明「发生过替换」,不能说明「没有遗漏」。
|
|
141
|
+
- 不做静态数据保护:它保护的是发往模型的那一份,不是磁盘上的会话日志、备份或导出的文件。
|
|
142
|
+
|
|
94
143
|
## 界面
|
|
95
144
|
|
|
96
145
|
| 插件配置 | 会话「隐私保护」 |
|
|
@@ -112,7 +161,7 @@ someone@gmail.com → EMAIL
|
|
|
112
161
|
| `maskKeys` | `true` | 读起来像密钥或个人信息的 **JSON 键名**也换成占位符(`{"sk-…": …}`);协议自身的键(`model`、`role`、`type`、`name`、`id` 等)、工具定义和工具调用的参数名永不动,否则供应商读不懂请求。关闭后这类键名原样发出([ADR-0029](docs/adr/0029-mask-json-keys.md)) |
|
|
113
162
|
| `toolGuard` | `off` | 工具调用参数里还原出值、又指向本机以外的 host 时怎么办:`off` 只计数,`warn` 告警并记一条,`block` 这次调用的参数里不还原,工具拿到占位符。只有 `restoreLog` 打开时回复里才会有还原值,关闭时这一项不会生效([ADR-0014](docs/adr/0014-tool-guard.md)) |
|
|
114
163
|
| `restoreLog` | `false` | 回复里的占位符在写入会话日志前是否换回真值。默认关闭:占位符原样进日志,明文不进日志,agent 拿到的也是占位符;打开后日志与 agent 都拿到真值,会话同步、备份、分享、导出带走的也是真值([ADR-0003](docs/adr/0003-restore-before-session-log.md)) |
|
|
115
|
-
| `shape` | `false` | 密钥换成同形的假 key(前缀、长度、字符类别不变),而不是
|
|
164
|
+
| `shape` | `false` | 密钥换成同形的假 key(前缀、长度、字符类别不变),而不是 `⟦DSH_REDACTED:…⟧` 占位符;不足 8 个字符、或含字母数字与 `-` `_` `.` 以外字符的值仍用占位符;`restoreLog` 打开时回复里照样还原([ADR-0015](docs/adr/0015-shape.md)) |
|
|
116
165
|
| `cookieNames` | `[]` | 追加要脱敏的 cookie 名 |
|
|
117
166
|
| `cookieKeep` | `['lang', 'locale', 'theme', 'tz']` | 永不脱敏的 cookie 名 |
|
|
118
167
|
| `protectEnvBlock` | `true` | `<env>` … `</env>` 块原样发出,供会校验它的 provider 使用;只保护宿主生成的文本(系统提示词、`system`、`instructions`、`systemInstruction`),用户消息和工具结果里的 `<env>` 不算([ADR-0004](docs/adr/0004-protected-regions.md) 补充) |
|
|
@@ -154,11 +203,8 @@ someone@gmail.com → EMAIL
|
|
|
154
203
|
## 须知
|
|
155
204
|
|
|
156
205
|
- 从 0.1.x 升级上来:默认不再还原,agent 拿到的是占位符。需要旧行为(agent 与日志都拿到真值)时,在配置页打开 `restoreLog`(「会话日志写入真值」)。
|
|
157
|
-
- 会话日志默认是占位符:`restoreLog`
|
|
158
|
-
-
|
|
159
|
-
- 压缩的请求先解压再脱敏;`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`。
|
|
160
|
-
- 值表只在内存里([ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md))。重启后,规则命不中、只靠记忆兜住的值第一次出站会按原文发出。
|
|
161
|
-
- `restoreLog` 打开时,还原发生在回复里,包括工具调用参数:模型被诱导把占位符写进 `curl` 之类的命令时,工具执行时用的是真值。插件只记账(统计卡与 `/privacy status` 里的「工具参数」计数),不拦截([ADR-0009](docs/adr/0009-value-table-and-restore-exfiltration.md));关闭时回复里没有真值,这条路径不存在。
|
|
206
|
+
- 会话日志默认是占位符:`restoreLog` 关闭(默认)时,回复里的占位符原样进日志,回复里的真值不进日志,agent 拿到的也是占位符;打开后还原发生在日志落盘之前,日志与 agent 都是真值,会话同步、备份、分享、导出带走的也是真值([ADR-0003](docs/adr/0003-restore-before-session-log.md))。
|
|
207
|
+
- 压缩的请求先解压再脱敏;`restoreLog` 打开时压缩的回复也先解码再还原,关闭时压缩的回复原样穿过网关、由适配器按 `content-encoding` 自己解压(用 `undici.request` 直连的 adapter 要自己解压,`fetch` 会自动解)。请求里认不出的 `content-encoding` 不发([ADR-0025](docs/adr/0025-compression-and-upgrades.md))。模型调用里的 `upgrade` 握手(WebSocket)与 `CONNECT` 隧道也不发:Codex 第一次被拒后回落到 SSE,之后同一会话直接走 SSE;模型调用之外的升级与隧道(别的组件自己的连接)放行,消息不脱敏,每个 host 提示一次([ADR-0032](docs/adr/0032-upgrade-scoped-to-masked-calls.md))——这是 fail-closed 往 fail-open 的取舍,代价见 ADR;需要整条链路放行的 host 仍可加进 `excludeHosts`。
|
|
162
208
|
- 脱敏出错时请求不会发出,报错 `dsh-privacy-gateway: masking failed, request not sent`([ADR-0005](docs/adr/0005-fail-closed.md))。止血办法是 `/privacy off`,或在插件页停用本插件、把配置 `enabled` 设为 `false`。
|
|
163
209
|
|
|
164
210
|
## 开发
|
|
Binary file
|
|
Binary file
|