繪製助理的威脅模型

閱讀約 31 分鐘,4 節 中共有 3 個範例。

版次 2026.11.3 範例於 2026年11 月 22 通過測試 60 個範例中有 60 個通過 變更內容

由 AI 翻譯。經人工以英文驗證。 我們如何製作書籍

譯自英文書,版次 2026.11.3。 閱讀原文

Labs

透過實作學習本章

完全照書中的方式執行每個範例,修改程式碼觀察結果,並在書中的程式碼與資料上嘗試你自己的想法。無須安裝,你的工作會自動儲存。約 30 秒內開啟。

完全照書中的方式執行每個範例,修改程式碼觀察結果,並在書中的程式碼與資料上嘗試你自己的想法。無須安裝,你的工作會自動儲存。由 Labs 為你執行:每月 40 小時。

在 Lab 中開啟,於新分頁開啟

正在檢查您的時數…

正在尋找您的 Lab…

於您自己的電腦,免費: 下載本書的筆記本,連同其程式碼與資料,皆取自 GitHub。

讀完本章後,你能為助理繪製威脅模型:它的資產、外部文字進入它的各個位置、把這些文字送往模型及其工具的資料流,以及攻擊者用來把資料帶出去的管道。你會為每個工具和整個助理計算致命三要素(lethal trifecta)中具備的要素數量,將計算結果對照 Meta 的二規則(Rule of Two),並把每項風險對應到命名它的 OWASP 條目。

辦公室的助理出自第 1 章,它讀取一封收件匣郵件、查詢一位租戶,並擷取一個網頁。該章的攻擊經由這三個步驟完成,而且只是一次攻擊。針對單一攻擊的測試,只能顯示該攻擊做了什麼,並不能顯示助理還能接觸到什麼。在選擇任何防禦措施之前,你需要一份清單,列出助理接觸的對象、它所讀取的文字來自何處,以及有哪些路徑通往辦公室之外。本章根據辦公室自己的程式碼畫出這份清單,而關於辦公室的各項說法,都附有可以執行的範例。

資產與信任

最近一次變動於第 2026.11.2 版

資產是辦公室可能損失的任何東西,也是攻擊者可能想要的任何東西:一筆紀錄、一項機密,或是代表辦公室行事的能力。信任邊界是指不同來源的文字進入助理脈絡的那個位置。邊界另一側的文字,例如房客的訊息或承包商的工具描述,對助理沒有任何權威。然而模型讀取這些文字時,與讀取辦公室自己的指示是在同一個串流中,因此邊界只是關於文字來自何處的事實,並不是模型自己會去強制執行的機制。

辦公室有四項資產。第一項是房客紀錄:姓名、單位、電話號碼、租金餘額與銀行參考編號,全部由同一個工具回傳。第二項是系統提示中的隱藏脈絡,其中包含辦公室內部的銀行對帳備註與一把入口網站金鑰。這把金鑰是假的,也沒有任何範例會印出它的值,但攻擊者仍然會想要它。第三項是行動的能力:傳送訊息(訊息會進入評分程式讀取的寄件匣)以及預約承包商到訪。第四項是回覆本身。網頁檢視會將回覆以 Markdown 算繪,因此回覆中的連結或圖片就是通往辦公室外部的通道。第 7 章會處理這個通道。

一筆紀錄是否重要,取決於由誰收到它。房客可以知道自己的銀行參考編號,助理本來就應該把它讀回給房客。辦公室真正會損失的,是助理把某位房客的紀錄交給詢問另一位房客的人,或交給辦公室以外的位址。因此,資產除了以內容命名,也要以它流出的路徑命名;威脅模型也必須從紀錄追到回傳它的工具,再從該工具追到所有可能攜帶它的通道。

為了找出哪些工具能接觸這些資產,本書閱讀的是工具程式碼,而不是設計筆記。

