dsh-privacy-gateway 0.1.4 → 0.1.6

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 CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  [简体中文](README.md) | English
4
4
 
5
- A DeepSeek Harness plugin that adds a redaction gateway on the host process's undici global dispatcher. Secrets in outgoing model request bodies are replaced with placeholders, and placeholders in the replies are replaced back with the real values. The agent, adapters and providers don't notice it, and one interception point covers every provider that goes through `fetch()`, including adapters that plugins provide.
5
+ ![The model only sees {{placeholder}}: secrets, credentials and personal data are replaced with placeholders before they are sent, and restored in the replies — one interception point, every provider goes through it](docs/assets/screenshots/0-banner.png)
6
6
 
7
- Status: published on npm.
7
+ A redaction gateway on the host process's undici global dispatcher. Secrets in outgoing model request bodies are replaced with placeholders, and placeholders in the replies are replaced back with the real values. The agent, adapters and providers don't notice it, and one interception point covers every provider that goes through `fetch()`, including adapters that plugins provide.
8
+
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.
8
10
 
9
11
  ## Install
10
12
 
@@ -13,12 +15,20 @@ Status: published on npm.
13
15
  dsh plugin --profile web add dsh-privacy-gateway@latest
14
16
 
15
17
  # The same version as a GitHub Release asset (prereleases get one too)
16
- dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.1.0/dsh-privacy-gateway-0.1.0.tgz
18
+ dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.1.4/dsh-privacy-gateway-0.1.4.tgz
17
19
  ```
18
20
 
19
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)).
20
22
 
21
- In the default web profile the first install works at once, with no restart. After an upgrade, a release that changed only the client takes effect at once; one with host changes needs a restart of dsh.
23
+ In the default web profile the first install works at once, with no restart of the dsh instance. Updating the plugin through the dsh web profile's plugin update feature needs no restart of the dsh instance either. When updating by hand, uninstall the old version before installing the new one, and that needs no restart either.
24
+
25
+ ## Features
26
+
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
+ - **Actions**: pick `mask` / `warn` / `block` per kind; a key can be sent as a made-up key of its own form (`shape`).
29
+ - **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
+ - **The `/privacy` command**: status, a temporary on / off, and `test` to preview how a text would go out.
31
+ - **Live configuration**: everyday items are changed on the plugin page and apply from the next call; when masking fails, the request is not sent.
22
32
 
23
33
  ## What is masked
24
34
 
@@ -58,6 +68,7 @@ someone@gmail.com → EMAIL
58
68
  - One value seen again gets the same placeholder.
59
69
  - 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)).
60
70
  - 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
+ - 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)).
61
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)).
62
73
 
63
74
  ## Screens
package/README.md CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  [English](README.en.md) | 简体中文
4
4
 
5
- DeepSeek Harness 插件:在宿主进程的 undici 全局 dispatcher 上装一层脱敏网关。出站把模型请求体里的密钥换成占位符,入站把回流里的占位符换回真值。对 agent、adapter、provider 都无感,一处拦截覆盖所有走 `fetch()` 的 provider,包括插件提供的 adapter。
5
+ ![模型只看见 {{占位符}}:密钥、凭据、个人信息发出前换成占位符,回复里再换回原值,一处拦截,所有 provider 都经过它](docs/assets/screenshots/0-banner.png)
6
6
 
7
- 状态:已发布到 npm。
7
+ 在宿主进程的 undici 全局 dispatcher 上装一层脱敏网关。出站把模型请求体里的密钥换成占位符,入站把回流里的占位符换回真值。对 agent、adapter、provider 都无感,一处拦截覆盖所有走 `fetch()` 的 provider,包括插件提供的 adapter。
8
+
9
+ 如果你在用**中转站**或者在处理**敏感信息**、**线上数据**,请务必注意保护信息安全。
8
10
 
9
11
  ## 安装
10
12
 
@@ -13,12 +15,20 @@ DeepSeek Harness 插件:在宿主进程的 undici 全局 dispatcher 上装一
13
15
  dsh plugin --profile web add dsh-privacy-gateway@latest
14
16
 
15
17
  # 同一版本的 GitHub Release 附件(预发布也发在这里)
16
- dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.1.0/dsh-privacy-gateway-0.1.0.tgz
18
+ dsh plugin --profile web add https://github.com/xbzbing/dsh-privacy-gateway/releases/download/v0.1.4/dsh-privacy-gateway-0.1.4.tgz
17
19
  ```
