Fix #137: decouple hose-link cache and add issue PR rule
- Decouple getHoseProvisionalAuthLink from internal closeapi session cache to prevent silent truncation and cache pollution (#137) - Add --force, --refresh, -f options and positive integer validation to auth hose-link - Clarify distinction between Hose web assistance links and Seal delegation tokens across CLI help, SKILL.md, and docs - Add modular issue resolution and PR workflow rule under .agents/rules/
This commit is contained in:
1 parent
0fad6359b5
commit
1f8bd016aa
12 files changed
+286
-139
No files matched your search
@@ -39,8 +39,16 @@ export async function handleAuthCommand(action: string | undefined, corp: CorpCo
|
||||
}
|
||||
|
||||
if (action === "hose-link") {
|
||||
const expiresIn = numberOption(args.options.expire) ?? 7200;
|
||||
printJson(await getHoseProvisionalAuthLink(corp, expiresIn));
|
||||
const rawExpire = args.options.expire;
|
||||
const expiresIn = rawExpire !== undefined ? numberOption(rawExpire) : 7200;
|
||||
if (expiresIn === undefined || expiresIn <= 0) {
|
||||
throw new Error(`Invalid --expire: ${String(rawExpire)}. Must be a positive number of seconds (e.g. --expire 7200 or --expire 86400).`);
|
||||
}
|
||||
const force =
|
||||
booleanOption(args.options.force) === true ||
|
||||
booleanOption(args.options.refresh) === true ||
|
||||
booleanOption(args.options.f) === true;
|
||||
printJson(await getHoseProvisionalAuthLink(corp, expiresIn, { force }));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+17
-9
@@ -676,8 +676,14 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
},
|
||||
{
|
||||
name: "hose-link",
|
||||
summary: "Generate Hose third-party assistance link",
|
||||
usage: ["seal-use auth hose-link [--corp <corpId>] [--expire 7200]"]
|
||||
summary: "【合思主站】生成免密登录/第三方协助入口链接",
|
||||
usage: ["seal-use auth hose-link [--corp <corpId>] [--expire 7200] [--force]"],
|
||||
options: [
|
||||
{ flag: "--expire <seconds>", description: "链接有效时间(秒),默认 7200,支持如 86400(1天)" },
|
||||
{ flag: "--force, --refresh, -f", description: "强制向合思 OpenAPI 申请全新临时凭证" }
|
||||
],
|
||||
description:
|
||||
"专用于合思 (Hose) 来源企业。向合思申请临时 ticket,生成直达合思/易快报主站 (https://app.ekuaibao.com/web/thirdparty.html) 的免密登录链接。凭证独立生成,不读取亦不污染 CLI 内部会话。注意:此链接不可通过 'seal-use delegation list' 查询(后者仅管理 Seal 审核后台的委托令牌)。"
|
||||
},
|
||||
{
|
||||
name: "extract-keys",
|
||||
@@ -706,24 +712,26 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
},
|
||||
{
|
||||
area: "delegation",
|
||||
title: "Delegation tokens",
|
||||
description: "Manage Seal user delegation tokens and temporary access credentials.",
|
||||
title: "【Seal 审核后台】用户委托授权与协助链接",
|
||||
description: "管理 Seal AI 智能审核后台 (https://<tenant>.sealai.cc/delegate) 的用户委托授权令牌与协助凭据。注意:此处仅管理 Seal 审核台的委托授权,不包含合思主站的免密登录链接 (seal-use auth hose-link)。",
|
||||
commands: [
|
||||
{
|
||||
name: "list",
|
||||
summary: "List active delegation tokens",
|
||||
usage: ["seal-use delegation list [--corp <corpId>]"]
|
||||
summary: "列出当前 Seal 租户已生效的委托授权令牌 (Delegation Tokens)",
|
||||
usage: ["seal-use delegation list [--corp <corpId>]"],
|
||||
description: "查询已在 Seal 平台签发的委托授权记录。若返回 [] 表示当前租户暂无有效委托。注意:合思主站免密链接不在此列表中。"
|
||||
},
|
||||
{
|
||||
name: "create",
|
||||
summary: "Create a new delegation token",
|
||||
summary: "创建新的 Seal 审核后台委托授权链接",
|
||||
usage: [
|
||||
"seal-use delegation create [--note <note>] [--from-link <url>] [--corp <corpId>]"
|
||||
]
|
||||
],
|
||||
description: "生成访问 Seal AI 智能审核台的委托授权链接。有效期由 Seal 服务端策略统一管理。"
|
||||
},
|
||||
{
|
||||
name: "revoke",
|
||||
summary: "Revoke an existing delegation token",
|
||||
summary: "撤销指定的 Seal 委托授权令牌",
|
||||
usage: ["seal-use delegation revoke <tokenId> [--corp <corpId>]"]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -8,11 +8,14 @@ import {
|
||||
assertHoseAssistTenantMatches,
|
||||
defaultSealUrl,
|
||||
exchangeHoseAssistLink,
|
||||
fetchHoseOpenApiKeysFromLink,
|
||||
fetchHoseStaffDetails,
|
||||
getHoseEnterpriseUrl,
|
||||
getHoseProvisionalAuthLink,
|
||||
normalizeBaseUrl,
|
||||
parseHoseAssistLink
|
||||
} from "./hose.js";
|
||||
import { getHoseAuthCache } from "./token-store.js";
|
||||
|
||||
const ORIGINAL_ENV = process.env.SEAL_HOME_TOKEN_STORE;
|
||||
const ORIGINAL_FETCH = globalThis.fetch;
|
||||
@@ -267,4 +270,98 @@ describe("hose auth helpers", () => {
|
||||
expect(res.keys[0]!.appSecurity).toBe("sec_secret_password_456789");
|
||||
expect(res.keys[0]!.active).toBe(true);
|
||||
});
|
||||
|
||||
test("getHoseProvisionalAuthLink generates independent provisional link and ignores internal cache", async () => {
|
||||
const initialExpiresAt = Date.now() + 7134_000;
|
||||
setupTokenStore({
|
||||
"corp-test": {
|
||||
hose: {
|
||||
openapi: {
|
||||
token: "existing-openapi-token",
|
||||
expiresAt: Date.now() + 3600_000
|
||||
},
|
||||
closeapi: {
|
||||
token: "existing-close-token",
|
||||
url: "https://app.ekuaibao.com/web/thirdparty.html?accessToken=existing-close-token&ekbCorpId=CORP-TEST",
|
||||
expiresAt: initialExpiresAt
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const corp: CorpConfig = {
|
||||
id: "corp-test",
|
||||
name: "Corp Test",
|
||||
environment: "production",
|
||||
seal: { endpoints: { approvalStylePreferences: "" } },
|
||||
source: {
|
||||
type: "hose",
|
||||
domain: "https://app.ekuaibao.com",
|
||||
appKey: "key",
|
||||
appSecurity: "sec",
|
||||
staffId: "staff-1",
|
||||
corpId: "CORP-TEST"
|
||||
},
|
||||
auth: { refreshTtl: 300 }
|
||||
};
|
||||
|
||||
let requestedExpireDate: number | undefined;
|
||||
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const urlStr = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
const url = new URL(urlStr);
|
||||
|
||||
if (url.pathname === "/api/openapi/v1.1/provisional/getProvisionalAuth") {
|
||||
let body: Record<string, unknown> = {};
|
||||
if (input instanceof Request) {
|
||||
body = await input.clone().json().catch(() => ({}));
|
||||
} else if (typeof init?.body === "string") {
|
||||
body = JSON.parse(init.body);
|
||||
}
|
||||
requestedExpireDate = typeof body.expireDate === "number" ? body.expireDate : undefined;
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
value: {
|
||||
message: "https://app.ekuaibao.com/web/thirdparty.html?accessToken=fresh-token-86400&ekbCorpId=CORP-TEST&pageType=home"
|
||||
}
|
||||
}),
|
||||
{ status: 200, headers: { "content-type": "application/json" } }
|
||||
);
|
||||
}
|
||||
|
||||
return new Response("not found", { status: 404 });
|
||||
}) as typeof fetch;
|
||||
|
||||
const result = await getHoseProvisionalAuthLink(corp, 86400);
|
||||
|
||||
expect(requestedExpireDate).toBe(86400);
|
||||
expect(result.expiresIn).toBe(86400);
|
||||
expect(result.token).toBe("fresh-token-86400");
|
||||
expect(result.url).toContain("fresh-token-86400");
|
||||
|
||||
// Ensure internal closeapi cache was NOT overwritten
|
||||
const cacheAfter = getHoseAuthCache("corp-test");
|
||||
expect(cacheAfter.closeapi?.token).toBe("existing-close-token");
|
||||
expect(cacheAfter.closeapi?.expiresAt).toBe(initialExpiresAt);
|
||||
});
|
||||
|
||||
test("getHoseProvisionalAuthLink rejects invalid or non-positive expiresIn", async () => {
|
||||
const corp: CorpConfig = {
|
||||
id: "corp-test",
|
||||
name: "Corp Test",
|
||||
environment: "production",
|
||||
seal: { endpoints: { approvalStylePreferences: "" } },
|
||||
source: {
|
||||
type: "hose",
|
||||
domain: "https://app.ekuaibao.com",
|
||||
appKey: "key",
|
||||
appSecurity: "sec",
|
||||
staffId: "staff-1",
|
||||
corpId: "CORP-TEST"
|
||||
},
|
||||
auth: { refreshTtl: 300 }
|
||||
};
|
||||
|
||||
expect(getHoseProvisionalAuthLink(corp, -100)).rejects.toThrow("Invalid expire seconds");
|
||||
expect(getHoseProvisionalAuthLink(corp, 0)).rejects.toThrow("Invalid expire seconds");
|
||||
});
|
||||
});
|
||||
+4
-11
@@ -403,7 +403,8 @@ export async function getHoseEnterpriseUrl(corp: CorpConfig): Promise<string> {
|
||||
|
||||
export async function getHoseProvisionalAuthLink(
|
||||
corp: CorpConfig,
|
||||
expiresIn = 7200
|
||||
expiresIn = 7200,
|
||||
_options?: { force?: boolean }
|
||||
): Promise<{
|
||||
corpId: string;
|
||||
staffId: string;
|
||||
@@ -415,16 +416,8 @@ export async function getHoseProvisionalAuthLink(
|
||||
throw new Error(`Unsupported Seal source: ${corp.source.type}`);
|
||||
}
|
||||
|
||||
const cache = getHoseAuthCache(corp.id);
|
||||
if (isFresh(cache.closeapi) && cache.closeapi.url && cache.closeapi.token) {
|
||||
const remainingSeconds = Math.max(60, Math.floor((cache.closeapi.expiresAt - Date.now()) / 1000));
|
||||
return {
|
||||
corpId: corp.source.corpId,
|
||||
staffId: corp.source.staffId,
|
||||
url: cache.closeapi.url,
|
||||
token: cache.closeapi.token,
|
||||
expiresIn: Math.min(expiresIn, remainingSeconds)
|
||||
};
|
||||
if (!Number.isFinite(expiresIn) || expiresIn <= 0) {
|
||||
throw new Error(`Invalid expire seconds: ${expiresIn}. Must be a positive integer.`);
|
||||
}
|
||||
|
||||
const openapiToken = await ensureHoseOpenapiToken(corp);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { KyInstance } from "ky";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import * as api from "./api.js";
|
||||
import { defaultSealUrl, getHoseEnterpriseUrl, getHoseProvisionalAuthLink, probeHoseDomain } from "../../core/auth/hose.js";
|
||||
import { defaultSealUrl, ensureHoseCloseApiToken, getHoseEnterpriseUrl, getHoseProvisionalAuthLink, probeHoseDomain } from "../../core/auth/hose.js";
|
||||
import { CorpConfig } from "../../core/config/types.js";
|
||||
import { loadGlobalConfig, loadCorpConfigs, getEnterprisesDirCandidates } from "../../core/config/loader.js";
|
||||
import { resolveCorpConfig } from "../../core/config/manager.js";
|
||||
@@ -1782,8 +1782,8 @@ export const sealTools = [
|
||||
);
|
||||
}
|
||||
|
||||
const linkInfo = await getHoseProvisionalAuthLink(context.corp, expiresIn);
|
||||
const provisionalToken = new URL(linkInfo.url).searchParams.get("accessToken");
|
||||
const hoseAccess = await ensureHoseCloseApiToken(context.corp);
|
||||
const provisionalToken = hoseAccess.token;
|
||||
if (!provisionalToken) {
|
||||
throw new Error("Failed to obtain Hose provisional authentication token");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user