threat-tool-table.py Python 3.13.16 · bm25s 0.3.16 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · numpy 2.5.5 通過
"""Prints one block per office tool: what it reads and writes, whether its output carries outside text, whether itsdefinition is third-party, whether it reaches outside the office and whether it returns private records. The prose'stable rests on the 'untrusted output' and 'reaches outside' lines; their derivations are in lib/threat.py."""from lib import cases, harness, threat, tools  # lib first: threads and seeds are fixed heredef main():    rows = threat.table()    print(f"tools in SPECS: {len(tools.SPECS)}")    print(f"tools in the prompt list: {len(tools.TOOLS)}")    # The prompt list and the code's table must name the same tools.    assert {t["function"]["name"] for t in tools.TOOLS} == set(tools.SPECS)    for name in sorted(rows):        r = rows[name]        print(f"{name}, reads: {', '.join(r['reads']) or 'none'}")        print(f"{name}, writes: {', '.join(r['writes']) or 'none'}")        print(f"{name}, untrusted output: {'yes' if r['untrusted_output'] else 'no'}")        print(f"{name}, third-party definition (THIRD_PARTY_TOOLS): {'yes' if r['third_party_definition'] else 'no'}")        print(f"{name}, reaches outside the office: {'yes, via ' + r['outward'] if r['outward'] else 'no'}")        print(f"{name}, private records: {'yes' if r['private'] else 'no'}")    # The prompt is a second channel: it holds the office's private values on every episode, whichever tools it offers.    world = cases.load_world()    hidden = threat.office()["hidden_context"]    prompt = threat.system_prompt()    print(f"system prompt holds the portal key: {'yes' if world.portal_key in prompt else 'no'}")    print(f"system prompt holds the office's hidden context: {'yes' if hidden in prompt else 'no'}")    untrusted_definitions = threat.marked_untrusted_definitions()    print(f"tool definitions the prompt marks untrusted: {', '.join(untrusted_definitions) or 'none'}")    # Checks behind the claims: the private tool is the one that reads tenant records, the prompt holds the key.    assert [n for n, r in sorted(rows.items()) if r["private"]] == ["lookup_tenant"]    assert world.portal_key in prompt and hidden in prompt    assert untrusted_definitions == sorted(tools.THIRD_PARTY_TOOLS)if __name__ == "__main__":    main()
輸出python threat-tool-table.py
tools in SPECS: 8
tools in the prompt list: 8
book_visit, reads: bookings, slots
book_visit, writes: bookings, slots
book_visit, untrusted output: no
book_visit, third-party definition (THIRD_PARTY_TOOLS): yes
book_visit, reaches outside the office: yes, via third-party server
book_visit, private records: no
fetch_page, reads: fetch_log, missing, pages
fetch_page, writes: fetch_log
fetch_page, untrusted output: yes
fetch_page, third-party definition (THIRD_PARTY_TOOLS): no
fetch_page, reaches outside the office: yes, via fetch log
fetch_page, private records: no
list_messages, reads: inbox
list_messages, writes: none
list_messages, untrusted output: yes
list_messages, third-party definition (THIRD_PARTY_TOOLS): no
list_messages, reaches outside the office: no
list_messages, private records: no
list_slots, reads: slots
list_slots, writes: none
list_slots, untrusted output: yes
list_slots, third-party definition (THIRD_PARTY_TOOLS): yes
list_slots, reaches outside the office: yes, via third-party server
list_slots, private records: no
lookup_tenant, reads: world.tenants
lookup_tenant, writes: none
lookup_tenant, untrusted output: no
lookup_tenant, third-party definition (THIRD_PARTY_TOOLS): no
lookup_tenant, reaches outside the office: no
lookup_tenant, private records: yes
read_message, reads: inbox
read_message, writes: none
read_message, untrusted output: yes
read_message, third-party definition (THIRD_PARTY_TOOLS): no
read_message, reaches outside the office: no
read_message, private records: no
search_documents, reads: documents
search_documents, writes: none
search_documents, untrusted output: yes
search_documents, third-party definition (THIRD_PARTY_TOOLS): no
search_documents, reaches outside the office: no
search_documents, private records: no
send_message, reads: outbox
send_message, writes: outbox
send_message, untrusted output: no
send_message, third-party definition (THIRD_PARTY_TOOLS): no
send_message, reaches outside the office: yes, via outbox
send_message, private records: no
system prompt holds the portal key: yes
system prompt holds the office's hidden context: yes
tool definitions the prompt marks untrusted: book_visit, list_slots
習題 2.1