18
20
 
19
21
  预发布版本号带 `-`,只发 GitHub Release、不发 npm。仓库不提交 `lib/`,`dsh plugin add github:…` 拿到的树加载不了([ADR-0006](docs/adr/0006-distribution-and-build-artifacts.md))。
20
22
 
21
- 在默认的 web profile 里首次安装即装即用,无需重启。更新时,只改 client 的版本立即生效;含 host 改动的版本需重启 dsh。
23
+ 在默认的 web profile 里首次安装即装即用,无需重启 dsh 实例。通过 dsh web profile 的插件更新功能更新插件时,无需重启 dsh 实例。手动更新时建议先卸载旧版本再安装新版本,这样也不需要重启。
24
+
25
+ ## 功能
26
+
27
+ - **脱敏范围**:密钥、token、密码、私钥、cookie、邮箱、手机号、身份证、银行卡、自定义敏感词,各有开关。
28
+ - **动作可选**:按 kind 选 `mask` / `warn` / `block`,密钥可换成同形的假 key(`shape`)。
29
+ - **记录与统计**:按天落盘的脱敏记录、统计卡、会话「隐私保护」标签页;记录里只有占位符,没有真值。
30
+ - **`/privacy` 命令**:查状态、临时开关、`test` 预览一段文本会怎样发出。
31
+ - **配置热更新**:日常项在插件页上改,下一次调用即生效;脱敏出错时请求不发出。
22
32
 
23
33
  ## 脱敏范围
24
34
 
@@ -58,6 +68,7 @@ someone@gmail.com → EMAIL
58
68
  - 同一个值重复出现,占位符相同。
59
69
  - 短于 8 个字符的秘密(`abc123`、`666666`、`888888` 这类口令)不算值:照原样发出,也不进记录。它们随时能被爆破,遮住只是给人一种并不存在的保护;值表本来也不把这么短的值当作已知值([ADR-0031](docs/adr/0031-no-short-or-template-values.md))。
60
70
  - 明显是占位写法的值不算值: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
+ - 加密算法的名字不算值:`SCRAM-SHA-512`、`PBKDF2WithHmacSHA256` 这类名字写在规范里、人人可读,遮住什么都不保护,原样发出([ADR-0033](docs/adr/0033-algorithm-names.md))。
61
72
  - 键名和值一样脱敏:`{"metadata": {"sk-…": …}}` 里的键名也换成占位符,回复里再换回来;协议自身的键(`model`、`role`、`type`、`name`、`id` 等)、工具定义和工具调用的参数名不动([ADR-0029](docs/adr/0029-mask-json-keys.md))。
62
73
 
63
74
  ## 界面
package/lib/index.js CHANGED
@@ -1113,6 +1113,37 @@ function fileNameValue(v) {
1113
1113
  const dot = v.lastIndexOf(".");
1114
1114
  return dot > 0 && dot < v.length - 1 && FILE_EXT$1.has(v.slice(dot + 1).toLowerCase());
1115
1115
  }
