fix(secrets): avoid re-materializing plaintext apiKey in agent models.json#28393
fix(secrets): avoid re-materializing plaintext apiKey in agent models.json#28393kelvinCB wants to merge 3 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryProperly fixes the security issue where plaintext API keys could be persisted to Key Changes
Technical DetailsThe solution correctly uses a fallback chain: Note on Merge ModeWhen Confidence Score: 4/5
Last reviewed commit: 3c7a7ec |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c7a7eca9f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/agents/models-config.ts
Outdated
| // with plaintext apiKey values. Prefer the source snapshot (with SecretRef inputs) | ||
| // when available so models.json does not persist resolved secrets to disk. | ||
| const sourceCfg = getRuntimeConfigSourceSnapshot(); | ||
| const explicitProviders = (sourceCfg?.models?.providers ?? cfg.models?.providers ?? {}) as Record< |
There was a problem hiding this comment.
Respect passed config when selecting explicit model providers
When a runtime snapshot is active, this now always prefers getRuntimeConfigSourceSnapshot() over the config argument, so callers that pass an explicit config object can no longer control models.providers. In gateway flows where ensureOpenClawModelsJson() is called with request-specific config (for example, code paths that pass params.cfg/effectiveCfg), provider additions or overrides in that config are silently ignored and models.json is generated from the global source snapshot instead, which can lead to missing/incorrect registry entries for that run.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49cdf83073
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const sourceCfg = getRuntimeConfigSourceSnapshot(); | ||
| const explicitProviders = sourceCfg?.models?.providers ?? cfg.models?.providers ?? {}; |
There was a problem hiding this comment.
Respect passed config before source snapshot providers
ensureOpenClawModelsJson() now always reads explicitProviders from getRuntimeConfigSourceSnapshot() when a runtime snapshot exists, even when a caller explicitly passes a config argument; this changes precedence and can silently drop per-call provider overrides/additions, producing incorrect models.json contents and model resolution failures in runtime-secret sessions. Fresh evidence: this function is called with caller-supplied configs in production paths such as runImagePrompt (src/agents/tools/image-tool.ts), describeImageWithModel (src/media-understanding/providers/image.ts), and runEmbeddedPiAgent (src/agents/pi-embedded-runner/run.ts).
Useful? React with 👍 / 👎.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Thanks for the work on this PR and for contributing to this fix path. Closing this as superseded by #38955 (merged), which integrated the relevant fixes from this thread and completed the broader hardening scope for the secrets/models persistence cluster. The merged work now covers source-snapshot persistence, marker/provenance auth handling, audit/apply expansion (including models.json/header residues), and write-mode hardening/tests/docs in one end-to-end fix. Appreciate the contribution here. If there’s a remaining unique change from this PR that should still land, please call it out in a follow-up issue and reference #38955. |
Summary
Fixes #28359.
When runtime secrets are active,
loadConfig()may return a resolved runtime snapshot with plaintext provider keys.ensureOpenClawModelsJson()used that snapshot directly, which could persist plaintext API keys into~/.openclaw/agents/*/agent/models.json.What changed
getRuntimeConfigSourceSnapshot()export from config IO.ensureOpenClawModelsJson()to prefer the runtime source snapshot (pre-resolution config) when choosing explicit model providers.apiKeySecretRefmodels.jsonkeeps the SecretRef and does not persist plaintext.Why this is safe
Validation
pnpm test src/agents/models-config.skips-writing-models-json-no-env-token.test.ts