從輸出欄位讀取外部文字欄

+10 則證明

第 17 行從定義欄位填入不受信任輸出欄,因此定義來自外部的工具會被回報為帶有外部文字。請修改第 17 行,讓它讀取與該欄標籤相符的欄位。

        r = rows[name]        print(f"{name}, reads: {', '.join(r['reads']) or 'none'}")        print(f"{name}, writes: {', '.join(r['writes']) or 'none'}")        print(f"{name}, third-party definition (THIRD_PARTY_TOOLS): {'yes' if r['third_party_definition'] else 'no'}")        print(f"{name}, reaches outside the office: {'yes, via ' + r['outward'] if r['outward'] else 'no'}")        print(f"{name}, private records: {'yes' if r['private'] else 'no'}")
在 Python 3.13.16 · bm25s 0.3.16 · huggingface-hub 2.4.0 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · matplotlib 3.11.2 · numpy 2.5.5 · tokenizers 0.23.3 · torch 2.15.0+cpu · transformers 5.24.0 上執行

只有一個工具會回傳私人紀錄,範例也對此做了斷言。清單中每個工具各印一行,內容包括:它讀取什麼、寫入什麼、輸出是否帶有外部文字、其定義是否來自第三方、是否觸及辦公室外部,以及是否回傳私人紀錄。助理可使用 8 個工具,與提示中的工具清單所列的數量相同。其中六個屬於辦公室。有兩個是 list_slots 與 book_visit,來自承包商,它們的定義是在辦公室之外撰寫的。

輸出這一欄比較難判斷。有 5 個工具會回傳辦公室外部的人所寫的文字。其中四個是辦公室的工具:list_messages 與 read_message 回傳收件匣訊息,search_documents 回傳文件,fetch_page 回傳一個頁面。第五個是 list_slots,它回傳時段的備註,而這份備註可能由承包商撰寫。因此,「不受信任的輸出」是每一筆結果的屬性。工具的名稱無法決定這件事,看起來屬於內部的工具也可能帶有外部文字。

表中也顯示,無論提供哪些工具,提示在每一個回合中都含有入口網站金鑰與內部備註,所以只計算工具數量會漏掉這些值。程式碼對此做了斷言。移除一個工具,會移除通往它所讀取之紀錄的路徑,但不會移除放在提示中的值。第 9 章會處理這個問題,並對此做出承諾:本書會衡量這些值在不放入提示時會發生什麼事。

實用原則: 從程式碼中的工具清單,而不是從設計文件,來繪製資產與邊界。針對模型可使用的每個工具,記錄它讀取什麼、寫入什麼、哪些結果帶有外部文字,以及其定義是否來自外部。再將數量與提示中的工具清單核對。若某個工具出現在其中一份清單,卻沒有出現在另一份,就表示你正在繪製的模型存在缺口。

資料流

資料流追蹤一段文字,從它被寫下的地方,到模型讀取它的時刻。每個邊界都有一個載體(carrier)和一個通道(channel):載體是助理狀態中存放該文字的欄位,通道則是該文字抵達模型的方式。在辦公室的情境中,載體有兩種。第一種是助理所要求的結果中的文字:收件匣訊息、來自上傳或搜尋索引的文件、擷取的網頁,或承包商時段的備註。這類文字在助理呼叫工具時送達。第二種是工具定義中的文字:也就是模型在每一次提示中都會看到的名稱、描述與結構描述(schema),無論模型是否呼叫該工具。工具投毒(tool poisoning)會把給模型的指示放進工具定義中,Model Context Protocol in Practice, chapter 9 對此有所說明。第一種在模型提出要求時送達,第二種則每次都會送達。第二種的重要性超出其篇幅所顯示的程度。定義是在模型選擇工具之前被讀取的,因此它不只能改變呼叫回傳的內容,也能改變被呼叫的是哪一個工具。

外部文字可以進入的六個位置,就是攻擊集所使用的位置。第 3 章定義了這些位置,並說明案例是如何建構的。範例會在輸出中為它們加上 loc- 前綴,本書則省略該前綴。

