oeisthename/promptwall
GitHub: oeisthename/promptwall
PromptWall 是一款面向 AI Agent 的开源运行时安全中间件,通过输入防火墙、策略引擎和哈希链审计日志来防御 prompt injection 并管控工具调用行为。
Stars: 0 | Forks: 0
# PromptWall
**面向 AI agent 的开源运行时安全中间件。**
PromptWall 位于您的 AI agent 和它们使用的工具之间。它会检查 agent 读取的所有内容以发现隐藏的 prompt injection 尝试,在 agent 尝试执行的每一个动作运行前对其进行策略强制检查,并将每一个决策写入防篡改、哈希链式的审计日志中。
## 为什么需要
AI agent 现在正使用真实的凭据执行真实的操作——写入文件、调用 API、移动数据——但它们却没有类似的运行时访问控制层。Prompt injection(隐藏在 agent 读取内容中的恶意指令)是 agentic AI 中最紧迫且未解决的漏洞类别,而且目前没有任何开源工具能在运行时对 agent 的行为进行策略强制检查。PromptWall 正是为了填补这一空白而生。
## 工作原理
```
AI Agent (LangChain / CrewAI / raw MCP client)
│ all tool calls pass through
▼
┌─────────────────────────────────────────────┐
│ PROMPTWALL CORE │
│ ┌───────────┐ ┌──────────┐ ┌───────────┐ │
│ │ Input │─▶│ Policy │─▶│ Audit │ │
│ │ Firewall │ │ Engine │ │ Ledger │ │
│ └───────────┘ └──────────┘ └───────────┘ │
└─────────────────────────────────────────────┘
│ enforced / blocked
▼
MCP Servers / External Tools
Dashboard (Next.js) — live alerts,
policy editor, audit log viewer
```
- **Input Firewall** —— 在外部内容(工具输出、抓取的页面)到达模型之前,扫描其中是否存在 prompt injection。
- **Policy Engine** —— 在执行前,根据 YAML 定义规则(允许的域名、允许的路径、禁止的输出模式)检查每一个出站工具调用。
- **Audit Ledger** —— 仅追加、SHA-256 哈希链式的决策日志。任何对过去条目的篡改都会破坏链条,从而被检测到。
完整的架构说明:见 [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md)。
## 快速开始
```
git clone https://github.com/oeisthename/promptwall.git
cd promptwall
docker compose up
```
这将启动 API server、审计数据库以及位于 `http://localhost:3000` 的 dashboard。
### 在您自己的 agent 中安装中间件
```
uv add promptwall
```
```
from promptwall import PromptWall
guard = PromptWall(policy_file="policies/example-agent.yaml")
# 包装你现有的 tool-calling 逻辑
result = guard.enforce(tool_call)
```
完整的 LangChain 和 CrewAI 集成示例请见 [`examples/`](examples)。
## 编写策略
策略是纯 YAML 文件,旨在像代码一样进行审查和版本控制:
```
agent: research-agent
rules:
- name: no-outbound-to-unknown-hosts
plane: output
match: tool_call.url not in allowlist
action: block
severity: critical
- name: no-secret-shaped-strings
plane: output
match: output contains pattern:SECRET_PATTERN
action: redact
severity: high
```
完整示例请见 [`policies/example-agent.yaml`](policies/example-agent.yaml),完整的规则语法请见 [`docs/POLICY_REFERENCE.md`](docs/POLICY_REFERENCE.md)。
## 项目结构
```
promptwall/
├── src/promptwall/ # Core Python package
│ ├── firewall/ # Input scanning (injection detection)
│ ├── policy/ # YAML policy loading + enforcement
│ ├── ledger/ # Hash-chained audit log
│ ├── api/ # FastAPI server (REST + WebSocket)
│ └── observability/ # OpenTelemetry + structlog setup
├── dashboard/ # Next.js web dashboard
├── policies/ # Example policy files
├── examples/ # LangChain, CrewAI, raw MCP integration examples
├── tests/ # unit / integration / property-based tests
├── docs/ # Architecture, policy reference, threat model
└── docker-compose.yml
```
## 开发
```
uv sync --extra dev
uv run pytest
uv run ruff check .
uv run mypy src/
```
完整的贡献流程请见 [`CONTRIBUTING.md`](CONTRIBUTING.md)。
## 技术栈
Python 3.12 · Anthropic MCP SDK · Pydantic v2 · FastAPI · SQLite/PostgreSQL · OpenTelemetry · Next.js 16 · React 19 · TypeScript · Tailwind v4 · shadcn/ui
## 安全
找到了绕过 firewall 或 policy engine 的方法?请**不要**公开提交 issue。负责任的披露说明请见 [`SECURITY.md`](SECURITY.md)。
## 许可证
[MIT](LICENSE)
标签:AI代理, Web报告查看器, 中间件, 人工智能安全, 合规性, 审计日志, 测试用例, 用户代理, 策略引擎, 网络安全挑战, 请求拦截, 逆向工具, 配置错误