@inventec/dsh-copilot-auth 1.2.25 → 1.2.27
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 +5 -5
- package/package.json +4 -4
- package/src/host.mjs +78 -12
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# @inventec/dsh-copilot-auth
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@inventec/dsh-copilot-auth)
|
|
4
3
|
[](https://github.com/iasiv5/dsh-copilot-auth/actions/workflows/ci.yml)
|
|
5
|
-
[](https://www.npmjs.com/package/@inventec/dsh-copilot-auth)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
[](#版本兼容)
|
|
7
7
|
|
|
8
8
|
为 DSH(DeepSeek Harness)内置的 GitHub Copilot 通道补上**网页设备码登录 / 注销**入口,预置开箱即用的 Copilot 提供方路由,并提供**模型列表管理**。用公司 GitHub 账号(带 Copilot 订阅)登录 DSH 的方式与其他 Copilot 客户端一致:**网页 + 设备码**,全程不填 API Token。
|
|
9
9
|
|
|
@@ -80,7 +80,7 @@ pi-ai 的模型目录是打包时硬编码的 JSON:上游新增模型在本机
|
|
|
80
80
|
|
|
81
81
|
| 插件线 | DSH 实测版本 | 说明 |
|
|
82
82
|
|---|---|---|
|
|
83
|
-
| **v1.2.x** | `0.1.7-rc.2`、`0.2.0-rc.1/rc.2`、`0.2.1-rc.2` ~ `rc.5` | 当前线;`0.2.0` 起注意插件 peer 精确版本守卫;rc.3 Web 冒烟:`/copilot-auth/status` 200、`activated=true`、`settingsNotServed=[]`、`lastError=null`;rc.4/rc.5 为契约面等价重发布(宿主 web-app patch 连续零 diff
|
|
83
|
+
| **v1.2.x** | `0.1.7-rc.2`、`0.2.0-rc.1/rc.2`、`0.2.1-rc.2` ~ `rc.5`、`0.2.2-rc.1` | 当前线;`0.2.0` 起注意插件 peer 精确版本守卫;rc.3 Web 冒烟:`/copilot-auth/status` 200、`activated=true`、`settingsNotServed=[]`、`lastError=null`;rc.4/rc.5 为契约面等价重发布(宿主 web-app patch 连续零 diff),核验结论按等价口径纳入;`0.2.2-rc.1` 新 minor 线首轮已实机冒烟(2026-11-04:`settingsNotServed=[]`、`lastError=null`、`registryInstanceMismatch=false`、`catalogWritable=true`) |
|
|
84
84
|
| v1.1.x | `0.1.2-rc.1` ~ `0.1.5-rc.2` | 旧版线;依赖 v1.2.0 已移除的 authorization 挂载补丁,新版 DSH 上无法激活 |
|
|
85
85
|
|
|
86
86
|
逐版本沿革(v1.2.0 ~ v1.2.20 完整说明与已移除能力的语义记录)见 [docs/CHANGELOG.md](./docs/CHANGELOG.md)。
|
|
@@ -121,7 +121,7 @@ base 模型(GPT-4o / 4.1 一类)不耗 premium requests;premium 模型(C
|
|
|
121
121
|
- 自行 patch `llm-pi-ai` 整段 config 会覆盖预置路由;`settings.yaml` 的 `llm-pi-ai:` 节只能稀疏覆盖字段,无法删除预置路由本身(移除须卸载本插件)
|
|
122
122
|
- 路由前缀 `/copilot-auth` 两侧硬编码,不可配置
|
|
123
123
|
- 模型目录「**只增不更新**」:合并只补充本机从未见过的条目,上游对已有 id 的元数据修正不会同步(ADR 0001)
|
|
124
|
-
- DSH rc 版本耦合:实测 `0.1.7-rc.2`、`0.2.0-rc.1/rc.2
|
|
124
|
+
- DSH rc 版本耦合:实测 `0.1.7-rc.2`、`0.2.0-rc.1/rc.2`、`0.2.1-rc.2/rc.3`(rc.4/rc.5 为契约面等价重发布,按等价口径纳入核验范围)与 `0.2.2-rc.1`(新 minor 线首轮,2026-11-04 实机冒烟,见「版本兼容」);peer 仅 `@deepseek-ai/cordis@^4.0.2`
|
|
125
125
|
- DSH 升级后的目录自愈仅在 pi-ai 基线版本不变时按已确认条目只增重放;跨基线且条目缺失时上报 `self-heal-incompatible`,不修改安装树(重新执行一次手动刷新即可在新基线上激活)
|
|
126
126
|
- 并发保护为宿主单进程内 mutex,不支持多实例 / 多进程并发操作同一安装目录
|
|
127
127
|
- 目录 fsync 仅在 POSIX 执行:Windows 无目录 fsync 语义(必然 `EPERM`),直接跳过,一致性由 NTFS 元数据日志保证(v1.2.3 起)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inventec/dsh-copilot-auth",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.27",
|
|
4
|
+
"description": "Copilot 设备码登录注销与模型列表管理,免 API Token,目录兜底不覆盖定制,凭据入内置凭据库。",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"node": ">=20"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@deepseek-ai/cordis": "
|
|
57
|
+
"@deepseek-ai/cordis": ">=4.0.2"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"esbuild": "^0.24.0",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dsh": {
|
|
66
66
|
"engines": {
|
|
67
|
-
"dsh": ">=0.
|
|
67
|
+
"dsh": ">=0.2.0-rc.1"
|
|
68
68
|
},
|
|
69
69
|
"bundle": {
|
|
70
70
|
"patch": "./cordis.patch.yml"
|
package/src/host.mjs
CHANGED
|
@@ -113,7 +113,43 @@ async function syncAvailableModels(ctx, opts = {}) {
|
|
|
113
113
|
], desc?.revision);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
function isLoopbackHostname(hostname) {
|
|
117
|
+
if (hostname === "localhost" || hostname === "[::1]") return true;
|
|
118
|
+
const parts = hostname.split(".");
|
|
119
|
+
return parts.length === 4 && parts[0] === "127" && parts.every((p) => /^\d{1,3}$/.test(p) && Number(p) <= 255);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// know-how 035 兼容层:webStartup (0.2.1+) → webRuntime (≤0.2.0) → [];非抛式查询。
|
|
123
|
+
function trustedHostsOf(ctx) {
|
|
124
|
+
let startup, runtime;
|
|
125
|
+
try { startup = ctx?.get?.("webStartup"); } catch { /* 未注入即缺席 */ }
|
|
126
|
+
try { runtime = ctx?.get?.("webRuntime"); } catch { /* 同上 */ }
|
|
127
|
+
return startup?.trustedHosts ?? runtime?.trustedHosts ?? [];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Host 必须是 loopback 或宿主信任名单成员——DNS rebinding 下 Host=攻击者域,必被拒。 */
|
|
131
|
+
function isTrustedHostRequest(req, trustedHosts) {
|
|
132
|
+
const host = req.headers?.host;
|
|
133
|
+
if (typeof host !== "string" || host === "") return false;
|
|
134
|
+
let hostname;
|
|
135
|
+
try {
|
|
136
|
+
hostname = new URL(`http://${host}`).hostname;
|
|
137
|
+
} catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (isLoopbackHostname(hostname)) return true;
|
|
141
|
+
return (trustedHosts ?? []).some((entry) => {
|
|
142
|
+
try {
|
|
143
|
+
const parsed = new URL(`http://${entry}`);
|
|
144
|
+
return parsed.port !== "" ? `${parsed.hostname}:${parsed.port}` === host : parsed.hostname === hostname;
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
116
151
|
function sameOrigin(req) {
|
|
152
|
+
if (req.headers?.["sec-fetch-site"] === "cross-site") return false;
|
|
117
153
|
const origin = req.headers?.origin;
|
|
118
154
|
if (origin === undefined || origin === null || origin === "") return true;
|
|
119
155
|
try {
|
|
@@ -123,23 +159,52 @@ function sameOrigin(req) {
|
|
|
123
159
|
}
|
|
124
160
|
}
|
|
125
161
|
|
|
162
|
+
/** 官方信任检查的守卫式委派(dsh-m 0.9.0 同款):服务在位 → 官方判定;服务查不到(含未注入名 get 抛错,兼容 0.1.x 无 connection 服务)→ undefined 回落本地栅栏;围栏执行抛错 → fail-closed 403。 */
|
|
163
|
+
function officialRejection(ctx, req) {
|
|
164
|
+
let connection, reject;
|
|
165
|
+
try {
|
|
166
|
+
connection = ctx?.get?.("connection");
|
|
167
|
+
reject = connection?.requestRejection;
|
|
168
|
+
} catch {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
if (typeof reject !== "function") return undefined;
|
|
172
|
+
try {
|
|
173
|
+
return reject.call(connection, { headers: req.headers }) ?? undefined;
|
|
174
|
+
} catch {
|
|
175
|
+
return 403;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 路由信任栅栏(2026-11-12 PR 评审同款强化):原 guard 仅 Origin===Host,
|
|
181
|
+
* DNS rebinding(Origin 与 Host 均为攻击者域)可穿透驱动授权/退出/模型目录变更。
|
|
182
|
+
* 现官方 Connection 指纹围栏优先;官方服务缺席回落「Host ∈ loopback∪宿主名单 + 同源」。
|
|
183
|
+
*/
|
|
184
|
+
export function createGuard(ctx) {
|
|
185
|
+
return (req, res, method) => {
|
|
186
|
+
const rejection = officialRejection(ctx, req);
|
|
187
|
+
if (rejection !== undefined) {
|
|
188
|
+
json(res, rejection, { ok: false, error: "forbidden origin" });
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (!isTrustedHostRequest(req, trustedHostsOf(ctx)) || !sameOrigin(req)) {
|
|
192
|
+
json(res, 403, { ok: false, error: "forbidden origin" });
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (req.method !== method) {
|
|
196
|
+
json(res, 405, { ok: false, error: "method not allowed" });
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return true;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
126
203
|
function json(res, code, payload) {
|
|
127
204
|
res.writeHead(code, { "content-type": "application/json" });
|
|
128
205
|
res.end(JSON.stringify(payload));
|
|
129
206
|
}
|
|
130
207
|
|
|
131
|
-
function guard(req, res, method) {
|
|
132
|
-
if (!sameOrigin(req)) {
|
|
133
|
-
json(res, 403, { ok: false, error: "forbidden origin" });
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
if (req.method !== method) {
|
|
137
|
-
json(res, 405, { ok: false, error: "method not allowed" });
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
208
|
function readBody(req) {
|
|
144
209
|
if (req.body !== undefined) return Promise.resolve(req.body);
|
|
145
210
|
return new Promise((resolve, reject) => {
|
|
@@ -364,6 +429,7 @@ function serviceError(res, err) {
|
|
|
364
429
|
|
|
365
430
|
export function apply(ctx, opts = {}) {
|
|
366
431
|
const r = routes();
|
|
432
|
+
const guard = createGuard(ctx); // 全路由信任检查:官方指纹围栏优先,缺席回落 Host 栅栏 + 同源
|
|
367
433
|
const scope = resolveRuntimeScope(ctx);
|
|
368
434
|
const intentIO = createIntentIO(scope);
|
|
369
435
|
const legacyPath = opts.stateFile ?? defaultStateFile();
|