1116
+ /**
1117
+ * The words a published cryptographic algorithm's name is built from: scram,
1118
+ * sha, aes, gcm, pbkdf, with, padding, tls, siv, poly. The list is closed and
1119
+ * disjoint from SECRET_WORDS, so a real secret's random characters spell no
1120
+ * word of it (docs/adr/0033).
1121
+ */
1122
+ const ALGO_WORDS = new Set("scram sha shake md blake ripemd whirlpool crc xxh siphash hmac hkdf pbkdf argon bcrypt scrypt with aes des desede rc twofish serpent camellia idea chacha cha salsa blowfish aria sm ecb cbc ctr ccm gcm cfb ofb xts siv kw kwr padding pkcs oaep pss no rsa dsa dh ecdsa ecdh ecdhe ed x p ecc curve id tls ssl sasl gssapi jwt jose hs rs es ps poly".split(" "));
1123
+ /** The words in a value: runs of letters, with the boundary of a camelCase word opened. */
1124
+ function algorithmWords(v) {
1125
+ const out = [];
1126
+ for (const part of v.split(/[^A-Za-z]+/)) {
1127
+ if (part === "") continue;
1128
+ for (const w of part.match(/[A-Z]+[a-z]*|[a-z]+|[A-Z]+/g) ?? []) out.push(w.toLowerCase());
1129
+ }
1130
+ return out;
1131
+ }
1132
+ /**
1133
+ * The name of a published cryptographic algorithm, not a value: a Kafka
1134
+ * scram_mechanism's SCRAM-SHA-512, PBKDF2WithHmacSHA256,
1135
+ * ECDHE-RSA-AES128-GCM-SHA256. A spec publishes these names for anyone to
1136
+ * read, so masking one hides nothing — it only mangles a config in a tool's
1137
+ * output, and a reader suspects the config was edited. Every word of the
1138
+ * value has to be one of ALGO_WORDS and its characters a name's, or it is not
1139
+ * one: the words are published vocabulary, and a secret is not spelled out of
1140
+ * them (docs/adr/0033).
1141
+ */
1142
+ function algorithmValue(v) {
1143
+ if (!hasDigit(v) || !/^[A-Za-z0-9][A-Za-z0-9 ._+/-]*$/.test(v)) return false;
1144
+ const words = algorithmWords(v);
1145
+ return words.length > 0 && words.every((w) => ALGO_WORDS.has(w));
1146
+ }
1116
1147
  const SECRET_WORDS = new Set([
1117
1148
  "token",
1118
1149
  "tokens",
@@ -1832,6 +1863,29 @@ function quotedEnd(c, i, quote) {
1832
1863
  return Math.min(c.next.index(quote, i), c.next.index("\n", i));
1833
1864
  }
1834
1865
  /**
1866
+ * The end of the object whose `{` is s[i]: the `}` that matches it, or the cap
1867
+ * where it is not closed. A `}` inside a quoted value is no end, and a quote
1868
+ * may be written escaped (\"…\", a JSON string holding JSON).
1869
+ */
1870
+ function objectEnd(c, i) {
1871
+ const s$1 = c.s;
1872
+ const cap = Math.min(s$1.length, i + 4096);
1873
+ let depth = 0;
1874
+ let k = i;
1875
+ while (k < cap) {
1876
+ const ch = s$1[k];
1877
+ if (ch === "\"" || ch === "'") {
1878
+ const q = c.next.index(ch, k + 1);
1879
+ k = q < cap ? q + 1 : cap;
1880
+ continue;
1881
+ }
1882
+ if (ch === "{") depth++;
1883
+ else if (ch === "}" && --depth === 0) return k;
1884
+ k++;
1885
+ }
1886
+ return cap;
1887
+ }
1888
+ /**
1835
1889
  * A name starts where a run of name characters does, and is at most 64 of
1836
1890
  * them on each side of cookie: tried from every place in a long run, the
1837
1891
  * pattern read the rest of it each time.
@@ -1847,9 +1901,10 @@ function namedFields(c) {
1847
1901
  const first = m[1].toLowerCase().endsWith("set-cookie");
1848
1902
  let i = m.index + m[0].length;
1849
1903
  if (s$1[i] === "{") {
1850
- const close = s$1.indexOf("}", i);
1851
- const end = close < 0 ? Math.min(s$1.length, i + 4096) : close;
1852
- for (const d of s$1.slice(i, end).matchAll(DICT_PAIR)) {
1904
+ const end = objectEnd(c, i);
1905
+ const body = s$1.slice(i, end);
1906
+ if (isCookieObject(body)) cookieObject(c, body, i, true);
1907
+ else for (const d of body.matchAll(DICT_PAIR)) {
1853
1908
  const g = d.indices[2];
1854
1909
  value(c, d[1], i + g[0], i + g[1]);
1855
1910
  }
@@ -1890,34 +1945,53 @@ function cookiesTxt(c) {
1890
1945
  }
1891
1946
  const FLAT_OBJECT = /\{[^{}]{1,4000}\}/g;
1892
1947
  const OBJ_FIELD = /\\?"(name|value|domain|httpOnly)\\?"[ \t]*:[ \t]*(\\?"([^"\\\n]*)\\?"|true|false)/dgi;
1948
+ /** A cookie object's own fields, by the names they have whether or not their value is a literal ({\"name\":name). */
1949
+ const OBJ_NAME = /\\?["']name\\?["'][ \t]*:/i;
1950
+ const OBJ_VALUE = /\\?["']value\\?["'][ \t]*:/i;
1951
+ /**
1952
+ * Whether a text reads as a cookie object (Playwright storageState, HAR, a
1953
+ * browser extension's) and not as a dict of cookies by name: it has a name and
1954
+ * a value field, and those are the object's own, no cookie's (docs/adr/0010).
1955
+ */
1956
+ function isCookieObject(text) {
1957
+ return OBJ_NAME.test(text) && OBJ_VALUE.test(text);
1958
+ }
1959
+ /**
1960
+ * Masks what an object writes of its cookie: the `value`, and nothing else —
1961
+ * a `domain`, `path` or `expires` is no cookie and stays (docs/adr/0010). A
1962
+ * HAR header object {"name": "Cookie", "value": "…"} is a Cookie: line, and one
1963
+ * named Set-Cookie is a Set-Cookie: line. `named` says the object was found
1964
+ * under a cookie's name, where a name and a value alone are enough. False where
1965
+ * the object writes no value this can mask.
1966
+ */
1967
+ function cookieObject(c, text, base, named = false) {
1968
+ let name$1;
1969
+ let val;
1970
+ let cookieish = false;
1971
+ for (const f of text.matchAll(OBJ_FIELD)) {
1972
+ const key = f[1].toLowerCase();
1973
+ if (key === "domain" || key === "httponly") cookieish = true;
1974
+ if (f[3] === void 0) continue;
1975
+ if (key === "name") name$1 = f[3];
1976
+ if (key === "value") {
1977
+ const g = f.indices[3];
1978
+ val = [base + g[0], base + g[1]];
1979
+ }
1980
+ }
1981
+ if (name$1 === void 0 || !val) return false;
1982
+ const lower$1 = name$1.toLowerCase();
1983
+ if (lower$1 === "cookie" || lower$1 === "set-cookie") pairs(c, val[0], val[1], lower$1 === "set-cookie");
1984
+ else if (cookieish || named) value(c, name$1, val[0], val[1]);
1985
+ else return false;
1986
+ return true;
1987
+ }
1893
1988
  /**
1894
1989
  * A cookie as an export writes it (Playwright storageState, HAR, a browser
1895
1990
  * extension's): an object with name and value, and domain or httpOnly. A
1896
1991
  * HAR header object {"name": "Cookie", "value": "…"} is a Cookie: line.
1897
1992
  */
1898
1993
  function cookieObjects(c) {
1899
- const s$1 = c.s;
1900
- for (const o of s$1.matchAll(FLAT_OBJECT)) {
1901
- const text = o[0];
1902
- if (!/value/i.test(text) || !/name/i.test(text)) continue;
1903
- let name$1;
1904
- let val;
1905
- let cookieish = false;
1906
- for (const f of text.matchAll(OBJ_FIELD)) {
1907
- const key = f[1].toLowerCase();
1908
- if (key === "domain" || key === "httponly") cookieish = true;
1909
- if (f[3] === void 0) continue;
1910
- if (key === "name") name$1 = f[3];
1911
- if (key === "value") {
1912
- const g = f.indices[3];
1913
- val = [o.index + g[0], o.index + g[1]];
1914
- }
1915
- }
1916
- if (name$1 === void 0 || !val) continue;
1917
- const lower$1 = name$1.toLowerCase();
1918
- if (lower$1 === "cookie" || lower$1 === "set-cookie") pairs(c, val[0], val[1], lower$1 === "set-cookie");
1919
- else if (cookieish) value(c, name$1, val[0], val[1]);
1920
- }
1994
+ for (const o of c.s.matchAll(FLAT_OBJECT)) if (isCookieObject(o[0])) cookieObject(c, o[0], o.index);
1921
1995
  }
1922
1996
  function namedCookies(c, plan) {
1923
1997
  const s$1 = c.s;
@@ -2024,7 +2098,7 @@ function takes(r, s$1, a, b) {
2024
2098
  if (r.bound && (a > 0 && r.bound.includes(s$1[a - 1]) || b < s$1.length && r.bound.includes(s$1[b]))) return false;
2025
2099
  if (r.cat === "secret") {
2026
2100
  const v = s$1.slice(a, b);
2027
- if (v.length < MIN_SECRET_CHARS || !notATemplate(v)) return false;
2101
+ if (v.length < MIN_SECRET_CHARS || !notATemplate(v) || algorithmValue(v)) return false;
2028
2102
  }
2029
2103
  if (r.ok && !r.ok(s$1.slice(a, b))) return false;
2030
2104
  return !r.at || r.at(s$1, a, b);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-privacy-gateway",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "Process-wide HTTP redaction gateway for DSH: masks secrets in outgoing model requests and restores placeholders in the replies, for every provider.",
6
6
  "icon": "./assets/icon.svg",