我们论文的代码、路由器缓存和运行日志:
ROPE:针对间接提示注入的路由来源策略执行 作者:Xinhang Ma、Chaowei Xiao、William Yeoh、Ning Zhang、Yevgeniy Vorobeychik
ROPE 仅允许某个值在来自用户、用户指定的来源或用户自己的记录时,才能到达会改变状态的工具。 执行过程是对一组经过审计的敏感工具参数进行确定性的来源检查;路由器 LLM 只读取可信的用户请求,并设定每个参数的检查严格程度。
| 路径 | 内容 |
|---|---|
src/rope/ | 防御实现:路由器、按任务划分的作用域、策略编译器、来源标注器、运行时防护。 |
src/rope/scopes/_floor/<suite>.json | 每个套件经过审计的敏感参数表(所有路由器共享)。 |
src/rope/scopes/<router>/<suite>.json | 路由器缓存:四个被评估路由器的按任务作用域(opus 覆盖全部六个套件;gemini-3-flash、gpt-oss-20b、gpt-4o-mini 覆盖 AgentDyn 套件)。 |
src/common/ | 路由器的 LLM 补全缓存。 |
autodojo/ | 基准测试框架,包含六个被评估的套件(来自 AgentDojo 的 banking、slack、travel;来自 AgentDyn 的 github、shopping、dailylife)以及自适应(AutoDojo)攻击。 |
agentlab/ | 长时程基准测试:AgentLAB Task-Injection 轨迹和回放驱动程序(agentlab/README.md)。 |
logs/ | 论文数据背后的每一次 ROPE 运行记录。 |
analysis/aggregate.py | 从 logs/ 重新计算论文中的每一个 ROPE 数值。 |
Python 3.12,需安装 openai、pydantic、jsonschema、pyyaml、docstring-parser(以及用于原生 Gemini 路径的 google-genai)。在仓库根目录下执行:
export PYTHONPATH=$PWD/autodojo/src:$PWD/src
python analysis/aggregate.py logs # every model
python analysis/aggregate.py logs gpt-4o-mini # one model
它按智能体模型打印:每个套件的干净效用(CU)、攻击下的效用(UA)和攻击成功率(ASR),以及作为未加权套件均值的对应值,覆盖每种配置;静态攻击与自适应攻击;长时程攻击;按类别划分的结果;以及每一次残余的攻击成功。
三个基准 oracle 将一次被阻止的攻击判定为成功;analysis/corrections.py 根据其效果对这三个注入任务重新评分(slack IT5、dailylife IT7、github IT1)。CU 和 UA 从不被改动。
logs/<benchmark>/<model>/<config>/<suite>/user_task_<i>/<attack>/<case>.json
| 级别 | 取值 |
|---|---|
<benchmark> | agentdyn、agentdojo |
<model> | gpt-4o-mini、gpt-4o(仅 AgentDyn)、gemini-2.5-flash、qwen3-235b |
<config> | rope(防御,Opus 4.8 路由器);AgentDyn 上的 GPT-4o-mini 还支持:rope-clamp、rope-defaults-only、rope-always-fully-specified、rope-always-action-open(策略消融)、rope-router-<router>[-clamp](更廉价的路由器) |
<attack> | clean(无攻击,none.json)、static(important_instructions)、adaptive(AutoDojo)、long_horizon(AgentLAB Task-Injection,AgentDojo 套件) |
<case> | none.json(干净)或 injection_task_<k>.json |
每个 JSON 都是一份 AgentDojo 运行日志:完整的消息轨迹、注入内容,以及 utility 和 security 判定结果(security: true 表示攻击成功)。
# the defense (cached Opus router):
python -m rope.run_eval --suite github --attack important_instructions
python -m rope.run_eval --suite github --attack none # clean utility
python -m rope.run_eval --suite github --defense passthrough # no defense
# a cheaper router, optionally clamped to the audited floor; a fixed-policy ablation arm:
python -m rope.run_eval --suite github --router gemini-3-flash --clamp
python -m rope.run_eval --suite github --policy-mode defaults-only
# a live router (any OpenAI-compatible model):
python -m rope.run_eval --suite github --router live --router-model openai/gpt-4o-mini
# adaptive attack: replay the AutoDojo-optimized injections
AUTODOJO_CACHE=$PWD/autodojo/variant_generation/variants/github/openai/gpt-4o-mini/routed/injections.json \
python -m rope.run_eval --suite github --attack autodojo
# long-horizon attack: replay the AgentLAB traces
python agentlab/run_eval.py --suite banking --user-task user_task_0 --injection-task injection_task_0
环境变量:OPENROUTER_API_KEY(agent 模型和实时路由器)、ROPE_AGENT_MODEL(默认 openai/gpt-4o-mini)、ROPE_PIPELINE_TAG(运行名称前缀;它必须包含一个 AgentDojo 模型名称,默认 gpt-4o-mini-2024-07-18)。
要缓存你自己的路由器并像内置路由器一样使用它:
python -m rope.cache_router --router my-router --router-model <llm-id> --suite github
python -m rope.run_eval --router my-router --suite github --attack important_instructions
本仓库基于 AgentDojo 和 AgentDyn(基准测试套件)、AutoDojo(自适应攻击)以及 AgentLAB(长时程攻击轨迹)构建。
@article{ma2026rope,
title={ROPE: Routed origin policy enforcement against indirect prompt injection},
author={Ma, Xinhang and Xiao, Chaowei and Yeoh, William and Zhang, Ning and Vorobeychik, Yevgeniy},
journal={arXiv preprint arXiv:2608.27496},
year={2026}
}