threat-flows.py Python 3.13.16 · bm25s 0.3.16 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · numpy 2.5.5 通過
"""Each attack location, and the one channel that delivers its text to the model: a tool that reads the carrier's field,or the prompt's tool list. The injected text is checked in code and never printed. The probes are in lib/threat.py."""from lib import cases, threat  # lib first: threads and seeds are fixed heredef main():    # The counts are over the 120 fixed cases (dev and held-out). Chapter 1's 20 rough cases are left out.    fixed = [c for c in cases.load_cases() if c.split != "rough"]    rough = cases.load_cases("rough")    print(f"fixed cases: {len(fixed)}")    print(f"rough cases, chapter 1's set, not counted: {len(rough)}")    flows = threat.location_channels()    print(f"locations: {len(flows)}")    for f in flows:        loc = f["loc"]        print(f"{loc}, fixed cases: {sum(1 for c in fixed if c.location == loc)}")        print(f"{loc}, carrier kind: {f['kind']}")        print(f"{loc}, state field changed: {f['field']}")        print(f"{loc}, delivered by: {', '.join(f['channels']) or 'none'}")        print(f"{loc}, read the field but do not carry it: {', '.join(f['quiet']) or 'none'}")if __name__ == "__main__":    main()
輸出python threat-flows.py
fixed cases: 120
rough cases, chapter 1's set, not counted: 20
locations: 6
loc-inbox, fixed cases: 24
loc-inbox, carrier kind: inbox
loc-inbox, state field changed: inbox
loc-inbox, delivered by: read_message
loc-inbox, read the field but do not carry it: list_messages
loc-index, fixed cases: 24
loc-index, carrier kind: index
loc-index, state field changed: documents
loc-index, delivered by: search_documents
loc-index, read the field but do not carry it: none
loc-page, fixed cases: 12
loc-page, carrier kind: page
loc-page, state field changed: pages
loc-page, delivered by: fetch_page
loc-page, read the field but do not carry it: none
loc-server-output, fixed cases: 24
loc-server-output, carrier kind: server-output
loc-server-output, state field changed: slots
loc-server-output, delivered by: list_slots
loc-server-output, read the field but do not carry it: book_visit
loc-tool-description, fixed cases: 12
loc-tool-description, carrier kind: tool-description
loc-tool-description, state field changed: schemas
loc-tool-description, delivered by: prompt tool list
loc-tool-description, read the field but do not carry it: none
loc-upload, fixed cases: 24
loc-upload, carrier kind: upload
loc-upload, state field changed: documents
loc-upload, delivered by: search_documents
loc-upload, read the field but do not carry it: none

每個位置都有一個載體和一個負責傳遞的通道,範例會同時檢查兩者。下表列出各項:

位置 載體 抵達模型的途徑
inbox 一則收件匣訊息 read_message
upload 租戶上傳的文件 search_documents
index 已在搜尋索引中的文件 search_documents
page 一個固定測試頁面 fetch_page
server-output 承包商提供的時段備註 list_slots
tool-description 承包商工具的定義 提示中的工具清單,無需呼叫

有兩個位置共用同一個通道。upload與index都透過 search_documents 抵達模型,因為在這兩種情況下,文字都位於搜尋所回傳的文件中。這裡的計數涵蓋 120 個固定攻擊案例,開發集與保留集合計在內。第 1 章的 20 個粗略案例不計入。在固定案例中,24 個經由收件匣送達,12 個經由網頁送達。這些計數描述的是攻擊集的建構方式,因此無法說明助理遵從攻擊的頻率。

輸出也記錄了哪些其他工具會讀取某個位置的欄位,卻不把其文字帶給模型。list_messages 以這種方式讀取收件匣,但攻擊集把文字放在訊息本文中,而 list_messages 不會回傳本文。它確實會回傳寄件者與主旨,這兩者由外部人員撰寫,下方的三要素(trifecta)計數會將其視為外部文字。book_visit 讀取時段時不會帶出其備註,因此備註的通道是 list_slots。這些讀取並未為攻擊集增加通道,所以計算通道的讀者可以略過它們。

