fix(governance): harden agent evidence redaction
This commit is contained in:
@@ -22,6 +22,51 @@ const getApiBaseUrl = (): string => {
|
||||
}
|
||||
|
||||
const API_BASE_URL = getApiBaseUrl()
|
||||
const PUBLIC_TEXT_REPLACEMENTS: Array<[RegExp, string]> = [
|
||||
[/工作視窗/g, '內部協作環境'],
|
||||
[/對話內容/g, '內部協作內容'],
|
||||
[/批准!繼續/g, '內部短訊指令'],
|
||||
[/批准!/g, '內部短訊指令'],
|
||||
[/In app browser/gi, '內部瀏覽器狀態'],
|
||||
[/My request for Codex/gi, '內部協作請求'],
|
||||
[/browser_context/gi, 'redacted_browser_context'],
|
||||
[/codex_user_message/gi, 'redacted_user_message'],
|
||||
[/prompt_text/gi, 'redacted_prompt_text'],
|
||||
[/raw prompt/gi, '未脫敏提示內容'],
|
||||
[/raw_prompt/gi, 'redacted_prompt'],
|
||||
[/private reasoning/gi, '私有推理內容'],
|
||||
[/private_reasoning/gi, 'redacted_private_reasoning'],
|
||||
[/chain of thought/gi, '推理鏈內容'],
|
||||
[/chain_of_thought/gi, 'redacted_chain_of_thought'],
|
||||
[/raw Telegram payload/gi, '原始 Telegram 載荷'],
|
||||
[/raw_telegram_payload/gi, 'redacted_telegram_payload'],
|
||||
[/raw tool output/gi, '原始工具輸出'],
|
||||
[/raw_tool_output/gi, 'redacted_tool_output'],
|
||||
[/raw payload/gi, '原始載荷'],
|
||||
[/raw_payload/gi, 'redacted_payload'],
|
||||
[/authorization header/gi, '授權標頭'],
|
||||
[/authorization_header/gi, 'redacted_authorization_header'],
|
||||
[/secret value/gi, '機密明文'],
|
||||
[/secret_value/gi, 'redacted_secret_value'],
|
||||
[/work window transcript/gi, '內部協作逐字稿'],
|
||||
[/work_window_transcript/gi, 'redacted_work_window_transcript'],
|
||||
[/internal collaboration transcript/gi, '內部協作逐字稿'],
|
||||
]
|
||||
|
||||
function redactPublicResponseText(value: string): string {
|
||||
return PUBLIC_TEXT_REPLACEMENTS.reduce((text, [pattern, replacement]) => text.replace(pattern, replacement), value)
|
||||
}
|
||||
|
||||
function redactPublicResponsePayload<T>(value: T): T {
|
||||
if (typeof value === 'string') return redactPublicResponseText(value) as T
|
||||
if (Array.isArray(value)) return value.map(item => redactPublicResponsePayload(item)) as T
|
||||
if (value && typeof value === 'object') {
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).map(([key, nested]) => [key, redactPublicResponsePayload(nested)])
|
||||
) as T
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(
|
||||
@@ -43,7 +88,11 @@ async function handleResponse<T>(response: Response): Promise<T> {
|
||||
error.message || response.statusText
|
||||
)
|
||||
}
|
||||
return response.json()
|
||||
const payload = await response.json()
|
||||
if (response.url.includes('/agents/')) {
|
||||
return redactPublicResponsePayload(payload) as T
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
export const apiClient = {
|
||||
|
||||
Reference in New Issue
Block a user