Lab-confirmed:本文 reference 實作來自我(Maki)自家在跑的個人 PKI(mk-brain / ERIKA Bot / Inbox Bot 等),不是 enterprise production case study。Code snippet 為 reference 設計,非實際在跑的版本。
模型以外的周邊,往往才是先出事的地方
很多 builder 一講 AI 安全,焦點會自然落在 prompt 和 output。
但真正把事故串起來的,常常是周邊工具鏈。
不是模型說了什麼。
而是 extension 暴露了什麼、localhost 綁到哪裡、tool API 憑什麼相信呼叫方、哪個 publish route 居然讓模型自己選。
這就是 attack surface boundary 麻煩的地方。
它不像 prompt injection 那樣有一個很清楚的惡意字串。
它比較像是一堆看起來各自不大、放在一起卻能湊成 exploit chain 的小洞。
VS Code AI 延伸套件的 source map 洩漏案例,提醒我們 AI 功能常常不是倒在模型本體。
而是倒在你原本以為「只是配套」的 metadata、前端資產、除錯資訊、代理服務。
台北捷運 AI 客服被玩成 code generator 的經典案例則更直接。
Localhost 沒鎖。
Tool API 沒 auth。
Prompt 沒 hardening。
三個小問題加起來,就是一條可以走完的 RCE chain。
對不專做資安的工程師來說,attack surface boundary 最有價值的地方在於它很具體。
你不用先成為紅隊。
你只要先把暴露面列清楚,再把每個入口的預設值改對。
很多時候,風險不是來自 AI 太強,而是你把太多本機或內部能力當成理所當然的內網信任。
Attack Surface Boundary:外面到底打得到哪裡
攻擊面邊界不是抽象概念,而是每一個 port、header、tool route 和預設綁定位置。
Case:
主:VS Code AI 延伸套件 source map 洩漏(150 萬安裝量,2026 Q1 揭露)——擴充套件被抓到把 source map 連同敏感資訊一起暴露,攻擊面從「LLM 本體」轉移到「LLM 周邊工具鏈」。OWASP MCP Top 10 的 MCP04(Software Supply Chain)正是針對此類風險。
次:台北捷運 AI 客服被玩成 code generator(prompt injection 經典案例,2024 至今仍被當警示)。Localhost 沒鎖、tool API 沒 auth、prompt 沒 hardening——三個小漏洞合起來變成完整 RCE chain。TrendMicro 2026 趨勢報告為此類事件定調:「最可怕的內鬼不是人,是你親手訓練的 AI Agent」。
核心問題:你給 model 多大 autonomy?最小 auth 該怎麼設?
Rule:所有本機 agent 服務預設 127.0.0.1 不 0.0.0.0。所有 LLM tool API 必須HMAC + replay window(OneUptime 2026-01 canonical pattern)。
先把可打到的面縮小,再談模型要不要更聰明,順序不能反。
| Threat | Mitigation | Validated in (reference) |
|---|---|---|
| Localhost binding 不小心 0.0.0.0 | 所有服務預設 127.0.0.1;LAN 暴露需明確宣告並過 nginx/Tailscale 限縮 | OpenClaw / memory-hall / mk-brain RAG |
| Tool API 被 prompt injection 騙呼叫 | HMAC sha256=<hex> + X-Timestamp + |now-ts| < 300s replay window;hmac.compare_digest constant-time | memory-hall API |
| Tool Misuse(ASI02)/ Command Injection(MCP05) | output 過 deterministic policy gate(allowlist route_to,禁 LLM 決定 publish target);critical action 走 second-agent approval | mk-brain agent council |
Reference 實作(示意非 production code,依你環境調整):
# HMAC + replay window — LLM tool API 最小 auth
import hmac
import hashlib
import time
REPLAY_WINDOW_SECONDS = 300
def verify_request(
body: bytes,
signature_header: str,
timestamp_header: str,
key: bytes,
) -> bool:
# 1. Replay window
ts = int(timestamp_header)
if abs(time.time() - ts) > REPLAY_WINDOW_SECONDS:
return False
# 2. Constant-time HMAC compare
expected = hmac.new(
key,
f"{ts}.{body.decode()}".encode(),
hashlib.sha256,
).hexdigest()
received = signature_header.replace("sha256=", "")
return hmac.compare_digest(expected, received)
對應 OWASP:這篇先看哪幾條
MCP05 Command Injection & Execution:當 tool route 能被模型或外部輸入帶偏,命令注入就從理論變成實作問題。MCP01 Token Mismanagement:簽章、短期 token、重放視窗這些最小認證機制,決定 tool API 到底是不是門。ASI02 Tool Misuse:很多事故不是模型不會答,而是它太容易被允許去碰錯的工具。
想動手做? 這篇文的概念有對應的 5 課完整課程: 攻擊面邊界 101 →
也可以回到系列起點:信任邊界