arc-shield
Output sanitization for agent responses. Scans ALL outbound messages for leaked secrets, tokens, keys, passwords, and PII before they leave the agent.
⚠️ This is NOT an input scanner — clawdefender already handles that. This is an OUTPUT filter for catching things your agent accidentally includes in its own responses.
Why You Need This
Agents have access to sensitive data: 1Password vaults, environment variables, config files, wallet keys. Sometimes they accidentally include these in responses when:
- - Debugging and showing full command output
- Copying file contents that contain secrets
- Generating code examples with real credentials
- Summarizing logs that include tokens
Arc-shield catches these leaks before they reach Discord, Signal, X, or any external channel.
What It Detects
🔴 CRITICAL (blocks in --strict mode)
- - API Keys & Tokens: 1Password (
ops_*), GitHub (ghp_*), OpenAI (sk-*), Stripe, AWS, Bearer tokens - Passwords: Assignments like
password=... or INLINECODE6 - Private Keys: Ethereum (0x + 64 hex), SSH keys, PGP blocks
- Wallet Mnemonics: 12/24 word recovery phrases
- PII: Social Security Numbers, credit card numbers
- Platform Tokens: Slack, Telegram, Discord
🟠 HIGH (warns loudly)
- - High-entropy strings: Shannon entropy > 4.5 for strings > 16 chars (catches novel secret patterns)
- Credit cards: 16-digit card numbers
- Base64 credentials: Long base64 strings that look like tokens
🟡 WARN (informational)
- - Secret file paths:
~/.secrets/*, paths containing "password", "token", "key" - Environment variables:
ENV_VAR=secret_value exports - Database URLs: Connection strings with credentials
Installation
CODEBLOCK0
Or download as a skill bundle.
Usage
Command-line
CODEBLOCK1
Integration with OpenClaw Agents
Pre-send hook (recommended)
Add to your messaging skill or wrapper:
CODEBLOCK2
Manual pipe
Before any external message:
CODEBLOCK3
Testing
CODEBLOCK4
Includes test cases for:
- - Real leaked patterns (1Password tokens, Instagram passwords, wallet mnemonics)
- False positive prevention (normal URLs, email addresses, file paths)
- Redaction accuracy
- Strict mode blocking
Configuration
Patterns are defined in config/patterns.conf:
CODEBLOCK5
Edit to add custom patterns or adjust severity levels.
Modes
| Mode | Behavior | Exit Code | Use Case |
|---|
| Default | Pass through + warnings to stderr | 0 | Development, logging |
| INLINECODE10 |
Block on CRITICAL findings | 1 if critical | Production outbound messages |
|
--redact | Replace secrets with
[REDACTED:TYPE] | 0 | Safe logging, auditing |
|
--report | Analysis only, no pass-through | 0 | Auditing conversations |
Entropy Detection
The Python version (output-guard.py) includes Shannon entropy analysis to catch secrets that don't match regex patterns:
CODEBLOCK6
Threshold: 4.5 bits (configurable with --entropy-threshold)
Performance
- - Bash version: ~10ms for typical message (< 1KB)
- Python version: ~50ms with entropy analysis
- Zero external dependencies: bash + Python stdlib only
Fast enough to run on every outbound message without noticeable delay.
Real-World Catches
From our own agent sessions:
CODEBLOCK7
All blocked by arc-shield before reaching external channels.
Best Practices
- 1. Always use
--strict for external messages (Discord, Signal, X, email) - Use
--redact for logs you want to review later - Run tests after adding custom patterns to check for false positives
- Pipe through both bash and Python versions for maximum coverage:
message | arc-shield.sh --strict | output-guard.py --strict
- 5. Don't rely on this alone — educate your agent to avoid including secrets in the first place (see AGENTS.md output sanitization directive)
Limitations
- - Context-free: Can't distinguish between "here's my password: X" (bad) and "set your password to X" (instruction)
- No semantic understanding: Won't catch "my token is in the previous message"
- Pattern-based: New secret formats require pattern updates
Use in combination with agent instructions and careful prompt engineering.
Integration Example
Full OpenClaw agent integration:
CODEBLOCK9
Troubleshooting
False positives on normal text:
- - Adjust entropy threshold: INLINECODE18
- Edit
config/patterns.conf to refine regex patterns - Add exceptions to the pattern file
Secrets not detected:
- - Check pattern file for coverage
- Run with
--report to see what's being scanned - Test with
tests/run-tests.sh using your sample - Consider lowering entropy threshold (but watch for false positives)
Performance issues:
- - Use bash version only (skip entropy detection)
- Limit input size with INLINECODE22
- Run in background: INLINECODE23
Contributing
Add new patterns to config/patterns.conf following the format:
CODEBLOCK10
Test with tests/run-tests.sh before deploying.
License
MIT — use freely, protect your secrets.
Remember: Arc-shield is your safety net, not your strategy. Train your agent to never include secrets in responses. This tool catches mistakes, not malice.
arc-shield
智能体响应的输出净化工具。 在智能体所有外发消息离开前,扫描其中泄露的密钥、令牌、密码和PII(个人身份信息)。
⚠️ 这不是输入扫描器——clawdefender 已负责输入扫描。这是一个输出过滤器,用于捕捉智能体在自身响应中意外包含的内容。
为何需要此工具
智能体可访问敏感数据:1Password 密码库、环境变量、配置文件、钱包密钥。有时它们会在以下情况意外包含这些数据:
- - 调试并显示完整命令输出时
- 复制包含密钥的文件内容时
- 生成包含真实凭据的代码示例时
- 汇总包含令牌的日志时
Arc-shield 能在这些泄露到达 Discord、Signal、X 或任何外部渠道之前将其拦截。
检测内容
🔴 严重(--strict 模式下阻止)
- - API 密钥和令牌:1Password (ops)、GitHub (ghp)、OpenAI (sk-*)、Stripe、AWS、Bearer 令牌
- 密码:如 password=... 或 passwd: ... 的赋值
- 私钥:以太坊(0x + 64位十六进制)、SSH 密钥、PGP 块
- 钱包助记词:12/24 个单词的恢复短语
- PII:社会安全号码、信用卡号
- 平台令牌:Slack、Telegram、Discord
🟠 高(强烈警告)
- - 高熵字符串:长度超过 16 个字符且香农熵 > 4.5(捕捉新型密钥模式)
- 信用卡:16 位卡号
- Base64 凭据:类似令牌的长 base64 字符串
🟡 警告(信息性)
- - 密钥文件路径:~/.secrets/*、包含 password、token、key 的路径
- 环境变量:ENVVAR=secretvalue 导出
- 数据库 URL:包含凭据的连接字符串
安装
bash
cd ~/.openclaw/workspace/skills
git clone arc-shield
chmod +x arc-shield/scripts/.sh arc-shield/scripts/.py
或作为技能包下载。
使用方法
命令行
bash
发送前扫描智能体输出
agent-response.txt | arc-shield.sh
若发现严重密钥则阻止(用于外部消息前)
echo 消息文本 | arc-shield.sh --strict || echo 已阻止
编辑密钥并返回净化文本
cat response.txt | arc-shield.sh --redact
完整报告
arc-shield.sh --report < conversation.log
带熵检测的 Python 版本
cat message.txt | output-guard.py --strict
与 OpenClaw 智能体集成
发送前钩子(推荐)
添加到消息技能或包装器中:
bash
#!/bin/bash
send-message.sh 包装器
MESSAGE=$1
CHANNEL=$2
净化输出
SANITIZED=$(echo $MESSAGE | arc-shield.sh --strict --redact)
EXIT_CODE=$?
if [[ $EXIT_CODE -eq 1 ]]; then
echo 错误:消息包含严重密钥,已被阻止。 >&2
exit 1
fi
发送净化后的消息
openclaw message send --channel $CHANNEL $SANITIZED
手动管道
在任何外部消息前:
bash
生成响应
RESPONSE=$(agent-generate-response)
净化
CLEAN=$(echo $RESPONSE | arc-shield.sh --redact)
发送
signal send $CLEAN
测试
bash
cd skills/arc-shield/tests
./run-tests.sh
包含以下测试用例:
- - 真实泄露模式(1Password 令牌、Instagram 密码、钱包助记词)
- 误报预防(正常 URL、电子邮件地址、文件路径)
- 编辑准确性
- 严格模式阻止
配置
模式定义在 config/patterns.conf 中:
conf
CRITICAL|GitHub PAT|ghp_[a-zA-Z0-9]{36,}
CRITICAL|OpenAI Key|sk-[a-zA-Z0-9]{20,}
WARN|Secret Path|~\/\.secrets\/[^\s]*
编辑以添加自定义模式或调整严重级别。
模式
| 模式 | 行为 | 退出码 | 使用场景 |
|---|
| 默认 | 通过 + 警告到 stderr | 0 | 开发、日志记录 |
| --strict |
发现严重项时阻止 | 1(若严重) | 生产环境外发消息 |
| --redact | 用 [已编辑:类型] 替换密钥 | 0 | 安全日志记录、审计 |
| --report | 仅分析,不通过 | 0 | 审计对话 |
熵检测
Python 版本(output-guard.py)包含香农熵分析,用于捕捉不匹配正则模式的密钥:
python
检测高熵字符串,如:
kJ8nM2pQ5rT9vWxY3zA6bC4dE7fG1hI0 # 新型 API 密钥格式
Zm9vOmJhcg== # Base64 凭据
阈值:4.5 比特(可通过 --entropy-threshold 配置)
性能
- - Bash 版本:典型消息(< 1KB)约 10 毫秒
- Python 版本:带熵分析约 50 毫秒
- 零外部依赖:仅需 bash + Python 标准库
速度足够快,可在每条外发消息上运行而不会产生明显延迟。
真实案例
来自我们自己的智能体会话:
bash
1Password 令牌
ops_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
调试输出中的 Instagram 密码
instagram login: user@example.com / MyInsT@Gr4mP4ss!
文件列表中的钱包助记词
cat ~/.secrets/wallet-recovery-phrase.txt
abandon ability able about above absent absorb abstract...
git 配置中的 GitHub PAT
[remote origin]
url = https://ghp_abc123:@github.com/user/repo
所有内容在到达外部渠道前均被 arc-shield 阻止。
最佳实践
- 1. 始终对外部消息使用 --strict(Discord、Signal、X、电子邮件)
- 对需要稍后审查的日志使用 --redact
- 添加自定义模式后运行测试以检查误报
- 同时通过 bash 和 Python 版本管道以获得最大覆盖率:
bash
message | arc-shield.sh --strict | output-guard.py --strict
- 5. 不要仅依赖此工具——训练智能体避免首先包含密钥(参见 AGENTS.md 输出净化指令)
局限性
- - 无上下文:无法区分这是我的密码:X(不良)和将你的密码设置为 X(指令)
- 无语义理解:不会捕捉我的令牌在上一条消息中
- 基于模式:新的密钥格式需要更新模式
请与智能体指令和精心设计的提示工程结合使用。
集成示例
完整的 OpenClaw 智能体集成:
bash
在智能体的消息包装器中
send
externalmessage() {
local message=$1
local channel=$2
# 飞行前净化
if ! echo $message | arc-shield.sh --strict > /dev/null 2>&1; then
echo 错误:消息被 arc-shield 阻止(包含密钥) >&2
return 1
fi
# 用熵检测双重检查
if ! echo $message | output-guard.py --strict > /dev/null 2>&1; then
echo 错误:检测到高熵密钥 >&2
return 1
fi
# 安全发送
openclaw message send --channel $channel $message
}
故障排除
正常文本的误报:
- - 调整熵阈值:output-guard.py --entropy-threshold 5.0
- 编辑 config/patterns.conf 以优化正则模式
- 向模式文件添加例外
密钥未被检测到:
- - 检查模式文件的覆盖率
- 使用 --report 运行以查看扫描内容
- 使用你的样本通过 tests/run-tests.sh 测试