Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(media): 在私网审批中展示具体下载目标
liugaowei2a2f3d84564f
diff --git a/apps/desktop/src/main/cindy-media/__tests__/mediaDownload.test.ts b/apps/desktop/src/main/cindy-media/__tests__/mediaDownload.test.tsindex aa84931e0f..7229cbd842 100644--- a/apps/desktop/src/main/cindy-media/__tests__/mediaDownload.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/mediaDownload.test.ts@@ -53,7 +53,7 @@ describe('media download approval and network recovery', () => {const pending = download(ctx);await shown;expect(mocks.fetch).not.toHaveBeenCalled();- expect(ctx.confirm).toHaveBeenCalledWith({ origin: 'https://new.example.com', reasons: ['source'] });+ expect(ctx.confirm).toHaveBeenCalledWith({ source: 'https://new.example.com', reasons: ['source'] });approve(true);expect(await downloadedBytes(await pending)).toEqual(bytes);expect(mocks.fetch.mock.calls[0][1].headers).toBeUndefined();@@ -102,7 +102,7 @@ describe('media download approval and network recovery', () => {mocks.fetch.mockResolvedValueOnce(response(null, { status: 302, headers: { location: '/next' } })).mockResolvedValueOnce(response(null, { status: 302, headers: { location: 'https://other.example.com/video' } }));await download(ctx);- expect(ctx.confirm.mock.calls.map(([request]) => request.origin)).toEqual(['https://new.example.com', 'https://other.example.com']);+ expect(ctx.confirm.mock.calls.map(([request]) => request.source)).toEqual(['https://new.example.com', 'https://other.example.com']);expect(mocks.release).toHaveBeenCalledTimes(3);});@@ -112,9 +112,9 @@ describe('media download approval and network recovery', () => {.mockResolvedValueOnce(response(null, { status: 302, headers: { location: 'https://other.example.com/video' } })).mockRejectedValueOnce(new SsrFBlockedError('another private target'));await download(ctx);- expect(ctx.confirm.mock.calls.map(([request]) => [request.origin, request.reasons])).toEqual([- ['https://new.example.com', ['source']], ['https://new.example.com', ['network']],- ['https://other.example.com', ['source']], ['https://other.example.com', ['network']],+ expect(ctx.confirm.mock.calls.map(([request]) => [request.source, request.reasons])).toEqual([+ ['https://new.example.com', ['source']], ['https://new.example.com/video?signature=%5BREDACTED%5D', ['network']],+ ['https://other.example.com', ['source']], ['https://other.example.com/video', ['network']],]);expect(mocks.fetch.mock.calls[2][3].allowPrivateNetwork).toBe(false);});@@ -122,7 +122,7 @@ describe('media download approval and network recovery', () => {it('HTTP and a custom port require approval before dispatch', async () => {const ctx = context();await download(ctx, 'http://known.example.com:8080/video');- expect(ctx.confirm).toHaveBeenCalledWith({ origin: 'http://known.example.com:8080', reasons: ['http', 'port'] });+ expect(ctx.confirm).toHaveBeenCalledWith({ source: 'http://known.example.com:8080', reasons: ['http', 'port'] });expect(mocks.fetch.mock.calls[0][3]).toMatchObject({ allowHttp: true, targetUrl: 'http://known.example.com:8080/video' });});@@ -139,6 +139,8 @@ describe('media download approval and network recovery', () => {]);expect(mocks.fetch.mock.calls.map((call) => call[3].allowPrivateNetwork)).toEqual([false, true, false]);expect(mocks.fetch.mock.calls[2][0]).toBe(new URL(location, 'https://new.example.com').href);+ expect(ctx.confirm.mock.calls[1][0].source).toBe('https://new.example.com/video?signature=%5BREDACTED%5D');+ expect(ctx.confirm.mock.calls[2][0].source).toBe(new URL(location, 'https://new.example.com').href);expect(mocks.release).toHaveBeenCalledOnce();},);@@ -153,6 +155,20 @@ describe('media download approval and network recovery', () => {expect(mocks.fetch.mock.calls[1][1].headers).toBeUndefined();});+ it('shows the private endpoint and ordinary parameters without login or signature values', async () => {+ const ctx = context();+ mocks.fetch.mockRejectedValueOnce(new SsrFBlockedError('private'));+ await download(ctx, 'https://test-user:[email protected]/media/view?operation=read&signature=test-signature#hidden-fragment');+ const request = ctx.confirm.mock.calls.at(-1)![0];+ expect(request.reasons).toEqual(['network']);+ const shown = new URL(request.source);+ expect(shown.pathname).toBe('/media/view');+ expect(shown.searchParams.get('operation')).toBe('read');+ expect(shown.searchParams.get('signature')).toBe('[REDACTED]');+ expect(shown.hash).toBe('');+ expect(JSON.stringify(ctx.confirm.mock.calls)).not.toMatch(/test-user|test-password|test-signature|hidden-fragment/);+ });+it('a refreshed signed URL on the same origin reuses the operation approval', async () => {const ctx = context();mocks.fetch.mockResolvedValueOnce(response(null, { status: 403 }));diff --git a/apps/desktop/src/main/cindy-media/__tests__/mediaDownloadApproval.test.ts b/apps/desktop/src/main/cindy-media/__tests__/mediaDownloadApproval.test.tsindex 07a995fcb7..00129fecb1 100644--- a/apps/desktop/src/main/cindy-media/__tests__/mediaDownloadApproval.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/mediaDownloadApproval.test.ts@@ -42,7 +42,7 @@ describe('Host media permission', () => {const ctx = createMediaDownloadContext(host.session, () => true);mocks.request.mockResolvedValue({ kind: 'permission', behavior: 'allow', updatedInput: { approved: true } });try {- await expect(ctx.confirm({ origin: 'https://cdn.example.com', reasons: ['source'] })).resolves.toBe(true);+ await expect(ctx.confirm({ source: 'https://cdn.example.com', reasons: ['source'] })).resolves.toBe(true);const [session, request, signal] = mocks.request.mock.calls.at(-1)!;expect(session).toBe(host.session);expect(request).toMatchObject({ kind: 'permission', toolName: 'cindy.media.download', input: { source: 'https://cdn.example.com' } });@@ -53,12 +53,25 @@ describe('Host media permission', () => {expect(host.unsubscribe).toHaveBeenCalledOnce();});+ it('passes the displayed private target to the ordinary permission card', async () => {+ const host = hostSession();+ const ctx = createMediaDownloadContext(host.session, () => true);+ const source = 'https://internal.example.com/media/view?operation=read&signature=%5BREDACTED%5D';+ mocks.request.mockResolvedValue({ kind: 'permission', behavior: 'allow' });+ try {+ await expect(ctx.confirm({ source, reasons: ['network'] })).resolves.toBe(true);+ expect(mocks.request.mock.calls.at(-1)![1]).toMatchObject({+ kind: 'permission', toolName: 'cindy.media.download', input: { source },+ });+ } finally { ctx.dispose?.(); }+ });+it('rejects a late approval after the task stops', async () => {const host = hostSession();const ctx = createMediaDownloadContext(host.session, () => true);mocks.request.mockImplementation(async () => { host.stop(); return { kind: 'permission', behavior: 'allow' }; });try {- await expect(ctx.confirm({ origin: 'https://cdn.example.com', reasons: ['network'] })).rejects.toMatchObject({ code: 'MEDIA_DOWNLOAD_DEFERRED' });+ await expect(ctx.confirm({ source: 'https://cdn.example.com', reasons: ['network'] })).rejects.toMatchObject({ code: 'MEDIA_DOWNLOAD_DEFERRED' });expect(ctx.signal?.aborted).toBe(true);} finally { ctx.dispose?.(); }});@@ -69,7 +82,7 @@ describe('Host media permission', () => {const ctx = createMediaDownloadContext(host.session, () => current);mocks.request.mockImplementation(async () => { current = false; return { kind: 'permission', behavior: 'allow' }; });try {- await expect(ctx.confirm({ origin: 'https://cdn.example.com', reasons: ['source'] })).rejects.toMatchObject({ code: 'MEDIA_DOWNLOAD_DEFERRED' });+ await expect(ctx.confirm({ source: 'https://cdn.example.com', reasons: ['source'] })).rejects.toMatchObject({ code: 'MEDIA_DOWNLOAD_DEFERRED' });} finally { ctx.dispose?.(); }});});diff --git a/apps/desktop/src/main/cindy-media/mediaDownload.ts b/apps/desktop/src/main/cindy-media/mediaDownload.tsindex c6a7ceb736..9ec70b8e5d 100644--- a/apps/desktop/src/main/cindy-media/mediaDownload.ts+++ b/apps/desktop/src/main/cindy-media/mediaDownload.ts@@ -5,6 +5,7 @@ import path from 'node:path';import { setTimeout as delay } from 'node:timers/promises';import { SsrFBlockedError } from '@cindy/browser-control-runtime/ssrf-runtime';import { guardedOutboundFetch } from '../maker-host/outbound-fetch.js';+import { mediaRequestUrlForLog } from './mediaRequestLog.js';export type MediaDownloadReason = 'source' | 'http' | 'port' | 'credentials' | 'network';@@ -15,7 +16,7 @@ export interface MediaDownloadContext {approvals?: Set<string>;dispose?(): void;assertActive(): void;- confirm(input: { origin: string; reasons: MediaDownloadReason[] }): Promise<boolean>;+ confirm(input: { source: string; reasons: MediaDownloadReason[] }): Promise<boolean>;}export class MediaDownloadError extends Error {@@ -66,7 +67,10 @@ export async function downloadMediaResult(input: {if (!input.context) {throw new MediaDownloadError('MEDIA_DOWNLOAD_CONFIRMATION_REQUIRED', '本次下载需要用户确认,当前任务的审批通道不可用');}- const allowed = await input.context.confirm({ origin: url.origin, reasons });+ // Private-network approval is bound to an exact target, so show its path+ // and non-secret query values using the existing URL redaction policy.+ const source = reasons.includes('network') ? mediaRequestUrlForLog(url.href) : url.origin;+ const allowed = await input.context.confirm({ source, reasons });assertActive();if (!allowed) {throw new MediaDownloadError('MEDIA_DOWNLOAD_DENIED', '用户未允许本次下载,已停止;不要自动重试或再次请求审批');diff --git a/apps/desktop/src/main/cindy-media/mediaDownloadApproval.ts b/apps/desktop/src/main/cindy-media/mediaDownloadApproval.tsindex e05ce26e3f..66cb1b0996 100644--- a/apps/desktop/src/main/cindy-media/mediaDownloadApproval.ts+++ b/apps/desktop/src/main/cindy-media/mediaDownloadApproval.ts@@ -26,7 +26,7 @@ export function createMediaDownloadContext(signal: controller.signal,dispose: unsubscribe,assertActive,- confirm: async ({ origin, reasons }) => {+ confirm: async ({ source, reasons }) => {assertActive();// Bound only the human decision; generation has its own request timeout.const approvalSignal = AbortSignal.any([controller.signal, AbortSignal.timeout(8 * 60_000)]);@@ -37,7 +37,7 @@ export function createMediaDownloadContext(toolName: 'cindy.media.download',title: t('newChat.mediaDownload.title'),description: `${t('newChat.mediaDownload.description')}\n${details}\n${t('newChat.mediaDownload.scope')}`,- input: { source: origin },+ input: { source },metadata: { hostOwnedConfirmation: 'media_download' },};const decision = await session.runHostInteraction(request, () =>diff --git a/docs/dev-rules/media-storage-and-protocols.md b/docs/dev-rules/media-storage-and-protocols.mdindex e804ada805..afbbe43b93 100644--- a/docs/dev-rules/media-storage-and-protocols.md+++ b/docs/dev-rules/media-storage-and-protocols.md@@ -79,7 +79,8 @@- 默认经 `guardedOutboundFetch` 做 HTTPS、DNS/IP 校验及固定 IP 连接。人工例外只对当前精确 URL 的单跳生效,不自动传递到重定向目标,不改变其他网络调用的默认策略。来源批准按 origin 复用;受限网络例外按不含 fragment 的完整 URL 绑定,路径或 query- 变化后须重新确认该受限目标,不能借同源跳转访问另一内部接口。+ 变化后须重新确认该受限目标,不能借同源跳转访问另一内部接口。受限网络卡片显示+ 当前目标的路径及脱敏后的 query,复用现有 URL 脱敏规则,不显示登录信息或签名值。不附带生成接口凭证;地址内登录信息须单独确认,且不得沿重定向传递。- 网络时间累计最多 120 秒,连续 30 秒没有响应或数据则重试,单次人工审批最多等待八分钟。上游生成沿用自身请求超时,不另加覆盖生成阶段的下载计时器。