Skip to content

fix(models): omit plaintext api keys from models.json - #84987

Closed
junn-dev wants to merge 4 commits into
openclaw:mainfrom
junn-dev:codex/protect-agent-api-keys-11829
Closed

junn-dev wants to merge 4 commits into
openclaw:mainfrom
junn-dev:codex/protect-agent-api-keys-11829

Conversation

@junn-dev

@junn-dev junn-dev commented May 21, 2026 •

Copy link
Copy Markdown

Fixes #11829.

This implements the Layer 1 hardening for models.json generation:

  • omit plaintext provider apiKey values before serializing agent-visible models.json
  • preserve non-secret auth markers such as known environment variable markers so marker-backed providers keep working
  • migrate legacy plaintext models.json keys into auth-profiles.json before redacting the generated file, so upgrades do not silently erase the only available credential
  • cover explicit providers, implicit providers, merge-mode existing providers, and legacy migration behavior

Real behavior proof:

  • ensureOpenClawModelsJson() was exercised through the existing models-config harness with a pre-existing models.json containing a plaintext provider key.
  • The regression verifies the regenerated models.json omits that plaintext key and the key is preserved in auth-profiles.json under custom-proxy:models-json.
  • The planner regression verifies plaintext keys from explicit, implicit, and existing merge-mode providers are absent from serialized output while OPENAI_API_KEY remains as a non-secret marker.

Validation:

  • corepack pnpm exec vitest run --reporter=dot src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.skips-writing-models-json-no-env-token.test.ts -> 4 files passed, 26 tests passed
  • corepack pnpm exec oxlint src/agents/models-config.ts src/agents/models-config.plan.ts src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.skips-writing-models-json-no-env-token.test.ts
  • git diff --check

TaskBounty: https://www.task-bounty.com/task/fix-security-roadmap-protecting-api-keys-from-agen-uej5sq

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 5:55 AM ET / 09:55 UTC.

Summary
The PR redacts plaintext provider apiKey values from generated models.json, migrates legacy plaintext keys into auth profiles, and adds planner/writer regression coverage.

PR surface: Source +104, Tests +112. Total +216 across 4 files.

Reproducibility: yes. source-level: a models.json-only provider with a plaintext apiKey can be migrated, then PR-head planning can return skip and leave the original plaintext file unchanged. I did not run a live repro because this review is read-only.

Review metrics: 2 noteworthy metrics.

  • Credential migration paths: 1 added. The PR adds a plaintext models.json to auth-profile migration path, so upgrade behavior must be correct before merge.
  • Generated catalog outputs: 2 current-main output classes. Current main writes root models.json plus plugin-owned catalog sidecars, so redaction proof must cover both.

Stored data model
Persistent data-model change detected: serialized state: src/agents/models-config.skips-writing-models-json-no-env-token.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #11829
Summary: This PR is one candidate fix for the Layer 1 models.json apiKey exposure tracked by the open security roadmap issue; overlapping candidate PRs exist, but no merged canonical replacement was found.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted real setup proof showing generated models.json/catalog output after the fix and preserved provider auth.
  • Force a sanitized rewrite after migrating existing plaintext models.json keys.
  • Rebase onto current main and cover SQLite auth profiles plus root and plugin generated catalog outputs.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body describes harness/regression tests, but it does not include redacted terminal output, generated-file contents, logs, or another real after-fix OpenClaw setup proof; the contributor should add proof with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] A supported models.json-only provider can still retain its original plaintext apiKey because migration can run and the planner can return skip before writing sanitized contents.
  • [P1] The branch predates current main's root-plus-plugin generated catalog outputs, so a rebase must prove both classes omit plaintext credentials.
  • [P1] The branch's migration proof targets auth-profiles.json while current main persists auth profiles in openclaw-agent.sqlite.
  • [P1] The contributor proof is harness/regression-test evidence only, not redacted real setup output showing generated files after the fix and preserved runtime auth.

Maintainer options:

  1. Rebase And Repair Current-Main Coverage (recommended)
    Update the branch onto current main, force a sanitized rewrite after migration, and prove SQLite auth profiles plus root and plugin catalog outputs before merge.
  2. Fold The Useful Tests Into A Canonical Layer 1 Branch
    If maintainers choose a different overlapping PR, carry this branch's migration and redaction cases into that canonical implementation.
  3. Pause Until Canonical Security Direction Is Chosen
    Keep this PR as source material while maintainers choose which overlapping Layer 1 branch should own the final migration behavior.

Next step before merge

  • [P1] Human maintainer review is needed to choose the canonical Layer 1 security branch and require contributor real behavior proof before merge.

Security
Needs attention: The patch targets a real secret exposure, but it can still leave plaintext credentials in a supported generated-file path and its migration proof is stale against current auth storage.

Review findings

  • [P1] Force a sanitized rewrite after migration — src/agents/models-config.ts:289-292
  • [P2] Rebase migration proof onto SQLite auth profiles — src/agents/models-config.skips-writing-models-json-no-env-token.test.ts:238-246
Review details

Best possible solution:

Land one rebased Layer 1 implementation that sanitizes root and plugin-owned generated catalogs, migrates legacy plaintext credentials into current SQLite auth profiles, forces sanitized rewrites, and includes redacted real setup proof.

Do we have a high-confidence way to reproduce the issue?

Yes, source-level: a models.json-only provider with a plaintext apiKey can be migrated, then PR-head planning can return skip and leave the original plaintext file unchanged. I did not run a live repro because this review is read-only.

Is this the best way to solve the issue?

No, not as submitted; generated-catalog redaction is the right boundary, but the branch must force sanitized rewrites after migration and be rebuilt on current SQLite auth-profile plus plugin catalog behavior.