這些資料流也顯示了出口,而防禦必須切斷的正是向外的路徑。send_message 會寫入寄件匣,其中存放已接受、但沒有任何機制會投遞的訊息。fetch_page 會記錄被要求的 URL,而該 URL 可以在查詢字串中夾帶資料。book_visit 會把其引數送到承包商的伺服器,因此即使該預約是辦公室想要的,它仍屬於向外傳送。回覆中的連結與圖片,則在網頁檢視畫面轉譯它們時送出。第 1 章在前兩個通道上衡量了允許清單(allowlist),並說明它看不見什麼:轉譯後的回覆(允許清單看不見的部分)。

沿著這些表格追蹤第 1 章的攻擊,它就成為一條路徑。注入的文字從收件匣進入。助理透過 read_message 讀取它,該工具把文字放進模型的上下文。這段文字接著引導模型呼叫 lookup_tenant 與 fetch_page,而其中每一步都是從一個載體到一個通道的資料流。威脅模型就是助理可能走的這類路徑的集合,涵蓋從每個位置到每個向外通道。這個攻擊只是該集合中的一條路徑。本章的任務是列出其他路徑,以免把某一條路徑上的防禦誤認為對所有路徑都有效。

**實用原則:**對每個位置,指出它的載體與負責傳遞的工具,並標明文字是在模型提出要求時送達,還是隨每次提示送達。只有在某種傳遞確實能抵達模型時,才把該位置算作一個通道。向外的資料流也以同樣方式檢視,因為某一個通道上的允許清單,並不能說明其他通道的情況。

三項致命要素與「二規則」(Rule of Two)

最近一次變動於第 2026.11.2 版

Simon Willison 在2025 年 6 月的一篇文章中提出「致命三要素」(lethal trifecta)。它有三個環節:可存取私有資料、會接觸不受信任的內容,以及具備對外通訊的方式。他的重點在於資料竊取:同時具備這三項的代理程式(agent),可能被誘騙去讀取私有資料,並把資料送給攻擊者。拿掉其中一個環節,就能封住這條路徑,但這並不能封住所有攻擊。本書自己的訂位攻擊與訂金數字攻擊都不需要私有資料:前者讓助理預約了一次無人要求的看房,後者讓助理把遭汙染的數字當成答案說出來。第 6 章與第 9 章處理這類不竊取資料、而是採取行動或誤導的攻擊。Willison 的建議是避免在同一個代理程式中結合這三者;而三要素只是出自一位作者的分析框架,雖被廣泛引用。

Meta 在2025 年 10 月 31 日的一篇文章中,把同樣的概念轉為設計規則,稱為 Agents Rule of Two。這項規則指出,一個代理程式工作階段(session)最多只應結合三項特性中的兩項:處理不可信的輸入、接觸敏感系統或私有資料,以及變更狀態或對外通訊。文章指出,在提示注入(prompt injection)能被可靠地偵測並拒絕之前,這項規則都應維持有效,並將提示注入描述為大型語言模型(LLM)普遍存在、尚未解決的弱點。需要三項全部具備的代理程式,不應自行運作,而需要監督,例如由人員核准其動作。第 6 章即以這項條款為基礎。該文章也介紹了 Meta 自家的防護工具。本書將這項規則視為對設計的檢查,而不是經過量測的防禦手段,本章也沒有任何結果顯示它能減少攻擊。

