qq-bot-roost 1.1.13 → 1.1.14
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 +2 -2
- package/package.json +3 -3
- package/src/config.js +10 -4
- package/src/hashdir.js +48 -16
- package/src/host/ops.js +4 -0
- package/src/plugin/market.js +76 -29
- package/src/web/server.js +26 -0
- package/web/app.js +39 -1
- package/web/index.html +11 -2
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
<img src="https://img.shields.io/badge/Node.js-22.13%2B-339933?logo=node.js&logoColor=white" alt="Node.js 22.13+">
|
|
10
10
|
<img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="零依赖">
|
|
11
|
-
<img src="https://img.shields.io/badge/tests-
|
|
11
|
+
<img src="https://img.shields.io/badge/tests-1455%20passed-brightgreen" alt="测试 1455 项">
|
|
12
12
|
<img src="https://img.shields.io/badge/plugins-JS%20%7C%20Python%20%7C%20Go%20%7C%20any-blue" alt="多语言插件">
|
|
13
|
-
<img src="https://img.shields.io/badge/version-1.1.
|
|
13
|
+
<img src="https://img.shields.io/badge/version-1.1.14-blueviolet" alt="版本 1.1.14">
|
|
14
14
|
<img src="https://img.shields.io/badge/license-AGPL--3.0--only-blue" alt="AGPL-3.0-only">
|
|
15
15
|
<a href="https://github.com/roost-qq/qq-bot-roost/actions"><img src="https://img.shields.io/github/actions/workflow/status/roost-qq/qq-bot-roost/ci.yml?branch=master" alt="CI"></a>
|
|
16
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qq-bot-roost",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "栖 Roost:零依赖的 QQ 官方机器人框架,填 AppID/AppSecret 即连,插件可写任意语言",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"mock": "node src/main.js --mock",
|
|
31
31
|
"check": "node src/main.js --check",
|
|
32
32
|
"release:prepare": "node scripts/release-prepare.mjs",
|
|
33
|
-
"test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/healthz-identity.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/gateway-interaction-ack.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/media-time.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
|
|
33
|
+
"test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/market-hash-dual.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/healthz-identity.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/gateway-interaction-ack.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/media-time.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
|
|
34
34
|
"test:e2e": "node test/e2e.mjs",
|
|
35
|
-
"test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/healthz-identity.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
|
|
35
|
+
"test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/market-hash-dual.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/healthz-identity.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
|
|
36
36
|
"check:secrets": "node scripts/check-secrets.mjs",
|
|
37
37
|
"create": "node scripts/create-plugin.mjs",
|
|
38
38
|
"test:plugin": "node scripts/test-plugin.mjs",
|
package/src/config.js
CHANGED
|
@@ -177,10 +177,16 @@ const GLOBAL_DEFAULTS = {
|
|
|
177
177
|
intervalHours: 6,
|
|
178
178
|
},
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
plugins: {
|
|
181
|
+
autoInstallDeps: true,
|
|
182
|
+
/**
|
|
183
|
+
* 插件市场安装 / 更新时校验目录内容哈希,默认开。
|
|
184
|
+
* 关掉等于放弃供应链完整性校验(只靠 https 和索引本身),市场页会明确提示风险;
|
|
185
|
+
* 只在索引与框架算法版本错位的过渡期临时用,修好后请打开。
|
|
186
|
+
*/
|
|
187
|
+
verifyHash: true,
|
|
188
|
+
/** Go 插件用的 go 可执行文件路径,留空则用 PATH 里的 go 或 GO_BIN 环境变量 */
|
|
189
|
+
goBin: '',
|
|
184
190
|
/**
|
|
185
191
|
* 插件市场索引地址,换成你自己的插件仓库即可。
|
|
186
192
|
*
|
package/src/hashdir.js
CHANGED
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
* **换行符要归一**:Windows 上 `core.autocrlf=true` 的仓库,检出是 CRLF,
|
|
17
17
|
* 而 GitHub 打的 tarball 里是 LF。按原始字节哈希,两边永远对不上,
|
|
18
18
|
* 结果是「每个插件都校验失败」——比不校验更糟。所以文本文件统一按 LF 算。
|
|
19
|
+
*
|
|
20
|
+
* 两套算法(与插件仓 scripts/hashdir.mjs、dsh-roost src/ext-bundle.js 同步):
|
|
21
|
+
* · algo1 = 老算法,纯文档 / LICENSE 计入指纹;旧索引的 `sha256` 是它算的;
|
|
22
|
+
* · algo2 = 现行算法(HASH_ALGO),排除文档与运行时状态;`sha256_v2` 是它算的。
|
|
23
|
+
* 安装 / 更新时两个都认(见 plugin/market.js 的 entryHashes);框架自更新的
|
|
24
|
+
* `hashFileList()` 仍只走下面的 `isHashedFile()`,行为不变——别把两套规则混起来。
|
|
19
25
|
*/
|
|
20
26
|
import fs from 'node:fs/promises';
|
|
21
27
|
import path from 'node:path';
|
|
@@ -23,19 +29,39 @@ import crypto from 'node:crypto';
|
|
|
23
29
|
import { HASH_SKIP } from './skipdirs.js';
|
|
24
30
|
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
32
|
+
* algo1 的老跳过表:1.4.0 及以前就是这几项,只用来校验旧索引的 `sha256`。
|
|
33
|
+
* 来自 ./skipdirs.js 的 HASH_SKIP——改它会改变已发布插件的 sha256,必须同步重建索引。
|
|
34
|
+
*/
|
|
35
|
+
const LEGACY_SKIP_DIRS = HASH_SKIP;
|
|
36
|
+
const LEGACY_SKIP_FILES = new Set(['.deps.json', '.DS_Store', 'Thumbs.db']);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* algo2 额外排除:旧依赖位置、抽帧目录与运行时状态文件。
|
|
40
|
+
* 这些文件不入库,但用户机器上会生成——带进去会让同一份插件算出不同指纹。
|
|
28
41
|
*/
|
|
29
|
-
const
|
|
30
|
-
const
|
|
42
|
+
const SKIP_DIRS_ALGO2 = new Set([...HASH_SKIP, 'deps', 'shots']);
|
|
43
|
+
const SKIP_FILES_ALGO2 = new Set([
|
|
44
|
+
...LEGACY_SKIP_FILES,
|
|
45
|
+
'ui-data.json', 'qr.png', 'cookie.txt',
|
|
46
|
+
'replies.json', 'replied.json', 'pending.json', 'history.json', 'seen.json',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
/** 纯文档不进 algo2 指纹:改 README / LICENSE 不该逼维护者重算索引。 */
|
|
50
|
+
function isDocFile(name) {
|
|
51
|
+
const lower = name.toLowerCase();
|
|
52
|
+
return lower.endsWith('.md') || /^(license|licence|copying)(\.[a-z0-9]+)?$/.test(lower);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 算法版本。与插件仓 scripts/hashdir.mjs、dsh-roost src/ext-bundle.js 保持一致。 */
|
|
56
|
+
export const HASH_ALGO = 2;
|
|
31
57
|
|
|
32
58
|
/**
|
|
33
|
-
* 一个相对路径(`/`
|
|
59
|
+
* 一个相对路径(`/` 分隔,含文件名)是否参与**框架自更新**的内容指纹。
|
|
34
60
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
61
|
+
* **只服务 hashFileList()(框架自更新 / SHA256SUMS)**,不是插件目录哈希的排除规则:
|
|
62
|
+
* 插件目录哈希走下面 collect() 的 algo1 / algo2 两套表。两处别混——2026-11 就
|
|
63
|
+
* 因为发版脚本漏了这里的文档排除规则,导致 SHA256SUMS 记录的指纹含 17 个
|
|
64
|
+
* md/LICENSE、而更新器解包后算出的不含,v1.1.11 及之后所有版本的自更新全部失败。
|
|
39
65
|
*
|
|
40
66
|
* @param {string} rel 相对路径,如 `src/main.js` / `docs/架构说明.md`
|
|
41
67
|
* @returns {boolean}
|
|
@@ -45,8 +71,8 @@ export function isHashedFile(rel) {
|
|
|
45
71
|
const name = parts.pop();
|
|
46
72
|
if (!name) return false;
|
|
47
73
|
// 任一级目录在跳过表里就排除(与 collect 逐层剪枝等价)
|
|
48
|
-
if (parts.some((seg) =>
|
|
49
|
-
if (
|
|
74
|
+
if (parts.some((seg) => LEGACY_SKIP_DIRS.has(seg))) return false;
|
|
75
|
+
if (LEGACY_SKIP_FILES.has(name)) return false;
|
|
50
76
|
const lower = name.toLowerCase();
|
|
51
77
|
if (lower.endsWith('.md')) return false;
|
|
52
78
|
if (/^(license|licence|copying)(\.[a-z0-9]+)?$/.test(lower)) return false;
|
|
@@ -74,7 +100,9 @@ function normalize(buf) {
|
|
|
74
100
|
* @param {string} root
|
|
75
101
|
* @returns {Promise<string[]>} 已排序的相对路径
|
|
76
102
|
*/
|
|
77
|
-
async function collect(root) {
|
|
103
|
+
async function collect(root, algo) {
|
|
104
|
+
const dirs = algo >= 2 ? SKIP_DIRS_ALGO2 : LEGACY_SKIP_DIRS;
|
|
105
|
+
const files = algo >= 2 ? SKIP_FILES_ALGO2 : LEGACY_SKIP_FILES;
|
|
78
106
|
const out = [];
|
|
79
107
|
|
|
80
108
|
const walk = async (dir, prefix) => {
|
|
@@ -86,11 +114,12 @@ async function collect(root) {
|
|
|
86
114
|
}
|
|
87
115
|
for (const it of items) {
|
|
88
116
|
if (it.isDirectory()) {
|
|
89
|
-
if (
|
|
117
|
+
if (dirs.has(it.name)) continue;
|
|
90
118
|
await walk(path.join(dir, it.name), prefix ? `${prefix}/${it.name}` : it.name);
|
|
91
119
|
} else if (it.isFile()) {
|
|
120
|
+
if (files.has(it.name)) continue;
|
|
121
|
+
if (algo >= 2 && isDocFile(it.name)) continue;
|
|
92
122
|
const rel = prefix ? `${prefix}/${it.name}` : it.name;
|
|
93
|
-
if (!isHashedFile(rel)) continue;
|
|
94
123
|
out.push(rel);
|
|
95
124
|
}
|
|
96
125
|
// 符号链接一律跳过:它可能指向仓库外,内容不稳定
|
|
@@ -134,7 +163,9 @@ export async function hashFileList(root, rels) {
|
|
|
134
163
|
* 算目录的内容指纹。
|
|
135
164
|
*
|
|
136
165
|
* @param {string} dir 插件目录
|
|
137
|
-
* @param {{exclude?: string[], only?: string[]}} [opts]
|
|
166
|
+
* @param {{algo?: number, exclude?: string[], only?: string[]}} [opts]
|
|
167
|
+
* - `algo`:1 = 老算法(含文档),2 = 现行算法(排除文档与运行时状态);默认 HASH_ALGO。
|
|
168
|
+
* 校验市场条目时两个都算,见 plugin/market.js 的 entryHashes。
|
|
138
169
|
* - `exclude`:精确匹配要跳过的相对路径(如 `SHA256SUMS` 这种会自引用的文件)
|
|
139
170
|
* - `only`:只算这些路径(`src` 这类目录前缀,或 `package.json` 这类文件名)。
|
|
140
171
|
* 用途:GitHub 的 tarball 是**全量**(含 .github、scripts、sdk),
|
|
@@ -143,6 +174,7 @@ export async function hashFileList(root, rels) {
|
|
|
143
174
|
* @returns {Promise<string>} 64 位十六进制
|
|
144
175
|
*/
|
|
145
176
|
export async function hashDir(dir, opts = {}) {
|
|
177
|
+
const algo = Number.isFinite(opts.algo) ? Number(opts.algo) : HASH_ALGO;
|
|
146
178
|
/**
|
|
147
179
|
* 根目录不存在时必须报错,**不能静默返回空哈希**。
|
|
148
180
|
*
|
|
@@ -156,7 +188,7 @@ export async function hashDir(dir, opts = {}) {
|
|
|
156
188
|
|
|
157
189
|
const skip = new Set(opts.exclude ?? []);
|
|
158
190
|
const only = (opts.only ?? []).map((p) => String(p));
|
|
159
|
-
let files = (await collect(dir)).filter((rel) => !skip.has(rel));
|
|
191
|
+
let files = (await collect(dir, algo)).filter((rel) => !skip.has(rel));
|
|
160
192
|
if (only.length) {
|
|
161
193
|
files = files.filter((rel) =>
|
|
162
194
|
only.some((p) => rel === p || rel.startsWith(p.endsWith('/') ? p : `${p}/`)),
|
package/src/host/ops.js
CHANGED
|
@@ -373,6 +373,8 @@ export function registerOps(def, { R, err, log = () => {} }) {
|
|
|
373
373
|
branch: idx.branch || 'main',
|
|
374
374
|
sha256: idx?.archive?.sha256 ?? idx?.sha256 ?? null,
|
|
375
375
|
exists: (pid) => plugins().loaded.has(pid),
|
|
376
|
+
// 与面板共用同一个全局开关,老配置默认开
|
|
377
|
+
verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
|
|
376
378
|
});
|
|
377
379
|
await ensurePluginInList(R, r.id, true, err);
|
|
378
380
|
const scanned = await plugins().rescan();
|
|
@@ -428,6 +430,7 @@ export function registerOps(def, { R, err, log = () => {} }) {
|
|
|
428
430
|
const r = await updatePlugins({
|
|
429
431
|
tmp: repo.tmp, index: repo.index, pluginsDir: DIRS.plugins,
|
|
430
432
|
ids: [id], localVersions: localVers,
|
|
433
|
+
verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
|
|
431
434
|
});
|
|
432
435
|
if (r.failed.length) throw err.bad(r.failed[0].error);
|
|
433
436
|
if (!r.updated.length) throw err.bad(`${id} 没有可用的更新`);
|
|
@@ -448,6 +451,7 @@ export function registerOps(def, { R, err, log = () => {} }) {
|
|
|
448
451
|
const r = await updatePlugins({
|
|
449
452
|
tmp: repo.tmp, index: repo.index,
|
|
450
453
|
pluginsDir: DIRS.plugins, localVersions: localVers,
|
|
454
|
+
verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
|
|
451
455
|
});
|
|
452
456
|
for (const u of r.updated) {
|
|
453
457
|
await plugins().reload(u.id).catch((e) => log(`插件 ${u.id} 重载失败:${e.message}`));
|
package/src/plugin/market.js
CHANGED
|
@@ -291,6 +291,23 @@ async function fetchIndexOnce(url) {
|
|
|
291
291
|
* @param {string|null} [p.sha256] 索引里给的仓库包校验值,有就验
|
|
292
292
|
* @returns {Promise<{id:string, dir:string}>}
|
|
293
293
|
*/
|
|
294
|
+
/**
|
|
295
|
+
* 索引条目声明的两种目录哈希(schema 4 起双写)。
|
|
296
|
+
*
|
|
297
|
+
* 2026-11-23 的坑:插件仓把 `sha256` 退回 algo1(给老安装器用),新增
|
|
298
|
+
* `sha256_v2` 存 algo2。框架此前只算 algo2 却拿它去比 `sha256`,于是所有
|
|
299
|
+
* 带 README / LICENSE 的插件 100% 装不上。现在两个都认,任一匹配即通过。
|
|
300
|
+
* 旧索引只有 `sha256` 的也兼容:可能是 algo1,也可能是早期的 algo2 值。
|
|
301
|
+
*/
|
|
302
|
+
export function entryHashes(entry) {
|
|
303
|
+
const legacy = String(entry?.sha256 ?? '').toLowerCase();
|
|
304
|
+
const current = String(entry?.sha256_v2 ?? '').toLowerCase();
|
|
305
|
+
return {
|
|
306
|
+
legacy: /^[0-9a-f]{64}$/.test(legacy) ? legacy : '',
|
|
307
|
+
current: /^[0-9a-f]{64}$/.test(current) ? current : '',
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
294
311
|
/**
|
|
295
312
|
* 校验失败时说清楚:到底是「索引过期」还是「内容真被改了」。
|
|
296
313
|
*
|
|
@@ -311,10 +328,13 @@ async function shaMismatchError(entry, dir, got) {
|
|
|
311
328
|
' 已中止,原有插件未动。',
|
|
312
329
|
);
|
|
313
330
|
}
|
|
331
|
+
const { legacy, current } = entryHashes(entry);
|
|
332
|
+
const expected = [...new Set([current, legacy].filter(Boolean))];
|
|
314
333
|
return new Error(
|
|
315
334
|
'插件内容校验失败(sha256 不匹配)\n' +
|
|
316
|
-
` 索引 ${
|
|
317
|
-
'
|
|
335
|
+
` 索引 ${expected.join(' / ') || '(没有哈希)'}\n 实际 ${got}\n` +
|
|
336
|
+
' 索引和实际内容对不上:可能是仓库被改动,也可能是索引与框架的哈希算法版本不一致。\n' +
|
|
337
|
+
' 先刷新市场 / 升级框架再试;仍失败就别装。已中止,原有插件未动。',
|
|
318
338
|
);
|
|
319
339
|
}
|
|
320
340
|
|
|
@@ -340,13 +360,40 @@ async function readVersionLoose(dir) {
|
|
|
340
360
|
}
|
|
341
361
|
}
|
|
342
362
|
|
|
343
|
-
/**
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
363
|
+
/**
|
|
364
|
+
* 校验插件目录内容。安装 / 更新共用一套规则,避免两边各自漂移。
|
|
365
|
+
*
|
|
366
|
+
* 双算法任一匹配即通过:现行索引 `sha256` 是 algo1、`sha256_v2` 是 algo2;
|
|
367
|
+
* 老索引只有 `sha256`,值可能是任一算法算出来的,两种都试一遍。
|
|
368
|
+
*
|
|
369
|
+
* @param {object} entry 索引条目
|
|
370
|
+
* @param {string} dir 待校验的插件目录
|
|
371
|
+
* @param {{verifyHash?: boolean}} [opts] verifyHash=false 时跳过校验(面板开关,默认开)
|
|
372
|
+
*/
|
|
373
|
+
export async function verifyPluginDir(entry, dir, opts = {}) {
|
|
374
|
+
const { legacy, current } = entryHashes(entry);
|
|
375
|
+
if (!legacy && !current) {
|
|
376
|
+
log.warn(`索引里没有 ${entry?.id} 的 sha256,本次未做内容校验`);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (opts.verifyHash === false) {
|
|
380
|
+
log.warn(`插件 ${entry?.id} 的内容哈希校验已被关闭(market.verifyHash=false)`);
|
|
381
|
+
return;
|
|
349
382
|
}
|
|
383
|
+
|
|
384
|
+
const gotCurrent = await hashDir(dir);
|
|
385
|
+
if ((current && gotCurrent === current) || (legacy && gotCurrent === legacy)) {
|
|
386
|
+
log.info(`插件 ${entry?.id} 内容 sha256 校验通过`);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (legacy) {
|
|
390
|
+
const gotLegacy = await hashDir(dir, { algo: 1 });
|
|
391
|
+
if (gotLegacy === legacy) {
|
|
392
|
+
log.info(`插件 ${entry?.id} 内容 sha256 校验通过(algo1)`);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
throw await shaMismatchError(entry, dir, gotCurrent);
|
|
350
397
|
}
|
|
351
398
|
|
|
352
399
|
/**
|
|
@@ -517,7 +564,9 @@ export function isExtensionEntry(entry) {
|
|
|
517
564
|
return entry?.kind === 'dsh-extension';
|
|
518
565
|
}
|
|
519
566
|
|
|
520
|
-
export async function installPlugin({
|
|
567
|
+
export async function installPlugin({
|
|
568
|
+
entry, pluginsDir, repo, branch = 'main', exists, sha256 = null, verifyHash = true,
|
|
569
|
+
}) {
|
|
521
570
|
const id = String(entry?.id ?? '').trim();
|
|
522
571
|
if (isExtensionEntry(entry)) {
|
|
523
572
|
throw new Error(`「${id}」是 DSH 扩展,不归框架插件市场;请在 dsh-roost 面板的「设置 → 扩展」里安装`);
|
|
@@ -566,15 +615,7 @@ export async function installPlugin({ entry, pluginsDir, repo, branch = 'main',
|
|
|
566
615
|
* 没有稳定的压缩包哈希可对。校验放在**拷贝进 plugins/ 之前**,
|
|
567
616
|
* 对不上就什么都不留。
|
|
568
617
|
*/
|
|
569
|
-
|
|
570
|
-
const got = await hashDir(resolved);
|
|
571
|
-
if (got !== String(entry.sha256).toLowerCase()) {
|
|
572
|
-
throw await shaMismatchError(entry, resolved, got);
|
|
573
|
-
}
|
|
574
|
-
log.info(`插件 ${id} 内容 sha256 校验通过`);
|
|
575
|
-
} else {
|
|
576
|
-
log.warn(`索引里没有 ${id} 的 sha256,本次安装未做内容校验`);
|
|
577
|
-
}
|
|
618
|
+
await verifyPluginDir(entry, resolved, { verifyHash });
|
|
578
619
|
|
|
579
620
|
const dest = path.join(pluginsDir, id);
|
|
580
621
|
await fs.rm(dest, { recursive: true, force: true });
|
|
@@ -589,14 +630,22 @@ export async function installPlugin({ entry, pluginsDir, repo, branch = 'main',
|
|
|
589
630
|
|
|
590
631
|
/**
|
|
591
632
|
* 把市场索引和本地已装插件对上,给面板用。
|
|
633
|
+
*
|
|
634
|
+
* DSH 扩展(`kind: dsh-extension`)与框架插件共用同一份 index.json,但装的位置、
|
|
635
|
+
* 安装器、运行形态都不同——框架面板列出来只会让用户点了安装再报错。这里就把
|
|
636
|
+
* 扩展从面板列表里滤掉(执行层 `installPlugin` 的守卫仍在,两道都要有)。
|
|
637
|
+
* `detectUpdates` 也跳过扩展,所以分类计数、更新提示、卡片列表口径一致。
|
|
638
|
+
*
|
|
592
639
|
* @param {object[]} indexPlugins
|
|
593
640
|
* @param {Set<string>} installedIds
|
|
594
641
|
*/
|
|
595
642
|
export function mergeWithInstalled(indexPlugins, installedIds) {
|
|
596
|
-
return indexPlugins
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
643
|
+
return indexPlugins
|
|
644
|
+
.filter((p) => !isExtensionEntry(p))
|
|
645
|
+
.map((p) => ({
|
|
646
|
+
...p,
|
|
647
|
+
installed: installedIds.has(p.id),
|
|
648
|
+
}));
|
|
600
649
|
}
|
|
601
650
|
|
|
602
651
|
/* ------------------------------------------------------------------ */
|
|
@@ -799,9 +848,12 @@ export async function syncCodeTree(src, dest, keepTop) {
|
|
|
799
848
|
* @param {string} p.pluginsDir 目标插件目录
|
|
800
849
|
* @param {string[]} [p.ids] 只更新这些;不传则更新全部「有新版」的
|
|
801
850
|
* @param {Object<string,string>} [p.localVersions] 本地版本,用于判断谁有新版
|
|
851
|
+
* @param {boolean} [p.verifyHash] 是否校验目录内容,默认 true(面板可关)
|
|
802
852
|
* @returns {Promise<{updated:Array, skipped:Array, failed:Array}>}
|
|
803
853
|
*/
|
|
804
|
-
export async function updatePlugins({
|
|
854
|
+
export async function updatePlugins({
|
|
855
|
+
tmp, index, pluginsDir, ids, localVersions = {}, verifyHash = true,
|
|
856
|
+
}) {
|
|
805
857
|
const want = ids?.length ? new Set(ids) : null;
|
|
806
858
|
const result = { updated: [], skipped: [], failed: [] };
|
|
807
859
|
|
|
@@ -839,12 +891,7 @@ export async function updatePlugins({ tmp, index, pluginsDir, ids, localVersions
|
|
|
839
891
|
* 「第一次装的时候小心,以后随便覆盖」,供应链校验的意义就没了。
|
|
840
892
|
* 校验放在**动旧目录之前**:对不上就什么都不碰,用户手上的插件还是好的。
|
|
841
893
|
*/
|
|
842
|
-
|
|
843
|
-
const got = await hashDir(src);
|
|
844
|
-
if (got !== String(entry.sha256).toLowerCase()) {
|
|
845
|
-
throw await shaMismatchError(entry, src, got);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
894
|
+
await verifyPluginDir(entry, src, { verifyHash });
|
|
848
895
|
|
|
849
896
|
const hadOld = await fs.stat(dest).catch(() => null);
|
|
850
897
|
|
package/src/web/server.js
CHANGED
|
@@ -2763,6 +2763,8 @@ async function startWebServerInstance({
|
|
|
2763
2763
|
repo: idx.repo,
|
|
2764
2764
|
updated: idx.updated,
|
|
2765
2765
|
source: url2 || 'default',
|
|
2766
|
+
// 面板「插件市场」的内容哈希校验开关;老配置没这个字段时默认开
|
|
2767
|
+
verifyHash: globalCfg?.plugins?.verifyHash !== false,
|
|
2766
2768
|
plugins: mergeWithInstalled(idx.plugins, installedIds),
|
|
2767
2769
|
// 本地有新版可用的插件
|
|
2768
2770
|
updates: updates.map((u) => ({
|
|
@@ -2780,6 +2782,26 @@ async function startWebServerInstance({
|
|
|
2780
2782
|
}
|
|
2781
2783
|
}
|
|
2782
2784
|
|
|
2785
|
+
/**
|
|
2786
|
+
* 市场内容哈希校验开关(全局,默认开;面板「插件市场」直接切换)。
|
|
2787
|
+
*
|
|
2788
|
+
* 严格只认布尔:字符串 "false" 若按真值判断会被读成「开」,
|
|
2789
|
+
* 安全开关上这种错代价最大。立即生效——安装 / 更新每次都现读 globalCfg。
|
|
2790
|
+
*/
|
|
2791
|
+
if (pathname === '/api/market/settings' && req.method === 'PUT') {
|
|
2792
|
+
const body = await readBody(req);
|
|
2793
|
+
if (typeof body?.verifyHash !== 'boolean') {
|
|
2794
|
+
return json(res, 400, { error: 'verifyHash 必须是 true / false' });
|
|
2795
|
+
}
|
|
2796
|
+
globalCfg.plugins = {
|
|
2797
|
+
...(globalCfg.plugins ?? {}),
|
|
2798
|
+
verifyHash: body.verifyHash,
|
|
2799
|
+
};
|
|
2800
|
+
await saveGlobalConfig?.(globalCfg).catch(() => {});
|
|
2801
|
+
log.info(`插件市场内容哈希校验已${body.verifyHash ? '开启' : '关闭'}`);
|
|
2802
|
+
return json(res, 200, { ok: true, verifyHash: body.verifyHash });
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2783
2805
|
// 一键安装
|
|
2784
2806
|
if (pathname === '/api/market/install' && req.method === 'POST') {
|
|
2785
2807
|
const body = await readBody(req);
|
|
@@ -2816,6 +2838,8 @@ async function startWebServerInstance({
|
|
|
2816
2838
|
// 索引给了仓库包校验值就带上,tarball 那边会比对
|
|
2817
2839
|
sha256: idx?.archive?.sha256 ?? idx?.sha256 ?? null,
|
|
2818
2840
|
exists: (pid) => plugins.loaded.has(pid),
|
|
2841
|
+
// 面板开关:只有显式 false 才关,老配置没这个字段时默认校验
|
|
2842
|
+
verifyHash: globalCfg?.plugins?.verifyHash !== false,
|
|
2819
2843
|
});
|
|
2820
2844
|
|
|
2821
2845
|
/**
|
|
@@ -4661,6 +4685,7 @@ async function startWebServerInstance({
|
|
|
4661
4685
|
pluginsDir: DIRS.plugins,
|
|
4662
4686
|
ids: [id],
|
|
4663
4687
|
localVersions: localVers,
|
|
4688
|
+
verifyHash: globalCfg?.plugins?.verifyHash !== false,
|
|
4664
4689
|
});
|
|
4665
4690
|
if (r.failed.length) return json(res, 400, { error: r.failed[0].error });
|
|
4666
4691
|
if (!r.updated.length) return json(res, 400, { error: `${id} 没有可用的更新` });
|
|
@@ -4692,6 +4717,7 @@ async function startWebServerInstance({
|
|
|
4692
4717
|
index: repo.index,
|
|
4693
4718
|
pluginsDir: DIRS.plugins,
|
|
4694
4719
|
localVersions: localVers,
|
|
4720
|
+
verifyHash: globalCfg?.plugins?.verifyHash !== false,
|
|
4695
4721
|
});
|
|
4696
4722
|
|
|
4697
4723
|
// 更新成功的逐个重载,失败的不碰
|
package/web/app.js
CHANGED
|
@@ -1996,7 +1996,7 @@ function fillForm(c) {
|
|
|
1996
1996
|
? '当前框架没有内置信任公钥,这个开关即使打开也不起作用(框架自更新照常放行)。'
|
|
1997
1997
|
: !trust.pubkeyValid
|
|
1998
1998
|
? '信任公钥配错了,解析不了——这个开关打开也不会生效。检查配置里的 security.trust.pubkey。'
|
|
1999
|
-
: '开启后,框架自更新会校验 SHA256SUMS
|
|
1999
|
+
: '开启后,框架自更新会校验 SHA256SUMS 签名,不符或缺失时拒绝更新;插件市场不做签名校验(内容哈希在「插件市场」页单独开关,默认开)。';
|
|
2000
2000
|
}
|
|
2001
2001
|
}
|
|
2002
2002
|
|
|
@@ -4451,6 +4451,15 @@ async function testMirrors() {
|
|
|
4451
4451
|
}
|
|
4452
4452
|
}
|
|
4453
4453
|
|
|
4454
|
+
/** 市场内容哈希开关的说明:关掉时必须把风险说清楚,别让用户以为照旧受保护 */
|
|
4455
|
+
function setMarketHashHint(on) {
|
|
4456
|
+
const el = $('#marketHashHint');
|
|
4457
|
+
if (!el) return;
|
|
4458
|
+
el.textContent = on
|
|
4459
|
+
? '安装 / 更新会比对索引 sha256,内容不符就拒绝。'
|
|
4460
|
+
: '已关闭:不再校验下载内容完整性,仅建议兼容旧索引时临时使用。';
|
|
4461
|
+
}
|
|
4462
|
+
|
|
4454
4463
|
/**
|
|
4455
4464
|
* 拉市场数据并渲染。reveal=false 用于进插件页时的后台预拉:只填数据,不切页签。
|
|
4456
4465
|
* 在途请求复用(loading),成功过的用缓存(loaded),只有 force 才真重拉。
|
|
@@ -4479,6 +4488,12 @@ async function loadMarket({ reveal = true, force = false } = {}) {
|
|
|
4479
4488
|
}
|
|
4480
4489
|
|
|
4481
4490
|
meta.textContent = `${d.repo} · 更新于 ${d.updated || '未知'}`;
|
|
4491
|
+
// 内容哈希开关:后端只回「开 / 关」,老配置没字段时按默认开处理
|
|
4492
|
+
const hashBox = $('#marketVerifyHash');
|
|
4493
|
+
if (hashBox) {
|
|
4494
|
+
hashBox.checked = d.verifyHash !== false;
|
|
4495
|
+
setMarketHashHint(hashBox.checked);
|
|
4496
|
+
}
|
|
4482
4497
|
// 网络不通时后端会退回本地缓存,得让用户知道这是旧数据
|
|
4483
4498
|
if (d.stale) {
|
|
4484
4499
|
meta.innerHTML =
|
|
@@ -4892,6 +4907,29 @@ $('#proxySelect')?.addEventListener('change', (e) => {
|
|
|
4892
4907
|
saveMirror();
|
|
4893
4908
|
});
|
|
4894
4909
|
$('#proxyCustom')?.addEventListener('change', saveMirror);
|
|
4910
|
+
|
|
4911
|
+
/**
|
|
4912
|
+
* 市场内容哈希校验:改完立即落盘生效,不重启。
|
|
4913
|
+
* 失败时把勾选弹回去——安全开关最怕「面板显示开着、后端其实没保存」的假状态。
|
|
4914
|
+
*/
|
|
4915
|
+
$('#marketVerifyHash')?.addEventListener('change', async (e) => {
|
|
4916
|
+
const on = e.target.checked;
|
|
4917
|
+
try {
|
|
4918
|
+
const r = await api('/api/market/settings', {
|
|
4919
|
+
method: 'PUT',
|
|
4920
|
+
body: JSON.stringify({ verifyHash: on }),
|
|
4921
|
+
});
|
|
4922
|
+
const actual = r?.verifyHash !== false;
|
|
4923
|
+
if (actual !== on) e.target.checked = actual;
|
|
4924
|
+
setMarketHashHint(actual);
|
|
4925
|
+
toast(`内容哈希校验已${actual ? '开启' : '关闭'}`, actual ? 'ok' : 'info');
|
|
4926
|
+
} catch (err) {
|
|
4927
|
+
e.target.checked = !on;
|
|
4928
|
+
setMarketHashHint(!on);
|
|
4929
|
+
toast(`保存失败:${errText(err)}`, 'error');
|
|
4930
|
+
}
|
|
4931
|
+
});
|
|
4932
|
+
|
|
4895
4933
|
/* 子页签:切到市场时确保数据拉过;切回已安装只切显隐,不产生请求 */
|
|
4896
4934
|
$$('[data-plugin-subtab]').forEach((btn) => {
|
|
4897
4935
|
btn.addEventListener('click', () => {
|
package/web/index.html
CHANGED
|
@@ -1041,7 +1041,7 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
|
|
|
1041
1041
|
</label>
|
|
1042
1042
|
<div class="hint" id="trustHint">
|
|
1043
1043
|
开启后,面板里「更新框架」会检查 Release 里的 SHA256SUMS 签名,签名不符或缺失时拒绝更新。
|
|
1044
|
-
只影响框架自身升级;<b>插件市场不再做签名校验</b
|
|
1044
|
+
只影响框架自身升级;<b>插件市场不再做签名校验</b>,下载内容的 sha256 校验在「插件市场」页单独开关(默认开)。
|
|
1045
1045
|
需要框架内置信任公钥——没内置时这个开关不起作用。
|
|
1046
1046
|
</div>
|
|
1047
1047
|
<div class="hint">
|
|
@@ -1183,8 +1183,17 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
|
|
|
1183
1183
|
</div>
|
|
1184
1184
|
</div>
|
|
1185
1185
|
|
|
1186
|
-
<!-- 下载源:国内直连 GitHub 经常超时,这里可以换镜像 -->
|
|
1187
1186
|
<div class="mirror-bar">
|
|
1187
|
+
<!--
|
|
1188
|
+
内容哈希校验:默认开。关掉后安装 / 更新不再比对索引 sha256,
|
|
1189
|
+
只建议在索引与框架算法版本错位的过渡期临时用。
|
|
1190
|
+
-->
|
|
1191
|
+
<label class="switch small" title="安装 / 更新时比对索引里的 sha256,防止下载内容被替换">
|
|
1192
|
+
<input type="checkbox" id="marketVerifyHash" checked> 校验内容哈希
|
|
1193
|
+
</label>
|
|
1194
|
+
<span class="hint" id="marketHashHint"></span>
|
|
1195
|
+
|
|
1196
|
+
<!-- 下载源:国内直连 GitHub 经常超时,这里可以换镜像 -->
|
|
1188
1197
|
<span class="hint">下载源</span>
|
|
1189
1198
|
<select id="mirrorSelect" class="mini-select" aria-label="下载源"></select>
|
|
1190
1199
|
<input
|