Full review comments:

  • [P1] Force a sanitized rewrite after migration — src/agents/models-config.ts:289-292
    The migration copies plaintext apiKey values out of an existing models.json, but the planner can still return skip when that existing file is the only provider source. In that case the original plaintext models.json remains on disk, so the migration path needs to force a redacted rewrite or otherwise sanitize existing-only providers.
    Confidence: 0.9
  • [P2] Rebase migration proof onto SQLite auth profiles — src/agents/models-config.skips-writing-models-json-no-env-token.test.ts:238-246
    This test asserts that migration writes auth-profiles.json, but current main stores auth profiles in openclaw-agent.sqlite. A current-main fix needs SQLite-backed migration/proof rather than validating the retired JSON store path.
    Confidence: 0.84

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cf2efbe5d515.

Label changes

Label justifications:

  • P1: The PR addresses a real credential exposure path and still has a blocker that can leave plaintext secrets agent-visible.
  • merge-risk: 🚨 compatibility: The patch changes upgrade behavior for existing models.json apiKey data and must preserve working provider auth while removing plaintext output.
  • merge-risk: 🚨 auth-provider: The patch changes provider credential migration and generated catalog auth fields used by runtime provider selection.
  • merge-risk: 🚨 security-boundary: The patch is meant to remove agent-visible secrets but currently has a path that can leave plaintext credentials in place.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body describes harness/regression tests, but it does not include redacted terminal output, generated-file contents, logs, or another real after-fix OpenClaw setup proof; the contributor should add proof with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +104, Tests +112. Total +216 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 105 1 +104
Tests 2 112 0 +112
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 217 1 +216

Security concerns:

  • [high] Plaintext models.json can survive migration — src/agents/models-config.ts:289
    A models.json-only provider can have its apiKey migrated and then remain unchanged when planning returns skip, leaving the original plaintext credential in the agent-visible file.
    Confidence: 0.9
  • [medium] Auth-profile proof targets legacy JSON storage — src/agents/models-config.skips-writing-models-json-no-env-token.test.ts:238
    The branch's migration proof checks auth-profiles.json while current main stores auth profiles in openclaw-agent.sqlite, so upgrade safety is not established for the current storage model.
    Confidence: 0.84

What I checked:

  • Repository policy applied: Root AGENTS.md and src/agents/AGENTS.md were read fully; the PR touches auth/provider storage and generated model catalogs, so OpenClaw policy requires security, compatibility, current-main, and upgrade-safety review beyond the diff. (AGENTS.md:20, cf2efbe5d515)
  • PR migration runs before planning: On the PR head, existing plaintext models.json keys are migrated before the planner decides whether to rewrite models.json, but the original existingRaw and existingParsed are still passed into planning. (src/agents/models-config.ts:289, 6f9e8e46a536)
  • PR planner can skip before redaction: On the PR head, when no providers resolve, the planner returns skip before the new redaction helper can produce sanitized contents for an existing models.json-only provider. (src/agents/models-config.plan.ts:168, 6f9e8e46a536)
  • Current main has plugin catalog sidecars: Current main splits generated providers into root models.json and plugin-owned catalog writes, so a current fix must prove both output classes are sanitized. (src/agents/models-config.plan.ts:283, cf2efbe5d515)
  • Current main auth profiles are SQLite-backed: Current main updateAuthProfileStoreWithLock writes through the auth-profile SQLite transaction path, and the auth profile database path resolves to openclaw-agent.sqlite, while the PR test asserts auth-profiles.json. (src/agents/auth-profiles/store.ts:743, cf2efbe5d515)
  • models.json custom providers are supported: Docs support adding custom providers through models.providers or per-agent models.json, and document merge precedence for existing agent apiKey values, so the upgrade path is real product behavior. Public docs: docs/gateway/config-tools.md. (docs/gateway/config-tools.md:480, cf2efbe5d515)

Likely related people:

  • joshavant: Auth/model history shows PRs for SecretRef-safe models.json persistence and source-managed marker enforcement on the same generated catalog behavior. (role: SecretRef persistence contributor; confidence: high; commits: 8e20dd22d890, 0bcb95e8fa5e; files: src/agents/models-config.ts, src/agents/models-config.runtime-source-snapshot.test.ts, docs/concepts/models.md)
  • steipete: History shows Peter Steinberger authored the models-config planner extraction that still owns the planner seam this PR modifies. (role: models-config planning contributor; confidence: medium; commits: 53f6d962c25f; files: src/agents/models-config.plan.ts, src/agents/models-config.applies-config-env-vars.test.ts)
  • momothemage: The latest blame/current-main history for the touched auth-profile and model catalog files points through a recent merged PR that touched models-config, auth-profile SQLite, and plugin catalog files. (role: recent area contributor; confidence: medium; commits: 59df350f3c18; files: src/agents/models-config.ts, src/agents/models-config.plan.ts, src/agents/auth-profiles/store.ts)
  • Vincent Koc: Recent release-stabilization history touched the same models-config and auth-profile storage files, making this a plausible routing candidate for current-main rebase concerns. (role: recent adjacent contributor; confidence: low; commits: e085fa1a3ffd; files: src/agents/models-config.ts, src/agents/models-config.plan.ts, src/agents/auth-profiles/store.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@junn-dev

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@junn-dev

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 21, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 15, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for tackling both redaction and upgrade safety. We’re consolidating #11829 in maintainer-owned #87166. Since this branch was written, auth profiles moved from auth-profiles.json to the per-agent SQLite store, generated catalogs split into root and plugin-owned outputs, and migrations are no longer owned by the steady-state writer. The branch is also conflicting and can still skip the sanitized rewrite after migration. Closing this parallel implementation as superseded; the security issue and canonical PR remain open.

@steipete steipete closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security Roadmap: Protecting API Keys from Agent Access

2 participants