@mysterycode-liwen/dsh-credential-vault 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -15
- package/client.js +253 -17
- package/cordis.patch.yml +3 -3
- package/icon.svg +6 -6
- package/index.js +73 -98
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
A sidebar plugin for DeepSeek Harness that keeps accounts, passwords, API keys and recovery codes locally, plus an agent tool so the Harness can read them.
|
|
10
10
|
|
|
11
|
-
>
|
|
11
|
+
> 数据只留在本机:凭据明文只存在浏览器 `localStorage`,不上传、不同步。**Host 端只接收脱敏元数据,不落盘、不保存明文**。请勿在公用电脑上使用。
|
|
12
12
|
|
|
13
13
|
## 目录
|
|
14
14
|
|
|
@@ -72,8 +72,8 @@ dsh plugin --profile desktop why @mysterycode-liwen/dsh-credential-vault
|
|
|
72
72
|
- **密码生成器**:在账号密码字段旁点「⚙ 生成」,用加密安全随机数(Web Crypto)生成强密码,可设置长度与字符类型、避开易混淆字符,并实时显示强度;可直接填入表单或复制。(仅账号密码类提供,API Key / 其他类不显示)
|
|
73
73
|
- **健康审计**:点「🛡 健康审计」扫描全部凭据,列出弱密码 / 空密钥、重复使用、已过期 / 即将到期等问题并按严重程度排序,点击条目可直接跳转编辑。
|
|
74
74
|
- 登录网址 / Base URL 字段旁提供「访问」按钮,默认用 DeepSeek Harness 内置浏览器打开。
|
|
75
|
-
- 导入 / 导出:可把全部凭据导出为
|
|
76
|
-
- 设置页:访问密码开关、设置 /
|
|
75
|
+
- 导入 / 导出:可把全部凭据导出为 **加密备份 / JSON 备份 / CSV(Excel、WPS 可直接打开)/ Markdown 卡片**四种格式。**加密备份**用你设置的密码经 AES-GCM 加密全部明文,需密码才能导入,适合备份 / 迁移;JSON 保留全部字段(明文);CSV 用中文表头、常用列在前(明文);Markdown 每条凭据一张中文卡片(明文)。导入时自动识别格式,遇到加密备份会提示输入密码解密,并可选「合并(跳过重复 ID)」或「替换全部」。四种格式均可无损导回。
|
|
76
|
+
- 设置页:访问密码开关、设置 / 修改密码、密保问题重置、闲置自动锁定(可开关、可选时长)、**访问审计**(查看模型读取元数据的内存日志)、插件版本与检查更新。
|
|
77
77
|
|
|
78
78
|
## Agent 工具 / Agent tool
|
|
79
79
|
|
|
@@ -85,18 +85,20 @@ dsh plugin --profile desktop why @mysterycode-liwen/dsh-credential-vault
|
|
|
85
85
|
| `query` | string | 按标题、账号、平台、URL、备注做不区分大小写的子串过滤 |
|
|
86
86
|
| `category` | `"all"` \| `"account"` \| `"apikey"` \| `"other"` | 只返回某一类,默认 `all` |
|
|
87
87
|
| `limit` / `offset` | number | 分页,默认 20 条一页;条目多时先看 summary 再翻页 |
|
|
88
|
-
| `revealSecrets` | boolean |
|
|
88
|
+
| `revealSecrets` | boolean | **已废弃、无效**;保留仅为兼容旧调用。任何情况下密码 / API Key / 文本正文都只返回 `••••••••` |
|
|
89
89
|
|
|
90
|
-
Host
|
|
90
|
+
**安全边界**:浏览器同步给 Host 的是**脱敏元数据**(标题 / 分类 / 账号 / 平台 / URL / 备注等),密码 / API Key / 正文在浏览器端就被替换成 `••••••••`,明文从不进入模型上下文。Host 端也**不落盘**——快照只在内存中,重启后清空,等浏览器重新连接再同步。因此该工具只能用来「知道有哪些凭据」,不能用来「取明文」;需要看明文请到侧边栏面板操作。每次工具读取都会记入内存审计日志,可在设置页「访问审计」查看,或本机访问 `GET /dsh-credential-vault/audit`。
|
|
91
91
|
|
|
92
92
|
## 安全说明 / Security notice
|
|
93
93
|
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
- `dsh_credential_vault_read`
|
|
97
|
-
-
|
|
94
|
+
- 明文只存在浏览器 **localStorage**,不加密、不跨设备同步;Host 端**没有磁盘镜像**,快照仅存内存、重启即清空。请勿在公用 / 共享电脑上使用。
|
|
95
|
+
- 插件没有网络上传行为;浏览器→Host 的同步也只传脱敏元数据,密钥明文不出浏览器。
|
|
96
|
+
- `dsh_credential_vault_read` 永远把 `password` / `apiKey` / `content` 显示为 `••••••••`;`revealSecrets` 参数已失效,明文不会进入模型上下文。
|
|
97
|
+
- **加密备份导出**用你设置的密码(PBKDF2-SHA256 派生密钥 + AES-GCM)加密全部明文,文件里不含明文;密码不会被存储,丢失则无法恢复,请务必牢记。导入时在本机浏览器内解密。
|
|
98
|
+
- **完整导出(JSON / CSV / Markdown)包含明文密码 / API Key**:请像对待密码本身一样妥善保管,用完及时删除;跨平台 / 异地备份优先用加密备份。导入仅在本机浏览器内进行。
|
|
99
|
+
- 访问审计为**内存环形日志**(最多 200 条),只记录工具名 / 操作 / 查询条件 / 条数等元数据,不含明文,重启后清空。
|
|
98
100
|
- Host 工具的注册发生在 Harness 启动时:首次安装后请**重启 Harness 或在插件管理里关闭再启用**该插件。
|
|
99
|
-
-
|
|
101
|
+
- 访问密码与闲置锁定是**界面层**保护;明文仍在浏览器 localStorage 中,如需驱动器级加密请用 BitLocker / FileVault 之类的手段。
|
|
100
102
|
|
|
101
103
|
## 常见问题 / FAQ
|
|
102
104
|
|
|
@@ -107,13 +109,14 @@ Host 端把浏览器同步过来的快照写到 `~/.dsh/dsh-credential-vault/vau
|
|
|
107
109
|
Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理里把本插件关闭再启用。
|
|
108
110
|
|
|
109
111
|
**数据存在哪?换机器/重装会丢吗?**
|
|
110
|
-
|
|
112
|
+
明文只存在浏览器 `localStorage`;Host 端只有内存中的脱敏快照(重启即清空,不再有 `vault.json` 镜像文件)。换机器不会自动带过去,请用「导出 → 加密备份」生成加密文件(记好密码),再到新机器导入并输入同一密码解密。
|
|
111
113
|
|
|
112
114
|
**导出该选哪种格式?Excel 打开 CSV 会乱码吗?**
|
|
113
|
-
-
|
|
114
|
-
- **
|
|
115
|
-
- **
|
|
116
|
-
|
|
115
|
+
- **加密备份(推荐用于备份 / 迁移)**:全部明文用你设置的密码经 AES-GCM 加密,文件内不含明文;密码不存储、丢失不可恢复。导入时输入同一密码解密,无损还原。
|
|
116
|
+
- **JSON**:字段最完整,含明文,适合本机短期中转(妥善保管,用完删除)。
|
|
117
|
+
- **CSV**:带 UTF-8 BOM,Excel / WPS 双击即可正确显示中文;中文表头、常用列在前,ID / 时间戳等放在最后,适合表格查看与批量编辑(含明文)。
|
|
118
|
+
- **Markdown**:每条凭据一张卡片、中文标签两列表,空字段自动省略,方便阅读、贴到文档或做版本管理;完整数据以 HTML 注释内嵌,导入时无损还原(含明文)。
|
|
119
|
+
导入时会自动识别加密备份 / JSON / CSV / Markdown 四种格式(也兼容旧版英文表头的 CSV 与宽表格 Markdown);加密备份会先提示输入密码,无需手动选择格式。
|
|
117
120
|
|
|
118
121
|
**支持多设备同步吗?**
|
|
119
122
|
不支持,也不打算支持——本插件的定位就是「不上云的本机保险箱」。
|
|
@@ -123,6 +126,15 @@ Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理
|
|
|
123
126
|
|
|
124
127
|
## 更新日志 / Changelog
|
|
125
128
|
|
|
129
|
+
### 1.4.3 — 2026-11-23 — 安全加固
|
|
130
|
+
|
|
131
|
+
- **明文不再落盘**:移除 Host 端 `vault.json` 镜像与相关迁移逻辑,内存快照重启即清空。
|
|
132
|
+
- **脱敏同步**:浏览器→Host 只传元数据,密码 / API Key / 正文在浏览器端即替换为 `••••••••`;Host 端再次强制脱敏(纵深防御)。
|
|
133
|
+
- **工具只读元数据**:`dsh_credential_vault_read` 永不返回明文,`revealSecrets` 参数失效;系统提示同步说明。
|
|
134
|
+
- **关闭调试端点**:`GET /entries` 返回 404,不再暴露 Host 内存快照。
|
|
135
|
+
- **访问审计**:内存环形日志(最多 200 条,无明文),设置页可查看,或本机 `GET /dsh-credential-vault/audit`。
|
|
136
|
+
- **加密导出 / 解密导入**:新增「加密备份」导出格式,用密码经 PBKDF2-SHA256(21 万次迭代)派生 AES-GCM 密钥加密全部明文;导入时自动识别并提示输入密码解密,密码错误 / 文件损坏给出明确提示。文件不含明文,密码不存储、丢失不可恢复。
|
|
137
|
+
|
|
126
138
|
### 1.4.2 — 2026-11-22
|
|
127
139
|
|
|
128
140
|
- **字段过滤**:导入 / 加载 / 导出时统一按凭据类型清理字段,API Key 记录若残留账号类的「用户名 / 密码 / 网址」会被自动剔除,不再出现在卡片或导出文件中。
|
package/client.js
CHANGED
|
@@ -15,7 +15,7 @@ window.__ModuleLoader__.load({
|
|
|
15
15
|
// whatever port the Web GUI is on.
|
|
16
16
|
var API = 'dsh-credential-vault/';
|
|
17
17
|
/** Plugin version shown in Settings; keep in sync with package.json on release. */
|
|
18
|
-
var VERSION = '1.4.
|
|
18
|
+
var VERSION = '1.4.3';
|
|
19
19
|
|
|
20
20
|
// Compare two semver-ish strings: -1 (left older), 0 (equal), 1 (left newer).
|
|
21
21
|
// Used to decide "update available" against THIS client's version, so the
|
|
@@ -91,6 +91,8 @@ window.__ModuleLoader__.load({
|
|
|
91
91
|
resetSubmit: 'Reset password', resetFail: 'That answer does not match.', resetDone: 'Password has been reset. Please unlock again.',
|
|
92
92
|
resetUnavailable: 'No security question is configured. Restore from a backup or clear this browser\'s site data.',
|
|
93
93
|
lockIdle: 'Locked after inactivity',
|
|
94
|
+
auditTitle: 'Access audit', auditDesc: 'In-memory log of agent reads of your vault metadata. No secrets or plaintext are ever recorded; cleared on restart.',
|
|
95
|
+
auditView: 'View log', auditLoading: 'Loading…', auditTotal: 'Total events', auditEmpty: 'No accesses recorded yet.', auditFail: 'Audit log is unavailable.',
|
|
94
96
|
updateTitle: 'Plugin updates', updateDesc: 'Check whether a newer version of the dsh-credential-vault plugin is available.',
|
|
95
97
|
updateCurrent: 'Current version', updateLatest: 'Latest version', updateCheck: 'Check for updates',
|
|
96
98
|
updateChecking: 'Checking…', updateAvailable: 'A newer version is available:', updateUpToDate: 'You are up to date.',
|
|
@@ -117,6 +119,14 @@ window.__ModuleLoader__.load({
|
|
|
117
119
|
exportFormat: 'Export format', exportJson: 'JSON backup', exportJsonHint: 'Full fidelity — restores every field exactly (recommended).',
|
|
118
120
|
exportCsv: 'CSV for Excel / WPS', exportCsvHint: 'Chinese headers, readable order, UTF-8 with BOM.',
|
|
119
121
|
exportMd: 'Markdown cards', exportMdHint: 'One card per entry with Chinese labels — clean and readable.',
|
|
122
|
+
exportEncrypted: 'Encrypted backup (password)', exportEncryptedHint: 'Full backup with secrets, sealed by AES-GCM with a password you choose. Import asks for the same password.',
|
|
123
|
+
exportEncryptedGo: 'Encrypt & download', exportEncryptedDone: 'Encrypted backup downloaded — keep your password safe, it cannot be recovered.',
|
|
124
|
+
encPwHint: 'Choose a strong password. It is never stored — losing it means the backup cannot be restored.',
|
|
125
|
+
encPw: 'Encryption password', encPw2: 'Confirm password', encPwShort: 'Use at least 6 characters.',
|
|
126
|
+
encPwMismatch: 'Passwords do not match.', encPwRequired: 'Enter the password.',
|
|
127
|
+
encBusy: 'Working…', encNoCrypto: 'This browser does not support the required encryption (Web Crypto).',
|
|
128
|
+
encDetected: 'Encrypted backup detected', encImportHint: 'Enter the password used when exporting to decrypt this backup.',
|
|
129
|
+
encUnlock: 'Decrypt', encWrongPw: 'Wrong password or corrupted file.',
|
|
120
130
|
genButton: 'Generate password', genField: 'Generate a password for this field',
|
|
121
131
|
genTitle: 'Password generator', genHint: 'Generates a strong random password using your browser’s cryptographic random source. Nothing is stored or sent anywhere.',
|
|
122
132
|
genLength: 'Length', genUpper: 'Uppercase (A–Z)', genLower: 'Lowercase (a–z)', genDigits: 'Digits (0–9)',
|
|
@@ -194,6 +204,8 @@ window.__ModuleLoader__.load({
|
|
|
194
204
|
resetSubmit: '重置密码', resetFail: '密保答案不匹配。', resetDone: '密码已重置,请重新解锁。',
|
|
195
205
|
resetUnavailable: '尚未设置密保问题。请从备份恢复,或清除此浏览器的站点数据。',
|
|
196
206
|
lockIdle: '因长时间无操作已锁定',
|
|
207
|
+
auditTitle: '访问审计', auditDesc: '记录模型读取保险箱元数据的内存日志,不含任何密钥或明文,重启后清空。',
|
|
208
|
+
auditView: '查看日志', auditLoading: '加载中…', auditTotal: '事件总数', auditEmpty: '暂无访问记录。', auditFail: '访问审计不可用。',
|
|
197
209
|
updateTitle: '插件更新', updateDesc: '检查凭据保险箱插件是否有新版本可用。',
|
|
198
210
|
updateCurrent: '当前版本', updateLatest: '最新版本', updateCheck: '检查更新',
|
|
199
211
|
updateChecking: '检查中…', updateAvailable: '发现新版本:', updateUpToDate: '已是最新版本。',
|
|
@@ -220,6 +232,14 @@ window.__ModuleLoader__.load({
|
|
|
220
232
|
exportFormat: '导出格式', exportJson: 'JSON 备份', exportJsonHint: '完整保真,可精确恢复全部字段(推荐)。',
|
|
221
233
|
exportCsv: 'CSV(Excel / WPS)', exportCsvHint: '中文表头、常用列在前,UTF-8 BOM 编码。',
|
|
222
234
|
exportMd: 'Markdown 卡片', exportMdHint: '每条凭据一张卡片、中文标签,一目了然。',
|
|
235
|
+
exportEncrypted: '加密备份(密码保护)', exportEncryptedHint: '包含密钥的完整备份,用你设置的密码经 AES-GCM 加密。导入时需输入同一密码。',
|
|
236
|
+
exportEncryptedGo: '加密并下载', exportEncryptedDone: '加密备份已下载 — 请牢记密码,丢失后无法恢复。',
|
|
237
|
+
encPwHint: '请设置高强度密码。密码不会被存储 — 丢失后备份将无法恢复。',
|
|
238
|
+
encPw: '加密密码', encPw2: '确认密码', encPwShort: '密码至少 6 个字符。',
|
|
239
|
+
encPwMismatch: '两次输入的密码不一致。', encPwRequired: '请输入密码。',
|
|
240
|
+
encBusy: '处理中…', encNoCrypto: '当前浏览器不支持所需的加密功能(Web Crypto)。',
|
|
241
|
+
encDetected: '检测到加密备份', encImportHint: '输入导出时设置的密码以解密此备份。',
|
|
242
|
+
encUnlock: '解密', encWrongPw: '密码错误或文件已损坏。',
|
|
223
243
|
genButton: '生成密码', genField: '为此字段生成密码',
|
|
224
244
|
genTitle: '密码生成器', genHint: '使用浏览器的加密随机源生成高强度随机密码,不会存储或上传任何数据。',
|
|
225
245
|
genLength: '长度', genUpper: '大写字母 (A–Z)', genLower: '小写字母 (a–z)', genDigits: '数字 (0–9)',
|
|
@@ -404,6 +424,11 @@ window.__ModuleLoader__.load({
|
|
|
404
424
|
'.cv-upgrade-status{margin-top:10px;font-size:12.5px;color:var(--cv-t2);line-height:1.6}',
|
|
405
425
|
'.cv-upgrade-status.cv-ok{color:var(--cv-ok)}',
|
|
406
426
|
'.cv-upgrade-status.cv-err{color:var(--cv-err)}',
|
|
427
|
+
'.cv-audit-list{margin-top:10px;max-height:220px;overflow:auto;border:1px solid var(--cv-b1);border-radius:8px}',
|
|
428
|
+
'.cv-audit-row{display:flex;gap:10px;padding:7px 10px;border-bottom:1px solid var(--cv-b1);font-size:12px;line-height:1.4}',
|
|
429
|
+
'.cv-audit-row:last-child{border-bottom:0}',
|
|
430
|
+
'.cv-audit-time{color:var(--cv-t2);white-space:nowrap;font-variant-numeric:tabular-nums}',
|
|
431
|
+
'.cv-audit-detail{color:var(--cv-t1);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
407
432
|
'.cv-switch-row{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:12px 0;border-top:1px solid var(--cv-b1)}',
|
|
408
433
|
'.cv-switch-row:first-of-type{border-top:none}',
|
|
409
434
|
'.cv-switch-label{font-size:13.5px;font-weight:550}',
|
|
@@ -418,6 +443,7 @@ window.__ModuleLoader__.load({
|
|
|
418
443
|
'.cv-note-err{background:rgba(239,68,68,.12);color:var(--cv-err);border:1px solid rgba(239,68,68,.4)}',
|
|
419
444
|
'@keyframes cv-note-in{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}',
|
|
420
445
|
'.cv-field-error{color:var(--cv-err);font-size:12px;margin-top:2px}',
|
|
446
|
+
'.cv-enc-fields{display:flex;flex-direction:column;gap:8px;margin:14px 22px 4px;padding:13px;border-radius:9px;background:var(--cv-l1);border:1px solid var(--cv-b1)}',
|
|
421
447
|
'.cv-settings-fields{display:flex;flex-direction:column;gap:12px;margin-top:12px}',
|
|
422
448
|
// Password generator
|
|
423
449
|
'.cv-gen-secret{display:flex;gap:6px;align-items:stretch}',
|
|
@@ -486,11 +512,27 @@ window.__ModuleLoader__.load({
|
|
|
486
512
|
try { window.localStorage.setItem(STORAGE_KEY, JSON.stringify(arr)); } catch (e) {}
|
|
487
513
|
syncToHost(arr);
|
|
488
514
|
}
|
|
489
|
-
// Mirror
|
|
490
|
-
// dsh_credential_vault_read
|
|
491
|
-
//
|
|
515
|
+
// Mirror only METADATA to the Host so the Harness/Agent can discover which
|
|
516
|
+
// credentials exist via dsh_credential_vault_read. Plaintext secrets stay in
|
|
517
|
+
// this browser's localStorage and are NEVER sent to the Host process. The
|
|
518
|
+
// Host independently re-sanitizes every entry, so this is defense in depth.
|
|
519
|
+
// Fire-and-forget: the browser stays usable even if the Host route is down.
|
|
492
520
|
// Large vaults: DEBOUNCE so a burst of edits results in one POST, not dozens
|
|
493
521
|
// of multi-megabyte payloads. A trailing timer always flushes the latest data.
|
|
522
|
+
var MIRROR_FIELDS = ['id', 'title', 'category', 'username', 'provider', 'url', 'endpoint', 'expiry', 'notes', 'createdAt', 'updatedAt'];
|
|
523
|
+
var MIRROR_SECRETS = ['password', 'apiKey', 'content'];
|
|
524
|
+
function toEnvelope(entry) {
|
|
525
|
+
var out = {};
|
|
526
|
+
MIRROR_FIELDS.forEach(function (k) {
|
|
527
|
+
var v = entry[k];
|
|
528
|
+
if (typeof v === 'string' || typeof v === 'number') out[k] = v;
|
|
529
|
+
});
|
|
530
|
+
// Placeholder only — the real value never leaves this browser.
|
|
531
|
+
MIRROR_SECRETS.forEach(function (k) {
|
|
532
|
+
if (typeof entry[k] === 'string' && entry[k] !== '') out[k] = MASK;
|
|
533
|
+
});
|
|
534
|
+
return out;
|
|
535
|
+
}
|
|
494
536
|
var syncTimer = null;
|
|
495
537
|
var SYNC_DELAY = 400;
|
|
496
538
|
function syncToHost(arr, immediate) {
|
|
@@ -498,11 +540,12 @@ window.__ModuleLoader__.load({
|
|
|
498
540
|
function send() {
|
|
499
541
|
syncTimer = null;
|
|
500
542
|
try {
|
|
543
|
+
var envelope = arr.map(toEnvelope);
|
|
501
544
|
window.fetch(API + 'entries', {
|
|
502
545
|
method: 'POST',
|
|
503
546
|
credentials: 'same-origin',
|
|
504
547
|
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
505
|
-
body: JSON.stringify({ entries:
|
|
548
|
+
body: JSON.stringify({ entries: envelope })
|
|
506
549
|
}).catch(function () {});
|
|
507
550
|
} catch (e) {}
|
|
508
551
|
}
|
|
@@ -926,16 +969,113 @@ window.__ModuleLoader__.load({
|
|
|
926
969
|
if (fmt === 'md') return downloadText(buildMarkdown(arr), 'text/markdown;charset=utf-8', '凭据保险箱-' + stampNow() + '.md');
|
|
927
970
|
return exportBackup(arr);
|
|
928
971
|
}
|
|
972
|
+
// Encrypted export: full backup (secrets included) sealed with a password.
|
|
973
|
+
// Async because key derivation is Web Crypto. Resolves true on download.
|
|
974
|
+
function exportEncrypted(arr, password) {
|
|
975
|
+
if (!arr || arr.length === 0) return Promise.resolve(false);
|
|
976
|
+
return encryptBackup(arr, password).then(function (envelope) {
|
|
977
|
+
return downloadText(JSON.stringify(envelope, null, 2), 'application/json;charset=utf-8',
|
|
978
|
+
'凭据保险箱-加密-' + stampNow() + '.vault.json');
|
|
979
|
+
});
|
|
980
|
+
}
|
|
929
981
|
// Returns entries array or throws a recognisable error (JSON backups only).
|
|
930
982
|
function parseBackup(text) {
|
|
931
983
|
var data;
|
|
932
984
|
try { data = JSON.parse(text); } catch (e) { throw new Error('parse'); }
|
|
985
|
+
// An encrypted envelope is not a plain backup — surface a clear signal so
|
|
986
|
+
// the import UI can prompt for the password instead of treating it as data.
|
|
987
|
+
if (data && data.format === ENC_FORMAT) throw new Error('ENCRYPTED');
|
|
933
988
|
var arr = null;
|
|
934
989
|
if (data && Array.isArray(data.entries)) arr = data.entries;
|
|
935
990
|
else if (Array.isArray(data)) arr = data; // tolerate a bare array
|
|
936
991
|
if (!arr) throw new Error('shape');
|
|
937
992
|
return arr.filter(function (e) { return e && typeof e === 'object'; }).map(normalize);
|
|
938
993
|
}
|
|
994
|
+
|
|
995
|
+
// ---- Encrypted backup (PBKDF2 + AES-GCM, Web Crypto) ------------------
|
|
996
|
+
// The whole plaintext backup (secrets included) is encrypted with a key
|
|
997
|
+
// derived from a user-supplied password. Nothing about the password or the
|
|
998
|
+
// plaintext is stored in this file; losing the password means losing the
|
|
999
|
+
// backup. Uses only platform Web Crypto — no third-party libraries.
|
|
1000
|
+
var ENC_FORMAT = 'dsh-credential-vault-encrypted';
|
|
1001
|
+
var ENC_VERSION = 1;
|
|
1002
|
+
var KDF_ITERATIONS = 210000;
|
|
1003
|
+
function bytesToB64(bytes) {
|
|
1004
|
+
var out = '';
|
|
1005
|
+
var chunk = 0x8000;
|
|
1006
|
+
for (var i = 0; i < bytes.length; i += chunk) {
|
|
1007
|
+
var part = Array.prototype.slice.call(bytes, i, Math.min(i + chunk, bytes.length));
|
|
1008
|
+
out += String.fromCharCode.apply(null, part);
|
|
1009
|
+
}
|
|
1010
|
+
return btoa(out);
|
|
1011
|
+
}
|
|
1012
|
+
function b64ToBytes(b64) {
|
|
1013
|
+
var s = atob(String(b64));
|
|
1014
|
+
var out = new Uint8Array(s.length);
|
|
1015
|
+
for (var i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
|
|
1016
|
+
return out;
|
|
1017
|
+
}
|
|
1018
|
+
function deriveEncKey(password, salt, iterations) {
|
|
1019
|
+
var subtle = window.crypto && window.crypto.subtle;
|
|
1020
|
+
if (!subtle) return Promise.reject(new Error('NO_CRYPTO'));
|
|
1021
|
+
var enc = new TextEncoder();
|
|
1022
|
+
return subtle.importKey('raw', enc.encode(String(password)), 'PBKDF2', false, ['deriveKey'])
|
|
1023
|
+
.then(function (baseKey) {
|
|
1024
|
+
return subtle.deriveKey(
|
|
1025
|
+
{ name: 'PBKDF2', salt: salt, iterations: iterations, hash: 'SHA-256' },
|
|
1026
|
+
baseKey,
|
|
1027
|
+
{ name: 'AES-GCM', length: 256 },
|
|
1028
|
+
false,
|
|
1029
|
+
['encrypt', 'decrypt']
|
|
1030
|
+
);
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
// Resolve to a JSON-serialisable encrypted envelope.
|
|
1034
|
+
function encryptBackup(arr, password) {
|
|
1035
|
+
if (!password || !String(password)) return Promise.reject(new Error('EMPTY_PASSWORD'));
|
|
1036
|
+
var subtle = window.crypto && window.crypto.subtle;
|
|
1037
|
+
if (!subtle || !window.crypto.getRandomValues) return Promise.reject(new Error('NO_CRYPTO'));
|
|
1038
|
+
var plaintext = JSON.stringify(buildBackup(arr));
|
|
1039
|
+
var salt = new Uint8Array(16), iv = new Uint8Array(12);
|
|
1040
|
+
window.crypto.getRandomValues(salt);
|
|
1041
|
+
window.crypto.getRandomValues(iv);
|
|
1042
|
+
return deriveEncKey(password, salt, KDF_ITERATIONS).then(function (key) {
|
|
1043
|
+
return subtle.encrypt({ name: 'AES-GCM', iv: iv }, key, new TextEncoder().encode(plaintext));
|
|
1044
|
+
}).then(function (buf) {
|
|
1045
|
+
return {
|
|
1046
|
+
format: ENC_FORMAT, version: ENC_VERSION, kdf: 'PBKDF2-SHA256',
|
|
1047
|
+
iterations: KDF_ITERATIONS,
|
|
1048
|
+
salt: bytesToB64(salt), iv: bytesToB64(iv), cipherText: bytesToB64(new Uint8Array(buf))
|
|
1049
|
+
};
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
// Resolve to an entries array (decrypted + normalised), or reject with a
|
|
1053
|
+
// recognisable error: WRONG_PASSWORD / NOT_ENCRYPTED / NO_CRYPTO.
|
|
1054
|
+
function decryptBackup(envelope, password) {
|
|
1055
|
+
if (!envelope || envelope.format !== ENC_FORMAT) return Promise.reject(new Error('NOT_ENCRYPTED'));
|
|
1056
|
+
if (!password || !String(password)) return Promise.reject(new Error('EMPTY_PASSWORD'));
|
|
1057
|
+
var subtle = window.crypto && window.crypto.subtle;
|
|
1058
|
+
if (!subtle) return Promise.reject(new Error('NO_CRYPTO'));
|
|
1059
|
+
var salt = b64ToBytes(envelope.salt), iv = b64ToBytes(envelope.iv);
|
|
1060
|
+
var cipher = b64ToBytes(envelope.cipherText);
|
|
1061
|
+
var iterations = envelope.iterations || KDF_ITERATIONS;
|
|
1062
|
+
return deriveEncKey(password, salt, iterations).then(function (key) {
|
|
1063
|
+
return subtle.decrypt({ name: 'AES-GCM', iv: iv }, key, cipher);
|
|
1064
|
+
}).then(function (buf) {
|
|
1065
|
+
return parseBackup(new TextDecoder().decode(buf));
|
|
1066
|
+
}).catch(function (e) {
|
|
1067
|
+
if (e && (e.message === 'NOT_ENCRYPTED' || e.message === 'EMPTY_PASSWORD' || e.message === 'NO_CRYPTO')) throw e;
|
|
1068
|
+
throw new Error('WRONG_PASSWORD');
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
// Detect an encrypted envelope in raw imported text. Returns the envelope
|
|
1072
|
+
// object or null.
|
|
1073
|
+
function detectEncrypted(text) {
|
|
1074
|
+
try {
|
|
1075
|
+
var data = JSON.parse(String(text || '').replace(/^\uFEFF/, ''));
|
|
1076
|
+
return data && data.format === ENC_FORMAT ? data : null;
|
|
1077
|
+
} catch (e) { return null; }
|
|
1078
|
+
}
|
|
939
1079
|
// ---- Access-password security store ---------------------------------
|
|
940
1080
|
var SEC_KEY = '@local/dsh-credential-vault:security:v1';
|
|
941
1081
|
var SEC_KEY_LEGACY = '@local/credential-vault:security:v1';
|
|
@@ -1323,17 +1463,23 @@ window.__ModuleLoader__.load({
|
|
|
1323
1463
|
var errState = useState(''), err = errState[0], setErr = errState[1];
|
|
1324
1464
|
var inputRef = useState({})[0];
|
|
1325
1465
|
var detectedState = useState(''), detected = detectedState[0], setDetected = detectedState[1];
|
|
1466
|
+
var encState = useState(null), encEnv = encState[0], setEncEnv = encState[1];
|
|
1467
|
+
var encPwState = useState(''), encPw = encPwState[0], setEncPw = encPwState[1];
|
|
1468
|
+
var encBusyState = useState(false), encBusy = encBusyState[0], setEncBusy = encBusyState[1];
|
|
1326
1469
|
|
|
1327
1470
|
function onFile(ev) {
|
|
1328
1471
|
var f = ev.target.files && ev.target.files[0];
|
|
1329
1472
|
if (!f) return;
|
|
1330
|
-
setErr(''); setPending(null); setDetected('');
|
|
1473
|
+
setErr(''); setPending(null); setDetected(''); setEncEnv(null); setEncPw('');
|
|
1331
1474
|
setFileInfo({ name: f.name, size: f.size });
|
|
1332
1475
|
if (typeof FileReader === 'undefined') { setErr(t('importInvalid')); return; }
|
|
1333
1476
|
var reader = new FileReader();
|
|
1334
1477
|
reader.onload = function () {
|
|
1478
|
+
var text = String(reader.result || '');
|
|
1479
|
+
var env = detectEncrypted(text);
|
|
1480
|
+
if (env) { setEncEnv(env); setDetected('enc'); return; }
|
|
1335
1481
|
try {
|
|
1336
|
-
var res = parseImport(
|
|
1482
|
+
var res = parseImport(text);
|
|
1337
1483
|
setPending(res.entries);
|
|
1338
1484
|
setDetected(res.fmt);
|
|
1339
1485
|
if (res.entries.length === 0) setErr(t('importEmpty'));
|
|
@@ -1342,6 +1488,20 @@ window.__ModuleLoader__.load({
|
|
|
1342
1488
|
reader.onerror = function () { setErr(t('importInvalid')); setPending(null); };
|
|
1343
1489
|
reader.readAsText(f, 'utf-8');
|
|
1344
1490
|
}
|
|
1491
|
+
function decrypt() {
|
|
1492
|
+
if (!encEnv) return;
|
|
1493
|
+
if (!encPw) { setErr(t('encPwRequired')); return; }
|
|
1494
|
+
setErr(''); setEncBusy(true);
|
|
1495
|
+
decryptBackup(encEnv, encPw).then(function (arr) {
|
|
1496
|
+
setEncBusy(false);
|
|
1497
|
+
setPending(arr); setEncEnv(null); setEncPw(''); setDetected('json');
|
|
1498
|
+
if (arr.length === 0) setErr(t('importEmpty'));
|
|
1499
|
+
}).catch(function (e) {
|
|
1500
|
+
setEncBusy(false);
|
|
1501
|
+
var m = e && e.message;
|
|
1502
|
+
setErr(m === 'WRONG_PASSWORD' ? t('encWrongPw') : m === 'NO_CRYPTO' ? t('encNoCrypto') : t('importInvalid'));
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1345
1505
|
function submit() {
|
|
1346
1506
|
if (!pending || pending.length === 0) { setErr(t('importEmpty')); return; }
|
|
1347
1507
|
props.onImport(pending, mode);
|
|
@@ -1360,10 +1520,17 @@ window.__ModuleLoader__.load({
|
|
|
1360
1520
|
h('button', { type: 'button', className: 'cv-btn', onClick: function () { if (inputRef.el) inputRef.el.click(); } },
|
|
1361
1521
|
fileInfo ? '📄 ' + fileInfo.name : t('import')),
|
|
1362
1522
|
fileInfo ? h('div', { className: 'cv-import-file' },
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
h('div', { className: 'cv-
|
|
1523
|
+
encEnv ? t('encDetected')
|
|
1524
|
+
: t('importFound') + ':' + (pending ? pending.length : '…') +
|
|
1525
|
+
(detected ? ' · ' + t('importDetected') + ':' + t('fmt' + detected.charAt(0).toUpperCase() + detected.slice(1)) : '')) : null,
|
|
1526
|
+
encEnv ? h('div', { className: 'cv-enc-fields' },
|
|
1527
|
+
h('div', { className: 'cv-card-sub' }, t('encImportHint')),
|
|
1528
|
+
h('input', { type: 'password', className: 'cv-input', placeholder: t('encPw'), value: encPw, autoComplete: 'off',
|
|
1529
|
+
onChange: function (e) { setEncPw(e.target.value); },
|
|
1530
|
+
onKeyDown: function (e) { if (e.key === 'Enter') decrypt(); } })
|
|
1531
|
+
) : null,
|
|
1532
|
+
encEnv ? null : h('div', { className: 'cv-form-label' }, t('importMode')),
|
|
1533
|
+
encEnv ? null : h('div', { className: 'cv-import-modes' },
|
|
1367
1534
|
h('label', { className: 'cv-import-opt' },
|
|
1368
1535
|
h('input', { type: 'radio', name: 'cv-import-mode', checked: mode === 'merge', onChange: function () { setMode('merge'); } }),
|
|
1369
1536
|
h('div', null,
|
|
@@ -1383,7 +1550,9 @@ window.__ModuleLoader__.load({
|
|
|
1383
1550
|
),
|
|
1384
1551
|
h('div', { className: 'cv-modal-foot' },
|
|
1385
1552
|
h('button', { className: 'cv-btn', onClick: props.onCancel }, t('cancel')),
|
|
1386
|
-
|
|
1553
|
+
encEnv
|
|
1554
|
+
? h('button', { className: 'cv-btn cv-btn-primary', disabled: encBusy, onClick: decrypt }, encBusy ? t('encBusy') : t('encUnlock'))
|
|
1555
|
+
: h('button', { className: 'cv-btn cv-btn-primary', disabled: !pending || pending.length === 0, onClick: submit }, t('importConfirm'))
|
|
1387
1556
|
)
|
|
1388
1557
|
)
|
|
1389
1558
|
);
|
|
@@ -1391,11 +1560,34 @@ window.__ModuleLoader__.load({
|
|
|
1391
1560
|
|
|
1392
1561
|
function ExportModal(props) {
|
|
1393
1562
|
var t = props.t;
|
|
1563
|
+
var encState = useState(false), enc = encState[0], setEnc = encState[1];
|
|
1564
|
+
var pwState = useState(''), pw = pwState[0], setPw = pwState[1];
|
|
1565
|
+
var pw2State = useState(''), pw2 = pw2State[0], setPw2 = pw2State[1];
|
|
1566
|
+
var errState = useState(''), err = errState[0], setErr = errState[1];
|
|
1567
|
+
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1];
|
|
1394
1568
|
var fmts = [
|
|
1569
|
+
{ k: 'enc', name: 'exportEncrypted', hint: 'exportEncryptedHint', icon: '🔐' },
|
|
1395
1570
|
{ k: 'json', name: 'exportJson', hint: 'exportJsonHint', icon: '📦' },
|
|
1396
1571
|
{ k: 'csv', name: 'exportCsv', hint: 'exportCsvHint', icon: '📊' },
|
|
1397
1572
|
{ k: 'md', name: 'exportMd', hint: 'exportMdHint', icon: '📝' }
|
|
1398
1573
|
];
|
|
1574
|
+
function pick(f) {
|
|
1575
|
+
if (f.k !== 'enc') { props.onPick(f.k); return; }
|
|
1576
|
+
setErr(''); setEnc(true);
|
|
1577
|
+
}
|
|
1578
|
+
function doEncrypted() {
|
|
1579
|
+
if (!pw || pw.length < 6) { setErr(t('encPwShort')); return; }
|
|
1580
|
+
if (pw !== pw2) { setErr(t('encPwMismatch')); return; }
|
|
1581
|
+
setErr(''); setBusy(true);
|
|
1582
|
+
props.onEncrypted(pw).then(function (ok) {
|
|
1583
|
+
setBusy(false);
|
|
1584
|
+
if (ok) { setPw(''); setPw2(''); props.onDone(); }
|
|
1585
|
+
else setErr(t('exportFail'));
|
|
1586
|
+
}).catch(function (e) {
|
|
1587
|
+
setBusy(false);
|
|
1588
|
+
setErr(e && e.message === 'NO_CRYPTO' ? t('encNoCrypto') : t('exportFail'));
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1399
1591
|
return h('div', { className: 'cv-modal-backdrop', onMouseDown: function (e) { if (e.target === e.currentTarget) props.onCancel(); } },
|
|
1400
1592
|
h('div', { className: 'cv-modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': t('exportTitle'), tabIndex: -1,
|
|
1401
1593
|
onKeyDown: function (e) { if (e.key === 'Escape') props.onCancel(); } },
|
|
@@ -1404,17 +1596,24 @@ window.__ModuleLoader__.load({
|
|
|
1404
1596
|
h('div', { className: 'cv-modal-body' },
|
|
1405
1597
|
h('div', { className: 'cv-form-label' }, t('exportFormat')),
|
|
1406
1598
|
h('div', { className: 'cv-import-modes' }, fmts.map(function (f) {
|
|
1407
|
-
return h('button', { type: 'button', key: f.k, className: 'cv-import-opt cv-export-opt', onClick: function () {
|
|
1599
|
+
return h('button', { type: 'button', key: f.k, className: 'cv-import-opt cv-export-opt', onClick: function () { pick(f); } },
|
|
1408
1600
|
h('span', { className: 'cv-export-icon' }, f.icon),
|
|
1409
1601
|
h('div', null,
|
|
1410
1602
|
h('div', { className: 'cv-import-opt-name' }, t(f.name)),
|
|
1411
1603
|
h('div', { className: 'cv-import-opt-hint' }, t(f.hint))
|
|
1412
1604
|
)
|
|
1413
1605
|
);
|
|
1414
|
-
}))
|
|
1606
|
+
})),
|
|
1607
|
+
enc ? h('div', { className: 'cv-enc-fields' },
|
|
1608
|
+
h('div', { className: 'cv-card-sub' }, t('encPwHint')),
|
|
1609
|
+
h('input', { type: 'password', className: 'cv-input', placeholder: t('encPw'), value: pw, autoComplete: 'new-password', onChange: function (e) { setPw(e.target.value); } }),
|
|
1610
|
+
h('input', { type: 'password', className: 'cv-input', placeholder: t('encPw2'), value: pw2, autoComplete: 'new-password', onChange: function (e) { setPw2(e.target.value); } })
|
|
1611
|
+
) : null,
|
|
1612
|
+
err ? h('div', { className: 'cv-field-error', role: 'alert' }, err) : null
|
|
1415
1613
|
),
|
|
1416
1614
|
h('div', { className: 'cv-modal-foot' },
|
|
1417
|
-
h('button', { className: 'cv-btn', onClick: props.onCancel }, t('cancel'))
|
|
1615
|
+
h('button', { className: 'cv-btn', onClick: props.onCancel }, t('cancel')),
|
|
1616
|
+
enc ? h('button', { className: 'cv-btn cv-btn-primary', disabled: busy, onClick: doEncrypted }, busy ? t('encBusy') : t('exportEncryptedGo')) : null
|
|
1418
1617
|
)
|
|
1419
1618
|
)
|
|
1420
1619
|
);
|
|
@@ -1485,6 +1684,8 @@ window.__ModuleLoader__.load({
|
|
|
1485
1684
|
var upgradingState = useState(false), upgrading = upgradingState[0], setUpgrading = upgradingState[1];
|
|
1486
1685
|
var upgradeMsgState = useState(null), upgradeMsg = upgradeMsgState[0], setUpgradeMsg = upgradeMsgState[1];
|
|
1487
1686
|
var upgradeConfirmState = useState(null), upgradeConfirmDlg = upgradeConfirmState[0], setUpgradeConfirmDlg = upgradeConfirmState[1];
|
|
1687
|
+
var auditState = useState(null), auditData = auditState[0], setAudit = auditState[1];
|
|
1688
|
+
var auditLoadingState = useState(false), auditLoading = auditLoadingState[0], setAuditLoading = auditLoadingState[1];
|
|
1488
1689
|
var pollRef = useRef(null);
|
|
1489
1690
|
// Inline card messages: shown inside the settings card where the action
|
|
1490
1691
|
// happened, so feedback lands exactly where the user is looking.
|
|
@@ -1499,6 +1700,15 @@ window.__ModuleLoader__.load({
|
|
|
1499
1700
|
return function () { if (pollRef.current) { clearTimeout(pollRef.current); pollRef.current = null; } };
|
|
1500
1701
|
}, []);
|
|
1501
1702
|
|
|
1703
|
+
function fetchAudit() {
|
|
1704
|
+
if (auditLoading) return;
|
|
1705
|
+
setAuditLoading(true);
|
|
1706
|
+
window.fetch(API + 'audit', { credentials: 'same-origin', headers: { accept: 'application/json' } })
|
|
1707
|
+
.then(function (r) { return r.json(); })
|
|
1708
|
+
.then(function (body) { setAudit(body && body.ok === true ? body : { ok: false, events: [], total: 0 }); })
|
|
1709
|
+
.catch(function () { setAudit({ ok: false, events: [], total: 0 }); })
|
|
1710
|
+
.then(function () { setAuditLoading(false); });
|
|
1711
|
+
}
|
|
1502
1712
|
function checkUpdate() {
|
|
1503
1713
|
if (checking) return;
|
|
1504
1714
|
setChecking(true);
|
|
@@ -1813,6 +2023,29 @@ window.__ModuleLoader__.load({
|
|
|
1813
2023
|
CardNote('question')
|
|
1814
2024
|
)
|
|
1815
2025
|
),
|
|
2026
|
+
h('div', { className: 'cv-settings-card' },
|
|
2027
|
+
h('h3', null, t('auditTitle')),
|
|
2028
|
+
h('p', { className: 'cv-card-sub' }, t('auditDesc')),
|
|
2029
|
+
h('div', { className: 'cv-update-row' },
|
|
2030
|
+
h('button', { type: 'button', className: 'cv-btn', disabled: auditLoading, onClick: fetchAudit }, auditLoading ? t('auditLoading') : t('auditView'))
|
|
2031
|
+
),
|
|
2032
|
+
auditData ? h('div', { style: { marginTop: 10 } },
|
|
2033
|
+
auditData.ok !== true
|
|
2034
|
+
? h('p', { className: 'cv-card-sub', style: { margin: 0 } }, t('auditFail'))
|
|
2035
|
+
: (auditData.events && auditData.events.length > 0
|
|
2036
|
+
? h('div', { className: 'cv-audit-list' }, auditData.events.slice().reverse().map(function (ev, i) {
|
|
2037
|
+
var detail = ev.tool || ev.action || '-';
|
|
2038
|
+
if (ev.query) detail += ' · ' + ev.query;
|
|
2039
|
+
if (typeof ev.count === 'number') detail += ' · ' + ev.count;
|
|
2040
|
+
return h('div', { className: 'cv-audit-row', key: i },
|
|
2041
|
+
h('span', { className: 'cv-audit-time' }, String(ev.at || '').replace('T', ' ').replace('Z', '')),
|
|
2042
|
+
h('span', { className: 'cv-audit-detail' }, detail)
|
|
2043
|
+
);
|
|
2044
|
+
}))
|
|
2045
|
+
: h('p', { className: 'cv-card-sub', style: { margin: 0 } }, t('auditEmpty'))),
|
|
2046
|
+
h('p', { className: 'cv-card-sub', style: { marginTop: 8, marginBottom: 0 } }, t('auditTotal') + ':' + (auditData.total || 0))
|
|
2047
|
+
) : null
|
|
2048
|
+
),
|
|
1816
2049
|
h('div', { className: 'cv-settings-card' },
|
|
1817
2050
|
h('h3', null, t('updateTitle')),
|
|
1818
2051
|
h('p', { className: 'cv-card-sub' }, t('updateDesc')),
|
|
@@ -2106,7 +2339,8 @@ window.__ModuleLoader__.load({
|
|
|
2106
2339
|
}
|
|
2107
2340
|
function pickExport(fmt) {
|
|
2108
2341
|
setExporting(false);
|
|
2109
|
-
|
|
2342
|
+
var ok = exportEntries(entries, fmt);
|
|
2343
|
+
setToast(ok ? t('exportDone') : t('exportFail'));
|
|
2110
2344
|
}
|
|
2111
2345
|
function doImport(incoming, mode) {
|
|
2112
2346
|
setEntries(function (prev) {
|
|
@@ -2225,7 +2459,9 @@ window.__ModuleLoader__.load({
|
|
|
2225
2459
|
t: t, onImport: doImport, onCancel: function () { setImporting(false); }
|
|
2226
2460
|
}) : null,
|
|
2227
2461
|
exporting ? h(ExportModal, {
|
|
2228
|
-
t: t, onPick: pickExport, onCancel: function () { setExporting(false); }
|
|
2462
|
+
t: t, onPick: pickExport, onCancel: function () { setExporting(false); },
|
|
2463
|
+
onEncrypted: function (pw) { return exportEncrypted(entries, pw); },
|
|
2464
|
+
onDone: function () { setExporting(false); setToast(t('exportEncryptedDone')); }
|
|
2229
2465
|
}) : null,
|
|
2230
2466
|
auditing ? h(AuditModal, {
|
|
2231
2467
|
t: t, entries: entries, onEdit: auditEditEntry, onCancel: function () { setAuditing(false); }
|
package/cordis.patch.yml
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
- insert:
|
|
2
|
-
- id: dsh-credential-vault
|
|
3
|
-
name: '@mysterycode-liwen/dsh-credential-vault'
|
|
1
|
+
- insert:
|
|
2
|
+
- id: dsh-credential-vault
|
|
3
|
+
name: '@mysterycode-liwen/dsh-credential-vault'
|
package/icon.svg
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
|
|
2
|
-
<rect width="64" height="64" rx="14" fill="#2563eb"/>
|
|
3
|
-
<path d="M32 14 L46 19.5 V31 C46 40.5 39.8 46.8 32 50 C24.2 46.8 18 40.5 18 31 V19.5 Z" fill="#ffffff" opacity="0.96"/>
|
|
4
|
-
<circle cx="32" cy="29.5" r="4.3" fill="#2563eb"/>
|
|
5
|
-
<rect x="29.8" y="32.5" width="4.4" height="8.5" rx="2.2" fill="#2563eb"/>
|
|
6
|
-
</svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
|
|
2
|
+
<rect width="64" height="64" rx="14" fill="#2563eb"/>
|
|
3
|
+
<path d="M32 14 L46 19.5 V31 C46 40.5 39.8 46.8 32 50 C24.2 46.8 18 40.5 18 31 V19.5 Z" fill="#ffffff" opacity="0.96"/>
|
|
4
|
+
<circle cx="32" cy="29.5" r="4.3" fill="#2563eb"/>
|
|
5
|
+
<rect x="29.8" y="32.5" width="4.4" height="8.5" rx="2.2" fill="#2563eb"/>
|
|
6
|
+
</svg>
|
package/index.js
CHANGED
|
@@ -6,17 +6,19 @@
|
|
|
6
6
|
* 1. a loopback-only HTTP surface the browser POSTs its entries to, and
|
|
7
7
|
* 2. an agent tool (`dsh_credential_vault_read`) the model calls to read them.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* SECURITY MODEL (hardened):
|
|
10
|
+
* - The browser sends a METADATA-ONLY envelope. Secret fields (password /
|
|
11
|
+
* apiKey / content) never reach this Host process; plaintext stays in the
|
|
12
|
+
* browser's localStorage. Even a malicious full payload is sanitized here.
|
|
13
|
+
* - Nothing is persisted to disk. The snapshot lives only in memory and is
|
|
14
|
+
* re-synced by the browser on mount / change, so a restart simply starts
|
|
15
|
+
* empty until the browser reconnects.
|
|
16
|
+
* - Every tool access is recorded in a bounded, in-memory audit log that
|
|
17
|
+
* contains no plaintext (GET /audit, same-origin + loopback only).
|
|
12
18
|
*
|
|
13
19
|
* @module dsh-credential-vault
|
|
14
20
|
*/
|
|
15
21
|
|
|
16
|
-
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
|
|
17
|
-
import { homedir } from 'node:os'
|
|
18
|
-
import { join, resolve } from 'node:path'
|
|
19
|
-
|
|
20
22
|
/** Cordis plugin name. */
|
|
21
23
|
export const name = 'dsh-credential-vault'
|
|
22
24
|
|
|
@@ -44,7 +46,7 @@ const MAX_LIMIT = 200
|
|
|
44
46
|
const SUMMARY_FIELDS = ['id', 'title', 'category', 'username', 'provider', 'expiry', 'updatedAt']
|
|
45
47
|
|
|
46
48
|
/** Current plugin version. Keep in sync with package.json when releasing. */
|
|
47
|
-
const CURRENT_VERSION = '1.
|
|
49
|
+
const CURRENT_VERSION = '1.4.3'
|
|
48
50
|
|
|
49
51
|
/** Where update checks read the latest published version from (GitHub Releases latest). */
|
|
50
52
|
const RELEASES_API = 'https://api.github.com/repos/mysterycode-liwen/dsh-credential-vault/releases/latest'
|
|
@@ -53,63 +55,41 @@ const UPDATE_CHECK_TIMEOUT_MS = 8000
|
|
|
53
55
|
const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
54
56
|
let updateCache = { at: 0, result: null }
|
|
55
57
|
|
|
56
|
-
/** Last snapshot received from the browser. */
|
|
58
|
+
/** Last metadata-only snapshot received from the browser (never contains secrets). */
|
|
57
59
|
let snapshot = { entries: [], updatedAt: 0 }
|
|
58
60
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
: typeof raw === 'string' && (raw.startsWith('~/') || raw.startsWith('~\\')) ? join(homedir(), raw.slice(2))
|
|
65
|
-
: raw
|
|
66
|
-
return resolve(expanded)
|
|
67
|
-
}
|
|
61
|
+
/**
|
|
62
|
+
* Fields mirrored from the browser. Everything else (especially SECRET_FIELDS)
|
|
63
|
+
* is dropped, so the Host can never hold a plaintext password / key / body.
|
|
64
|
+
*/
|
|
65
|
+
const META_FIELDS = ['id', 'title', 'category', 'username', 'provider', 'url', 'endpoint', 'expiry', 'notes', 'createdAt', 'updatedAt']
|
|
68
66
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} catch {
|
|
84
|
-
// No file at the renamed location yet: fall through to the legacy path.
|
|
85
|
-
}
|
|
86
|
-
// One-time migration from the pre-rename store location.
|
|
87
|
-
try {
|
|
88
|
-
const parsed = JSON.parse(await readFile(legacyFile, 'utf8'))
|
|
89
|
-
if (parsed && Array.isArray(parsed.entries)) {
|
|
90
|
-
snapshot = { entries: parsed.entries, updatedAt: Number(parsed.updatedAt) || 0 }
|
|
91
|
-
try {
|
|
92
|
-
await mkdir(dir, { recursive: true })
|
|
93
|
-
await writeFile(file, JSON.stringify(snapshot), 'utf8')
|
|
94
|
-
} catch {
|
|
95
|
-
// Migration write is best-effort; the in-memory snapshot still works.
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
} catch {
|
|
99
|
-
// Nothing to restore: start with an empty snapshot.
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
async persist(next) {
|
|
103
|
-
try {
|
|
104
|
-
await mkdir(dir, { recursive: true })
|
|
105
|
-
const tmp = file + '.tmp'
|
|
106
|
-
await writeFile(tmp, JSON.stringify(next), 'utf8')
|
|
107
|
-
await rename(tmp, file)
|
|
108
|
-
} catch {
|
|
109
|
-
// Persistence is best-effort; the in-memory snapshot still works.
|
|
110
|
-
}
|
|
111
|
-
},
|
|
67
|
+
/**
|
|
68
|
+
* Force every incoming entry into a metadata-only shape. Applied defensively on
|
|
69
|
+
* POST /entries, so even a buggy or hostile client cannot smuggle a secret into
|
|
70
|
+
* the Host, the tool output, or the audit log.
|
|
71
|
+
*/
|
|
72
|
+
function sanitizeEnvelope(entry) {
|
|
73
|
+
const out = {}
|
|
74
|
+
for (const key of META_FIELDS) {
|
|
75
|
+
const value = entry[key]
|
|
76
|
+
if (typeof value === 'string' || typeof value === 'number') out[key] = value
|
|
77
|
+
}
|
|
78
|
+
// Keep the masked placeholders so the UI shape stays stable for the model.
|
|
79
|
+
for (const key of SECRET_FIELDS) {
|
|
80
|
+
if (typeof entry[key] === 'string' && entry[key] !== '') out[key] = MASK
|
|
112
81
|
}
|
|
82
|
+
return out
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// --- in-memory access audit (no plaintext, bounded) ------------------------
|
|
86
|
+
|
|
87
|
+
const MAX_AUDIT = 200
|
|
88
|
+
/** @type {{at:string, tool:string, action:string, entryId?:string, query?:string, count?:number}[]} */
|
|
89
|
+
const auditLog = []
|
|
90
|
+
function recordAudit(event) {
|
|
91
|
+
auditLog.push(Object.assign({ at: new Date().toISOString() }, event))
|
|
92
|
+
if (auditLog.length > MAX_AUDIT) auditLog.splice(0, auditLog.length - MAX_AUDIT)
|
|
113
93
|
}
|
|
114
94
|
|
|
115
95
|
// --- tiny HTTP helpers (self-contained so the bundle stays 7 files) --------
|
|
@@ -227,7 +207,7 @@ async function checkForUpdate() {
|
|
|
227
207
|
|
|
228
208
|
// --- HTTP surface ----------------------------------------------------------
|
|
229
209
|
|
|
230
|
-
async function handle(req, res
|
|
210
|
+
async function handle(req, res) {
|
|
231
211
|
try {
|
|
232
212
|
if (!isLoopback(req)) return fail(res, 403, 'NOT_LOOPBACK')
|
|
233
213
|
if (!isSameOrigin(req)) return fail(res, 403, 'BAD_ORIGIN')
|
|
@@ -237,6 +217,8 @@ async function handle(req, res, store) {
|
|
|
237
217
|
const method = (req.method || 'GET').toUpperCase()
|
|
238
218
|
|
|
239
219
|
// Browser -> Host: replace the snapshot with the browser's current vault.
|
|
220
|
+
// Every entry is forced through sanitizeEnvelope(), so secrets never enter
|
|
221
|
+
// this process even if the browser sends a full (legacy) payload.
|
|
240
222
|
if (pathname === '/entries' && method === 'POST') {
|
|
241
223
|
let body
|
|
242
224
|
try {
|
|
@@ -246,28 +228,26 @@ async function handle(req, res, store) {
|
|
|
246
228
|
}
|
|
247
229
|
const list = body && Array.isArray(body.entries) ? body.entries : null
|
|
248
230
|
if (!list) return fail(res, 400, 'BAD_ENTRIES', 'expected { entries: [] }')
|
|
249
|
-
// Keep only plain objects,
|
|
250
|
-
const entries = list
|
|
231
|
+
// Keep only plain objects, cap the count, then strip all secret fields.
|
|
232
|
+
const entries = list
|
|
233
|
+
.filter((e) => e !== null && typeof e === 'object' && !Array.isArray(e))
|
|
234
|
+
.slice(0, MAX_ENTRIES)
|
|
235
|
+
.map(sanitizeEnvelope)
|
|
251
236
|
snapshot = { entries, updatedAt: Date.now() }
|
|
252
|
-
await store.persist(snapshot)
|
|
253
237
|
return sendJson(res, 200, { ok: true, count: entries.length, truncated: list.length > entries.length })
|
|
254
238
|
}
|
|
255
239
|
|
|
256
|
-
// Debug / inspection: return a
|
|
240
|
+
// Debug / inspection endpoint removed: it used to return a page of the raw
|
|
241
|
+
// snapshot. It is not needed by the browser and only widened the read
|
|
242
|
+
// surface. The dsh_credential_vault_read tool is the sanctioned read path.
|
|
257
243
|
if (pathname === '/entries' && method === 'GET') {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
returned: page.length,
|
|
266
|
-
offset,
|
|
267
|
-
limit,
|
|
268
|
-
entries: page,
|
|
269
|
-
updatedAt: snapshot.updatedAt,
|
|
270
|
-
})
|
|
244
|
+
return fail(res, 404, 'NOT_FOUND')
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// In-memory access audit (same-origin + loopback already enforced above).
|
|
248
|
+
// Contains no plaintext — only tool names, actions, ids and counts.
|
|
249
|
+
if (pathname === '/audit' && method === 'GET') {
|
|
250
|
+
return sendJson(res, 200, { ok: true, total: auditLog.length, events: auditLog.slice() })
|
|
271
251
|
}
|
|
272
252
|
|
|
273
253
|
// Check GitHub Releases latest for a newer plugin version.
|
|
@@ -292,18 +272,15 @@ async function handle(req, res, store) {
|
|
|
292
272
|
|
|
293
273
|
// --- tool projection helpers ----------------------------------------------
|
|
294
274
|
|
|
295
|
-
function projectEntry(entry,
|
|
275
|
+
function projectEntry(entry, mode) {
|
|
296
276
|
const keys = mode === 'summary' ? SUMMARY_FIELDS : Object.keys(entry)
|
|
297
277
|
const out = {}
|
|
298
278
|
for (const key of keys) {
|
|
299
279
|
const value = entry[key]
|
|
300
280
|
if (value === null || value === undefined || value === '') continue
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
} else {
|
|
305
|
-
out[key] = value
|
|
306
|
-
}
|
|
281
|
+
// Secret fields in the snapshot are already MASK placeholders (the Host
|
|
282
|
+
// never receives plaintext). Guard here too, defense-in-depth.
|
|
283
|
+
out[key] = SECRET_FIELDS.includes(key) ? MASK : value
|
|
307
284
|
}
|
|
308
285
|
return out
|
|
309
286
|
}
|
|
@@ -322,16 +299,12 @@ function matches(entry, query, category) {
|
|
|
322
299
|
/**
|
|
323
300
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
324
301
|
*/
|
|
325
|
-
export function apply(ctx
|
|
326
|
-
const config = rawConfig !== null && typeof rawConfig === 'object' ? rawConfig : {}
|
|
327
|
-
const store = createStore(resolveHome(config.dshHome, process.env))
|
|
328
|
-
void store.restore()
|
|
329
|
-
|
|
302
|
+
export function apply(ctx) {
|
|
330
303
|
ctx.effect(() => {
|
|
331
304
|
const dispose = ctx.webServer.register({
|
|
332
305
|
kind: 'prefix',
|
|
333
306
|
path: PREFIX,
|
|
334
|
-
handler: (req, res) => handle(req, res
|
|
307
|
+
handler: (req, res) => handle(req, res),
|
|
335
308
|
})
|
|
336
309
|
return () => {
|
|
337
310
|
if (typeof dispose === 'function') dispose()
|
|
@@ -347,7 +320,7 @@ export function apply(ctx, rawConfig) {
|
|
|
347
320
|
{
|
|
348
321
|
name: 'dsh_credential_vault_read',
|
|
349
322
|
description:
|
|
350
|
-
'Read
|
|
323
|
+
'Read metadata about credentials in the user\'s local vault (accounts, API keys, other entries stored in the sidebar vault panel). Results are paginated: use limit/offset to page through large vaults, or mode="summary" for a lightweight id/title/category list first. Secret values (passwords / API keys / text bodies) are ALWAYS masked — plaintext never leaves the browser and cannot be returned by this tool; the revealSecrets parameter is accepted for compatibility but has no effect. Use this to discover which credentials exist; to actually use a secret, ask the user to open the vault panel and copy it.',
|
|
351
324
|
parameters: {
|
|
352
325
|
type: 'object',
|
|
353
326
|
properties: {
|
|
@@ -363,7 +336,7 @@ export function apply(ctx, rawConfig) {
|
|
|
363
336
|
mode: {
|
|
364
337
|
type: 'string',
|
|
365
338
|
enum: ['summary', 'full'],
|
|
366
|
-
description: 'summary = only id/title/category/account/provider/expiry (lightweight, recommended for browsing); full = all fields
|
|
339
|
+
description: 'summary = only id/title/category/account/provider/expiry (lightweight, recommended for browsing); full = all metadata fields (secrets always masked). Defaults to full.',
|
|
367
340
|
},
|
|
368
341
|
limit: {
|
|
369
342
|
type: 'number',
|
|
@@ -375,7 +348,7 @@ export function apply(ctx, rawConfig) {
|
|
|
375
348
|
},
|
|
376
349
|
revealSecrets: {
|
|
377
350
|
type: 'boolean',
|
|
378
|
-
description: '
|
|
351
|
+
description: 'Deprecated / no-op. Secret values are always masked and are never returned by this tool. Accepted only so older tool calls keep working.',
|
|
379
352
|
},
|
|
380
353
|
},
|
|
381
354
|
additionalProperties: false,
|
|
@@ -398,12 +371,14 @@ export function apply(ctx, rawConfig) {
|
|
|
398
371
|
const query = typeof a.query === 'string' ? a.query : ''
|
|
399
372
|
const category = typeof a.category === 'string' ? a.category : 'all'
|
|
400
373
|
const mode = a.mode === 'summary' ? 'summary' : 'full'
|
|
401
|
-
|
|
374
|
+
// revealSecrets is intentionally ignored: plaintext never reaches
|
|
375
|
+
// the Host, so there is nothing to reveal. Kept for compatibility.
|
|
402
376
|
const limit = Math.max(1, Math.min(MAX_LIMIT, Number.isFinite(a.limit) ? Math.floor(a.limit) : DEFAULT_LIMIT))
|
|
403
377
|
const offset = Math.max(0, Number.isFinite(a.offset) ? Math.floor(a.offset) : 0)
|
|
404
378
|
const all = Array.isArray(snapshot.entries) ? snapshot.entries : []
|
|
405
379
|
const filtered = all.filter((e) => matches(e, query, category))
|
|
406
380
|
const page = filtered.slice(offset, offset + limit)
|
|
381
|
+
recordAudit({ tool: 'dsh_credential_vault_read', action: 'read', category, query: query || undefined, count: page.length })
|
|
407
382
|
return {
|
|
408
383
|
total: filtered.length,
|
|
409
384
|
returned: page.length,
|
|
@@ -411,7 +386,7 @@ export function apply(ctx, rawConfig) {
|
|
|
411
386
|
limit,
|
|
412
387
|
hasMore: offset + page.length < filtered.length,
|
|
413
388
|
updatedAt: snapshot.updatedAt,
|
|
414
|
-
entries: page.map((e) => projectEntry(e,
|
|
389
|
+
entries: page.map((e) => projectEntry(e, mode)),
|
|
415
390
|
}
|
|
416
391
|
},
|
|
417
392
|
},
|
|
@@ -428,7 +403,7 @@ export function apply(ctx, rawConfig) {
|
|
|
428
403
|
name: 'tool:dsh-credential-vault',
|
|
429
404
|
order: 118,
|
|
430
405
|
text:
|
|
431
|
-
'凭据保险箱:用户把账号密码、API Key
|
|
406
|
+
'凭据保险箱:用户把账号密码、API Key、恢复码等保存在侧边栏「凭据保险箱」里。需要知道有哪些凭据时用 dsh_credential_vault_read 工具(按 query / category 过滤;数据多时先用 mode="summary" 看标题清单,再用 limit/offset 翻页)。出于安全,该工具只返回元数据——密码 / API Key / 文本正文一律显示为 ••••••••,明文只留在浏览器内、不会进入模型上下文,revealSecrets 参数已失效。不要向用户索要明文密钥;需要用到具体密钥时,请让用户自行在侧边栏面板中查看或复制。',
|
|
432
407
|
})
|
|
433
408
|
return () => {}
|
|
434
409
|
}, 'dsh-credential-vault-prompt')
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Credential vault",
|
|
4
|
-
"description": "Store
|
|
4
|
+
"description": "Store accounts, passwords and API keys locally. Secrets stay in your browser — the agent sees metadata only, nothing is written to disk."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED