Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): require redirect port for token broker manifests

fmfsaisai5de15ff7673d
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.oauth.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.oauth.test.ts
index c5c189c281..15925ef35b 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.oauth.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.oauth.test.ts
@@ -37,11 +37,13 @@ describe('FORGE_GUIDE · oauth 凭证章节', () => {
'"redirectPort"',
'"tokenBroker"',
'redirectPort 不是 1024–65535 整数',
- 'tokenBroker 与 clientSecret 同时声明',
+ 'tokenBroker 没同时声明 redirectPort',
+ '或与 clientSecret 同时声明',
'三路资格',
'静态官方前缀照旧放行',
'服务端 organization market 包已安装',
'organizationId 与当前组织一致',
+ 'release sha256 与批准 receipt 的 packageSha256 相等',
'installOrigin 为 `agent-forge`',
'不接受手动装入、个人身份或别的组织前缀',
'只给 Broker 与 oidc-token,不给宿主原语',
diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.ts
index f8618f6eb2..99504fedc7 100644
--- a/apps/desktop/src/main/cindy-brain/forge.ts
+++ b/apps/desktop/src/main/cindy-brain/forge.ts
@@ -1745,8 +1745,8 @@ node 详单**不接受** \`command\` / \`args\` / \`shell\` / \`env\` 或其它
"pkce": true, // 可选:PKCE(S256)开关,缺省 true
"extraAuthorizeParams": { "access_type": "offline", "prompt": "consent" }, // 可选 ≤8 条:服务商特有授权参数(协议保留参数禁写)
"identity": { "url": "https://api.example.com/userinfo", "labelPath": "email", "displayTemplate": "{team} · {user}", "avatarPath": "data.avatar_thumb" }, // 可选:授权后拉一次身份端点给账号打标签(设置页"已连接为 xxx";url 域名须命中 hosts)。labelPath 应指向**唯一且稳定**字段(如邮箱 / user_id)——它是重复授权时的同身份合并判定键,选 name 这类可重名可改名字段会误合并。displayTemplate 可选:人类可读展示名模板,\`{点分路径}\` 占位符从同一份身份响应取值(至少一个占位符,≤200 字符),任一占位符取不到值整体降级为空、回落显示 labelPath 的值——labelPath 的稳定字段不可读(如 Slack 的 user_id)时声明它,设置页与账号工具展示的就是渲染后的名字(邮箱这类本身可读的服务商不需要)。avatarPath 可选:头像 URL 在身份响应里的点分路径(如飞书的 "data.avatar_thumb")——主机取 https 地址后**不带凭证**下载小图(仅 png/jpeg/webp/gif、≤256KB)转 data URL 存库,\`/oauth\` 回查里以 account.avatarDataUrl 给你的 settingsHtml 展示(<img> 直接用)。**下载仅对第一方官方意识生效**(头像地址不受 hosts 白名单约束,第三方声明合法但恒降级 null)——所以页面必须能没头像也好看(如回落姓名首字圆片)
- "redirectPort": 53682, // 可选:loopback 回调固定端口(1024–65535)。服务商要求回调 URI 与注册值精确匹配(如 Atlassian)时声明,回调恒为 http://127.0.0.1:<端口>/callback;缺省 = 随机端口(Google 等允许任意 loopback 端口的服务商不用声明)
- "tokenBroker": "jira", // 可选:三路资格:静态官方前缀照旧放行;当前组织的服务端 organization market 包已安装、source 为 market、organizationId 与当前组织一致且 id 命中本组织已登记前缀;或当前组织身份下经 ghost forge 装入(receipt.installOrigin 为 agent-forge)且 id 命中本组织已登记前缀。后两条新增基座不接受手动装入、个人身份或别的组织前缀,且只给 Broker 与 oidc-token,不给宿主原语。声明后 code/refresh 交换经 Cindy 服务端 broker 完成(client secret 在服务端,不随包分发),与 clientSecret 互斥;设置页不再支持自填 client
+ "redirectPort": 53682, // 可选:loopback 回调固定端口(1024–65535);声明 tokenBroker 时必填。服务商要求回调 URI 与注册值精确匹配(如 Atlassian)时声明,回调恒为 http://127.0.0.1:<端口>/callback;非 broker 模式缺省 = 随机端口(Google 等允许任意 loopback 端口的服务商不用声明)
+ "tokenBroker": "jira", // 可选:三路资格:静态官方前缀照旧放行;当前组织的服务端 organization market 包已安装、source 为 market、organizationId 与当前组织一致、id 命中本组织已登记前缀且 release sha256 与批准 receipt 的 packageSha256 相等;或当前组织身份下经 ghost forge 装入(receipt.installOrigin 为 agent-forge)且 id 命中本组织已登记前缀。后两条新增基座不接受手动装入、个人身份或别的组织前缀,且只给 Broker 与 oidc-token,不给宿主原语。声明时必须同时声明 redirectPort;code/refresh 交换经 Cindy 服务端 broker 完成(client secret 在服务端,不随包分发),与 clientSecret 互斥;设置页不再支持自填 client
"brokerBounce": { "path": "/example/bounce", "callbackPath": "/example/callback" } // 可选:双地址弹跳回调(服务商后台只收 https redirect、不收 http loopback 时用)。必须与 tokenBroker、redirectPort 同时声明;报给服务商的 redirect_uri = broker 服务基地址 + path(主机运行时拼,清单不落域名),浏览器授权后由弹跳路由 302 回 http://127.0.0.1:<redirectPort><callbackPath>
}
}],
@@ -2944,15 +2944,17 @@ identity.displayTemplate 时,\`/oauth\` 回查与连接结果里 account.label
(含端口,如 Atlassian)时声明,主机回调恒为 \`http://127.0.0.1:<端口>/callback\`;
端口被占用时连接返回 LISTEN_FAILED(detail 带人话提示,settingsHtml 原样展示
即可;第一方官方内置意识会先自动结束占用进程并重试,第三方意识不享受此回收
- ——请选一个不易撞车的端口)。Google 这类允许任意 loopback 端口的服务商不用
- 声明。
+ ——请选一个不易撞车的端口)。声明 \`tokenBroker\` 时必须提供;非 broker 模式下,
+ Google 这类允许任意 loopback 端口的服务商不用声明。
- \`tokenBroker\`:资格有三路:①静态官方前缀命中,照旧放行;②当前组织的服务端
organization market 包已安装、source 为 \`market\`、organizationId 与当前组织一致,
- 且 id 命中本组织已登记前缀;③当前组织身份下经 ghost forge 装入(receipt 的
+ id 命中本组织已登记前缀,且 release sha256 与批准 receipt 的 packageSha256 相等;
+ ③当前组织身份下经 ghost forge 装入(receipt 的
installOrigin 为 \`agent-forge\`),且 id 命中本组织已登记前缀。第 2、3 条新增基座
不接受手动装入、个人身份或别的组织前缀,且只给 Broker 与 oidc-token,不给宿主原语。
code/refresh 交换改经 Cindy 服务端 broker 完成,client secret 由服务端持有、不随包
- 分发,且要求用户已登录 Cindy。声明它时与 clientSecret 互斥;PKCE 缺省开(verifier
+ 分发,且要求用户已登录 Cindy。声明它时必须同时声明 redirectPort,并与 clientSecret
+ 互斥;PKCE 缺省开(verifier
经 broker exchange 透传服务端),不吃 PKCE 的服务商显式 \`"pkce": false\`;
设置页的 \`/oauth/<key>/client\` 自填通道返回 405(settingsHtml 不要再画
client 输入区)。
@@ -4284,7 +4286,7 @@ const opened = await cindy.iosSimulator.request({
- oauth 声明格式错(source:"oauth" 缺 oauth 详单或反之、与 exchange 同时声明(互斥)、
authorizeUrl/tokenUrl 非 https 或域名不在 hosts 白名单、scopes 条目含空白/重复、
extraAuthorizeParams 覆写保留参数(client_id/redirect_uri/state/code_challenge 等)、
- redirectPort 不是 1024–65535 整数、tokenBroker 与 clientSecret 同时声明、
+ redirectPort 不是 1024–65535 整数、tokenBroker 没同时声明 redirectPort 或与 clientSecret 同时声明、
clientIdAlternatives 没与 clientId + tokenBroker 成套或包含重复/非法 ID、
当前安装来源或组织身份无权使用 tokenBroker、brokerBounce 没和 tokenBroker +
redirectPort 成套声明或路径不是 / 开头的站内绝对路径)
diff --git a/apps/desktop/src/shared/__tests__/ghost.oauth.test.ts b/apps/desktop/src/shared/__tests__/ghost.oauth.test.ts
index 01a4e248a8..20c3b6ac1e 100644
--- a/apps/desktop/src/shared/__tests__/ghost.oauth.test.ts
+++ b/apps/desktop/src/shared/__tests__/ghost.oauth.test.ts
@@ -286,11 +286,34 @@ describe('ghost · oauth 凭证声明校验', () => {
}
});
+ it('tokenBroker:必须带 redirectPort;非 broker 仍可省略', () => {
+ const base = {
+ authorizeUrl: 'https://accounts.example.com/authorize',
+ tokenUrl: 'https://accounts.example.com/token',
+ clientId: 'builtin-client-id',
+ };
+ const missingPort = validateGhostManifest(
+ oauthManifest({ oauth: { ...base, tokenBroker: 'jira' } }),
+ );
+ expect(missingPort.ok).toBe(false);
+ if (!missingPort.ok) expect(missingPort.reason).toContain('必须同时声明 redirectPort');
+
+ // This positive pair prevents accidentally requiring a fixed global port,
+ // while the no-broker control prevents widening the requirement to OAuth as a whole.
+ expect(
+ validateGhostManifest(
+ oauthManifest({ oauth: { ...base, tokenBroker: 'jira', redirectPort: 17872 } }),
+ ).ok,
+ ).toBe(true);
+ expect(validateGhostManifest(oauthManifest({ oauth: base })).ok).toBe(true);
+ });
+
it('tokenBroker:合法 slug 通过并保留;非法形状 / 与 clientSecret 互斥 → 拒', () => {
const base = {
authorizeUrl: 'https://accounts.example.com/authorize',
tokenUrl: 'https://accounts.example.com/token',
clientId: 'builtin-client-id',
+ redirectPort: 17872,
};
// broker 模式典型组合:内置 clientId + 无 clientSecret + pkce:false。
const ok = validateGhostManifest(
@@ -322,6 +345,7 @@ describe('ghost · oauth 凭证声明校验', () => {
tokenUrl: 'https://accounts.example.com/token',
clientId: 'cn-client-id',
tokenBroker: 'slack',
+ redirectPort: 17872,
};
const ok = validateGhostManifest(
oauthManifest({ oauth: { ...base, clientIdAlternatives: ['global-client-id'] } }),
diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.ts
index 2b4dd7ebbd..d9dbdb5c8b 100644
--- a/apps/desktop/src/shared/ghost.ts
+++ b/apps/desktop/src/shared/ghost.ts
@@ -775,15 +775,17 @@ export interface GhostSecretOauthDecl {
* 可选:loopback 回调固定端口(1024–65535)。Atlassian 这类服务商要求回调
* URI 与应用注册值精确匹配(含端口),声明后主机授权引擎钉死
* `http://127.0.0.1:<port>/callback`(端口被占用时结构化报错引导重试);
- * 缺省 = 随机端口(Google 等允许任意 loopback 端口的服务商)。
+ * 声明 tokenBroker 时必填;其它 OAuth 缺省 = 随机端口(Google 等允许任意
+ * loopback 端口的服务商)。
*/
redirectPort?: number;
/**
* 可选:XDT server token broker 的 provider slug(2026-07-14,xd-atlassian
* 意识化前置)。声明后 code 换 token 与 refresh 不直连 tokenUrl,改经主机
* 调 XDT server 的授权 broker(带登录 JWT;client secret 在服务端,不随包
- * 分发)。与 clientSecret 互斥。静态官方前缀照旧放行;其余资格由装入来源与
- * 当前组织事实共同判定。校验层保持纯函数不感知装入语境,门控在装入闸与连接闸。
+ * 分发)。必须同时声明 redirectPort,并与 clientSecret 互斥。静态官方前缀照旧
+ * 放行;其余资格由装入来源与当前组织事实共同判定。校验层保持纯函数不感知
+ * 装入语境,门控在装入闸与连接闸。
*/
tokenBroker?: string;
/**
@@ -2513,7 +2515,7 @@ export function ghostLocalePathFor(
): string | null {
if (!manifest.locales) return null;
const manifestLocale = (GHOST_LOCALES as readonly string[]).includes(locale ?? '')
- ? (locale as GhostLocale)
+ ? locale as GhostLocale
: null;
return (
(manifestLocale ? manifest.locales[manifestLocale] : undefined) ?? manifest.locales.en ?? null
@@ -2523,7 +2525,7 @@ export function ghostLocalePathFor(
/** 插件 app-context 只暴露协议旧四语;宿主新增语言固定回退英文以兼容存量插件。 */
export function ghostAppContextLocale(locale: string | undefined | null): GhostLocale {
return (GHOST_LOCALES as readonly string[]).includes(locale ?? '')
- ? locale as GhostLocale
+ ? (locale as GhostLocale)
: 'en';
}
@@ -4750,6 +4752,13 @@ export function validateGhostManifest(raw: unknown): ManifestValidation {
'network.secrets[].oauth.tokenBroker 与 clientSecret 互斥(broker 模式下 secret 由服务端持有,不随包分发)',
};
}
+ if (oa.redirectPort === undefined) {
+ return {
+ ok: false,
+ reason:
+ 'network.secrets[].oauth.tokenBroker 必须同时声明 redirectPort(broker 的 redirect_uri 端口必须稳定)',
+ };
+ }
}
if (oaClientIdAlternatives !== undefined && oa.tokenBroker === undefined) {
return {