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(provider-share): 拒绝超出日期范围的分享时间戳

fmfsaisai80960b05dc8c
diff --git a/apps/desktop/src/main/device-link/__tests__/providerShareInsights.test.ts b/apps/desktop/src/main/device-link/__tests__/providerShareInsights.test.ts
index d24e17c381..782c7a8d62 100644
--- a/apps/desktop/src/main/device-link/__tests__/providerShareInsights.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/providerShareInsights.test.ts
@@ -382,6 +382,33 @@ describe('provider share insights', () => {
state.active = false;
await expect(read('peer', request)).rejects.toThrow('PERMISSION_DENIED');
});
+ // #4317443934:原边界只验证有限数,1e300 会让 Intl 日期格式化崩溃。
+ // 通过真实 reader→接收解析入口覆盖四类时间字段;既有测试仅有正常毫秒值。tier: unit。
+ it.each(['updatedAt', 'windowReset', 'balanceReset', 'lastUsedAt'] as const)(
+ 'rejects invalid Date values in %s before displaying a host response',
+ async (field) => {
+ const { read } = fixture();
+ const view = await read('peer', request);
+ const account = view.quota!.accounts[0];
+ account.windows = [{
+ kind: 'week', label: null, remainingPercent: 15, resetsAt: null, windowMinutes: null,
+ }];
+ const setTime = (value: number | null) => {
+ if (field === 'updatedAt') account.updatedAt = value;
+ else if (field === 'windowReset') account.windows[0].resetsAt = value;
+ else if (field === 'balanceReset') account.balance!.resetsAt = value;
+ else view.usage!.parties[0].lastUsedAt = value;
+ };
+ for (const invalid of [1e300, -1e300, 8_640_000_000_000_001, -8_640_000_000_000_001]) {
+ setTime(invalid);
+ expect(parseProviderShareInsights(view)).toBeNull();
+ }
+ for (const valid of [null, 0, 1_792_425_600_000, 8_640_000_000_000_000, -8_640_000_000_000_000]) {
+ setTime(valid);
+ expect(parseProviderShareInsights(view)).toEqual(view);
+ }
+ },
+ );
it('strips unknown fields and ignores data for disabled capabilities on the receiving boundary', async () => {
const { read } = fixture();
const view = await read('peer', request);
diff --git a/apps/desktop/src/shared/providerShareInsights.ts b/apps/desktop/src/shared/providerShareInsights.ts
index a3ddf9ef9b..cf510f95df 100644
--- a/apps/desktop/src/shared/providerShareInsights.ts
+++ b/apps/desktop/src/shared/providerShareInsights.ts
@@ -61,17 +61,19 @@ export interface ProviderShareInsights {
// 对端返回值只保留展示字段;未知版本或缺字段不当成零额度。
const number = z.number().finite();
+// 有限数仍可能超出 Date 范围;拒绝会使接收端日期格式化抛错的时间戳。
+const timestamp = number.refine((value) => Number.isFinite(new Date(value).getTime()));
const money = z.object({ amount: number, currency: z.enum(['USD', 'CNY']) });
const quotaAccount = z.object({
state: z.enum(['ready', 'unsupported', 'unavailable', 'offline', 'needs-update', 'unlimited']),
- updatedAt: number.nullable(),
+ updatedAt: timestamp.nullable(),
windows: z
.array(
z.object({
kind: z.enum(['session', 'week', 'scoped']),
label: z.string().max(128).nullable(),
remainingPercent: number.min(0).max(100),
- resetsAt: number.nullable(),
+ resetsAt: timestamp.nullable(),
windowMinutes: number.nullable(),
}),
)
@@ -81,7 +83,7 @@ const quotaAccount = z.object({
remaining: number,
total: number.nullable(),
currency: z.enum(['USD', 'CNY']),
- resetsAt: number.nullable(),
+ resetsAt: timestamp.nullable(),
pools: z
.array(
z.object({
@@ -117,7 +119,7 @@ const schema = z.object({
isYou: z.boolean(),
isOwner: z.boolean(),
isRelay: z.boolean(),
- lastUsedAt: number.nullable(),
+ lastUsedAt: timestamp.nullable(),
days: z
.array(
z.object({