Files
agent-skills/devops/gitea-code-sync/references/redaction-patterns.md
Hermes Agent ccc63d1e70 first commit
2026-05-10 13:52:46 +08:00

63 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 敏感信息脱敏模式参考
## 常见密钥格式
| 格式 | 示例 | 匹配正则 |
|------|------|----------|
| MiniMax token | `tp-spf...2tid` | `tp-[a-zA-Z0-9]{20,}` |
| MiniMax API key | `sk-cp-...faRA` | `sk-cp-[a-zA-Z0-9]+` |
| QQ client secret | `bq6New...vQvR` | `bq6New[A-Za-z0-9]+` |
| WeChat openid | `o9cq801H7rXH9zNHTu-xaa29Hbuk@im.wechat` | `o9cq[a-zA-Z0-9@.-]+` |
| WeChat token | `2fc2d0...8d1b` | `2fc2d0[A-Za-z0-9]+` |
| Generic hex (30+) | various | `[a-f0-9]{30,}` |
## .env 脱敏易错点
注释行中的示例也可能匹配(如 `# KIMI_BASE_URL=https://api.kimi.com/coding/v1` 包含 `api.kimi.com` 不是密钥,但 `# OPENROUTER_API_KEY=sk-or-...` 包含完整格式密钥)。
```bash
# 验证 .env 非注释行无泄露
grep -v "^#" .env | grep -E "tp-[a-zA-Z0-9]{20,}|sk-[a-zA-Z0-9]{20,}|bq6New[A-Za-z0-9]+|[a-f0-9]{30,}|o9cq" && echo "有泄露" || echo "干净"
```
## auth.json 脱敏易错点
直接用 regex 替换会漏掉嵌套结构,且容易弄坏 JSON 格式(如尾部多出 `"`)。必须用 Python `json` 模块:
```python
import json
with open('auth.json', 'r') as f:
auth = json.load(f)
for provider, creds in auth['credential_pool'].items():
for c in creds:
c['access_token'] = '***'
with open('auth.json', 'w') as f:
json.dump(auth, f, indent=2, ensure_ascii=False)
# 验证是合法 JSON
with open('auth.json', 'r') as f:
json.load(f) # 能解析则格式正确
```
## 必须覆盖的敏感字段清单
### .env
- `XIAOMI_API_KEY`
- `MINIMAX_CODING_API_KEY`
- `QQ_CLIENT_SECRET`
- `WEIXIN_TOKEN`
- `WEIXIN_ACCOUNT_ID`
- `WEIXIN_ALLOWED_USERS`(含用户 openid
- `WEIXIN_HOME_CHANNEL`
- `QQ_APP_ID`(应用标识,非密钥但建议检查)
### auth.json
- `credential_pool.{provider}[].access_token`
### 其他可能遗漏的渠道配置
- 微信 `channel_directory.json` 中的用户 ID
- `gateway_state.json` 中的进程信息(一般不敏感)