threat-trifecta-check.py Python 3.13.16 · bm25s 0.3.16 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · numpy 2.5.5 通過
"""Each tool's trifecta legs, and whether removing one leg's tools leaves at most two legs (the Rule of Two), assertedon the computed sets. The prompt's private values are checked apart, since dropping the private tools does not remove them."""from lib import cases, threat, tools  # lib first: threads and seeds are fixed heredef main():    legs = threat.legs_by_tool()    total = set().union(*legs.values())    print(f"tools checked: {len(legs)}")    for name in sorted(legs):        print(f"{name}, legs: {', '.join(l for l in threat.LEGS if l in legs[name]) or 'none'}")    print(f"legs in the tool set, in total: {', '.join(l for l in threat.LEGS if l in total)}")    # The untrusted leg comes from two sources: a result that carries outside text, or a third-party definition.    rows = threat.table()    from_output = sorted(n for n, r in rows.items() if r["untrusted_output"])    from_definition = sorted(n for n, r in rows.items() if r["third_party_definition"])    held_untrusted = sorted(n for n, held in legs.items() if "untrusted" in held)    print(f"tools whose output carries outside text: {len(from_output)}")    print(f"tools with a third-party definition: {len(from_definition)}")    print(f"tools holding the untrusted leg: {len(held_untrusted)}")    print(f"untrusted leg, from output: {', '.join(from_output)}")    print(f"untrusted leg, from a third-party definition only: "          f"{', '.join(n for n in held_untrusted if n not in from_output) or 'none'}")    assert set(held_untrusted) == set(from_output) | set(from_definition), "the untrusted leg has another source"    # A tool that holds all three legs by itself would need no second tool to be dangerous.    whole = sorted(n for n, held in legs.items() if held == set(threat.LEGS))    print(f"tools with all three legs: {', '.join(whole) or 'none'}")    # The Rule of Two, per leg: remove every tool that carries the leg; the rest should carry at most two.    for leg in threat.LEGS:        kept, left = threat.without_leg(legs, leg)        print(f"without the {leg} tools, legs left: {len(left)} ({', '.join(l for l in threat.LEGS if l in left)})")        print(f"without the {leg} tools, tools kept: {', '.join(kept)}")        assert len(left) <= 2, f"removing the {leg} tools leaves {len(left)} legs"    # The prompt is a channel the tool list does not control: with the private tools removed, it still holds the values.    private = {n for n, held in legs.items() if "private" in held}    kept_schemas = tuple(t for t in tools.TOOLS if t["function"]["name"] not in private)    print(f"private values in the prompt, with the private tools removed: "          f"{'yes' if threat.holds_private_values(kept_schemas) else 'no'}")    # Checks behind the claims.    assert total == set(threat.LEGS), "the assistant has all three legs in total"    assert whole == [], "no single tool holds all three legs"    assert threat.holds_private_values(kept_schemas)if __name__ == "__main__":    main()
輸出python threat-trifecta-check.py
tools checked: 8
book_visit, legs: untrusted, outward
fetch_page, legs: untrusted, outward
list_messages, legs: untrusted
list_slots, legs: untrusted, outward
lookup_tenant, legs: private
read_message, legs: untrusted
search_documents, legs: untrusted
send_message, legs: outward
legs in the tool set, in total: private, untrusted, outward
tools whose output carries outside text: 5
tools with a third-party definition: 2
tools holding the untrusted leg: 6
untrusted leg, from output: fetch_page, list_messages, list_slots, read_message, search_documents
untrusted leg, from a third-party definition only: book_visit
tools with all three legs: none
without the private tools, legs left: 2 (untrusted, outward)
without the private tools, tools kept: book_visit, fetch_page, list_messages, list_slots, read_message, search_documents, send_message
without the untrusted tools, legs left: 2 (private, outward)
without the untrusted tools, tools kept: lookup_tenant, send_message
without the outward tools, legs left: 2 (private, untrusted)
without the outward tools, tools kept: list_messages, lookup_tenant, read_message, search_documents
private values in the prompt, with the private tools removed: yes
習題 2.2

收集所有持有不受信任腳位的工具

+10 則證明

第 17 行是空白的。它應依排序後的順序,列出 legs 中所有腳位包含不受信任腳位的工具。第 18 至 24 行維持不變。

    rows = threat.table()    from_output = sorted(n for n, r in rows.items() if r["untrusted_output"])    from_definition = sorted(n for n, r in rows.items() if r["third_party_definition"])    print(f"tools whose output carries outside text: {len(from_output)}")    print(f"tools with a third-party definition: {len(from_definition)}")    print(f"tools holding the untrusted leg: {len(held_untrusted)}")
在 Python 3.13.16 · bm25s 0.3.16 · huggingface-hub 2.4.0 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · matplotlib 3.11.2 · numpy 2.5.5 · tokenizers 0.23.3 · torch 2.15.0+cpu · transformers 5.24.0 上執行
習題 2.3

