避免 models.json 缓存泄露 API Key(PR #14836)
解决“`${ENV}` 在运行时被解开后写入缓存明文”的场景:在写入 models cache 前剥离 provider.apiKey。
GITHUBDiscovered 2026-02-13Author pahud
Prerequisites
- OpenClaw instance uses provider API keys (direct key or `${ENV}` indirection).
- You can inspect `~/.openclaw/agents/main/agent/models.json` on host.
Steps
- Backup current config and rotate any keys that may already have been exposed in cache/logs.
- Upgrade to PR #14836 build and restart gateway.
- Trigger model initialization once, then inspect generated models cache for `apiKey` fields.
- Confirm runtime requests still authenticate correctly through env/config resolution path.
- Add periodic secret-scan check on cache directory as defense-in-depth.
Commands
openclaw gateway statusopenclaw gateway restartgrep -R "apiKey" ~/.openclaw/agents/main/agent/models.jsonopenclaw models statusVerify
`models.json` no longer stores plaintext `apiKey`, while model calls continue to succeed.
Caveats
- If historical backups still contain plaintext keys, they remain a risk until rotated/deleted(需验证).
- Different agent/session cache paths may vary by deployment mode.
Source attribution
This tip is aggregated from community/public sources and preserved with attribution.
Open original source ↗