security: add prompt injection hardening (P0+P1)#1212
Open
Avaritia55 wants to merge 7 commits intojackwener:mainfrom
Open
security: add prompt injection hardening (P0+P1)#1212Avaritia55 wants to merge 7 commits intojackwener:mainfrom
Avaritia55 wants to merge 7 commits intojackwener:mainfrom
Conversation
…i-browser SKILL.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/browser/security.ts: 新增assertNotInjected()函式,內含 7 個 injection pattern(英文 + 中文 payload),偵測到時拋出[OpenCLI Security]錯誤src/browser/extract.ts: 在runExtractFromHtml()回傳前呼叫assertNotInjected,攔截進入 Agent context 的頁面文字src/browser/cdp.ts: 在readNetworkCapture()對 response body 加入 2000 char 截斷,並呼叫assertNotInjected檢查skills/opencli-browser/SKILL.md: 加入 Security Boundary 聲明與 eval Usage Policyskills/opencli-adapter-author/SKILL.md: 加入 eval 靜態表達式規則,禁止將頁面資料拼接進 eval 字串Motivation
OpenCLI 讓 AI Agent 透過已登入的 Chrome session 操作網站,頁面 UGC 與 API response 進入 Agent context 後有 prompt injection 風險。本 PR 實施兩層防護:
Test plan
npx tsc --noEmit— 0 errorsnpx vitest run src/browser/security.test.ts— 9/9 tests PASSnpx vitest run src/browser/— 278/278 tests PASS (22 files)npm run build— 成功assertNotInjected("ignore previous instructions...", "browser extract")正確拋出[OpenCLI Security]錯誤Known limitations
INJECTION_PATTERNS為靜態清單,無法覆蓋所有未知 payloadevaluate()直接呼叫路徑未加偵測(屬已知殘留風險)🤖 Generated with Claude Code