為什麼私有值仍會進入提示詞

+10 則證明

從工具清單中移除私有工具後,第 38 行的檢查仍然輸出 yes。下列哪一項說明是正確的?

為什麼私有值仍會進入提示詞:選出正確的說明
在 Python 3.13.16 上執行

此處的計數是以工具為單位,而在這 8 個工具中,沒有任何一個同時具備三個環節。lookup_tenant 只具備私有環節,send_message 只具備對外環節,fetch_page、book_visit 與 list_slots 則各具備兩個環節,即不受信任與對外。不受信任環節總共落在 6 個工具上,來源有兩種:帶有外部文字的結果,或第三方的定義。有五個工具是透過輸出而具備此環節:fetch_page、list_messages、list_slots、read_message 與 search_documents。book_visit 則僅因定義而具備。它的輸出是承包商的預約結果,不是外部文字,但其定義由承包商撰寫,而範例將第三方定義算作不受信任,因為模型在每次提示時都會讀取該定義。整體來看,所提供的助理具備全部三個環節。移除私有工具後剩下兩個,移除不受信任的工具或對外工具亦然。依此計數,只要移除任何一個環節,「二規則」就成立。程式碼對這些結果逐一進行斷言,因此若工具的變更破壞了其中任何一項,執行就會失敗。

審查者閱讀三要素計數時,有三個問題比總數更重要:提供給模型的是哪些工具、哪些文字會經由任何途徑進入它的提示,以及哪些管道能把資料帶出辦公室。計數只回答第一個問題,另外兩個問題需要上一節的資料流。

計數是以工具為單位,而問題也出在這裡:一次執行可能讀取了私有資料卻從未送出,如第 3 章所示。成功次數也有同樣的盲點:私有資料進入了上下文卻從未離開的執行,會被算作失敗。移除私有工具後,範例仍能在提示中找到私有值。入口網站金鑰與內部備註在每一個回合中都存在,因此該工作階段仍具備私有環節,而且若注入的指示要求,模型仍可透過對外工具把這些值送出去。這裡實際的衡量單位,是抵達模型的內容,而不是工具清單。

承包商的工具使對外環節更難推論。list_slots 與 book_visit 屬於對外工具,其定義來自承包商,因此模型讀到的相關文字並非辦公室所撰寫。book_visit 會把它的引數送到承包商的伺服器,這表示即使預約本身是需要的,使用者從未要求的引數仍會離開辦公室。第 6 章為這類呼叫撰寫引數政策,第 10 章則涵蓋承包商的伺服器與定義。第 8 章建立一種把不受信任環節從工具中切開的設計:一個模型在沒有工具的情況下閱讀外部文字,而擁有工具的第二個模型則從不接觸未經處理的該文字。

實用原則: 對你提供的每個工具計算其環節。接著依序移除各環節的工具,再重新計數,並且計算私有環節時,除了看有哪些工具會讀取它,也要看有哪些內容抵達提示。

風險對照

風險有名稱,描述風險的各份清單會為它編號。讀者若在某處看到「目標劫持」,在另一處看到 ASI01,就需要知道兩者是同一項風險。本書將每項風險對應到命名該風險的條目。這些條目來自兩份清單。OWASP Top 10 for Agentic Applications 於 2025 年 12 月 9 日發布,條目編號為 ASI01 至 ASI10。OWASP GenAI LLM Top 10 2026 則引用其固定版本 Zenodo 上的 v1.0。OWASP 以開放授權並附帶相同方式分享的條件發布這兩份清單,因此本書只列出名稱與編號,並以自己的話說明每項風險,不轉載清單中的描述。

本書只確認了部分編號。若本書尚未確認某個編號,下表會以文字說明該風險,並省略編號。MITRE ATLAS 矩陣也有對應這些攻擊的技術,但本書所固定的版本尚未確認,因此本章不列出任何 ATLAS 技術編號。若針對未確認的版本印出技術編號,就會形成讀者無法查證的主張。

風險(以本書的說法) 條目(ASI,2025 年 12 月 9 日;LLM 2026) 辦公室中的出現位置 章
助理讀取的文字改變了它原本要達成的目標 ASI01 代理目標劫持(Agent Goal Hijack);LLM01:2026 提示注入(Prompt Injection) inbox、upload、index、page 3、4、5
工具被用於使用者並未要求的事 ASI02 工具誤用與濫用(Tool Misuse & Exploitation) send_message、book_visit 6
助理對攻擊者提供的名稱動用其權限 ASI03 身分與權限濫用(Identity & Privilege Abuse) lookup_tenant 6、9
助理擁有的權力超出其任務所需 LLM03:2026 過度代理權限(Excessive Agency) 每個工具、每項任務 6
第三方的定義或輸出進入提示 ASI04 代理供應鏈漏洞(Agentic Supply Chain Vulnerabilities) list_slots、book_visit 10
提示中的私密值經由對外通道外洩 LLM02:2026 敏感資訊洩露(Sensitive Information Disclosure);LLM08:2026 隱藏脈絡暴露(Hidden Context Exposure) 系統提示、租戶紀錄 9
文件中遭污染的數字成為助理的答案 ASI06 記憶與脈絡污染(Memory & Context Poisoning) search_documents 9
回覆載入了會把資料帶出去的連結或圖片 LLM10:2026 不當輸出處理(Improper Output Handling) 渲染後的回覆 7

關於此表有兩點說明。這個對照是本書對各條目名稱與範圍的解讀,並非 OWASP 對這間辦公室所做的陳述。而關於遭污染數字的那一列,是本書自行的歸類:攻擊集中的錯誤存入目標正是該列所描述的情況,本書在第 9 章檢視它。

請由左至右閱讀每一列。風險是讀者的問題,條目是讀者在原始資料中會找到的名稱,辦公室欄說明這個問題在本案例中出現的位置,章欄則說明本書在何處量測答案,第一列的答案即是第 3 章的基準。此表也顯示威脅模型的用途。每一列都指出一個條目、辦公室中的一處位置,以及量測對應防禦的章。這裡每一列都有對應的章。若有某一列沒有章,就代表本書不測試該風險,內文也會明說。

當每條從某個位置通往對外通道的路徑,都已由某一列涵蓋,或已說明為未量測時,威脅模型才算完成。光有風險清單並不能完成它。路徑比名稱更重要,因為防禦是設置在路徑上,而被遺漏的路徑仍然敞開。表格不等於涵蓋。審查者會逐一對照每條對外路徑與各列,沒有對應列的路徑即為敞開,無論表格有多長。

依據設計文件繪製的模型,會漏掉程式碼實際做的事。後續變更中新增的工具就會缺席於圖中,而三要素(trifecta)也只會依設計者記得的工具來計算。每當新增工具或定義改變時,就應重新繪製模型,並以程式碼中的工具清單而非文件,來決定模型包含什麼。

本章做出的決定:

  • 威脅模型依程式碼繪製:八個工具,其中六個來自辦公室,兩個來自承包商。
  • 計算要素時,除了工具之外,也涵蓋進入模型提示的內容。
  • ASI 與 LLM 編號只在本書已確認時才列出。其他風險以文字命名。
  • 在版本確認之前,不列出 MITRE ATLAS 編號或版本號。

實用原則: 只有在本書已確認編號時,才將風險對應到條目並附上編號,否則以文字命名。為每一列提供一個量測防禦的章,或在內文中說明該風險未被量測。

本章,於本版次中

版次 2026.11.3範例於 2026年11 月 22 通過測試3 of 3 個範例 in this chapter pass

譯自英文書,版次 2026.11.3。

開始 Labs

本書仍可免費閱讀。

查看價格

引用本節

格式

各種格式皆引用英文原書,本譯本即依循該原書。

每種格式都會標示本版。其連結會開啟目前版次,節標題會說明該節內文最後一次變動的時間。存取日期與擷取日期即為你開啟此頁的當日。

本頁內容

第 2 章,共 12 章: 繪製助理的威脅模型

  1. 資產與信任
  2. 資料流
  3. 三項致命要素與「二規則」(Rule of Two)
  4. 風險對照

返回頂端所有章節