Skip to content

Stop writing plaintext provider keys to models.json - #84738

Closed
Finesssee wants to merge 1 commit into
openclaw:mainfrom
Finesssee:fix/models-json-api-key-redaction
Closed

Finesssee wants to merge 1 commit into
openclaw:mainfrom
Finesssee:fix/models-json-api-key-redaction

Conversation

@Finesssee

@Finesssee Finesssee commented May 21, 2026 •

Copy link
Copy Markdown

Summary

  • Stop preserving stale plaintext provider apiKey values from existing models.json during merge-mode regeneration.
  • Strip plaintext provider keys at the final models.json serialization boundary while preserving env, SecretRef, OAuth, AWS, and local non-secret markers.
  • Avoid projecting plaintext auth-profile keys into generated provider config; runtime auth can still resolve credentials through the auth profile store.

Fixes #11829.

Verification

  • pnpm install --frozen-lockfile
  • node scripts/run-vitest.mjs src/agents/models-config.merge.test.ts
  • node scripts/run-vitest.mjs src/agents/models-config.providers.normalize-keys.test.ts
  • node scripts/run-vitest.mjs src/agents/models-config.runtime-source-snapshot.test.ts
  • node scripts/run-vitest.mjs src/agents/models-config.applies-config-env-vars.test.ts
  • node scripts/run-vitest.mjs src/agents/models-config.skips-writing-models-json-no-env-token.test.ts
  • pnpm exec oxfmt --check src/agents/models-config.merge.ts src/agents/models-config.providers.secret-helpers.ts src/agents/models-config.plan.ts src/agents/models-config.merge.test.ts src/agents/models-config.providers.normalize-keys.test.ts src/agents/models-config.runtime-source-snapshot.test.ts
  • git diff --check
  • pnpm lint:core

Real behavior proof

Behavior addressed: generated models.json no longer writes raw provider API key strings where prompt-facing model config can expose them to agents.

Real environment tested: local macOS checkout with the repository lockfile installed via pnpm install --frozen-lockfile.

Exact steps or command run after this patch: I ran a live ensureOpenClawModelsJson invocation against a temporary agent directory that already contained a merge-mode models.json row with a stale plaintext value, then regenerated it with a runtime plaintext value and a SecretRef-managed provider.

Evidence after fix:

{
  "wrote": true,
  "openaiApiKeyPresent": false,
  "moonshotApiKey": "secretref-managed",
  "stalePlaintextPresent": false,
  "runtimePlaintextPresent": false,
  "openaiBaseUrl": "https://stale.example/v1",
  "providers": [
    "moonshot",
    "openai"
  ]
}

Observed result after fix: the generated file omitted the plaintext OpenAI provider key, removed the stale plaintext key from the previous models.json, preserved the non-secret SecretRef marker for Moonshot, and kept the merge-mode baseUrl behavior intact. All listed tests passed, formatting passed, git diff --check passed, and pnpm lint:core reported 0 warnings and 0 errors.

What was not tested: full end-to-end provider calls with real API credentials were not run; this patch only changes the generated models.json persistence boundary and keeps runtime credential resolution on existing env/profile/config paths.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed June 30, 2026, 10:29 PM ET / 02:29 UTC.

Summary
The branch removes plaintext provider apiKey persistence from generated models.json, drops preserved stale merge-mode keys, skips plaintext auth-profile projection, and adds focused model-config tests.

PR surface: Source -8, Tests +67. Total +59 across 6 files.

Reproducibility: yes. Source inspection shows current main serializes provider maps into root and plugin catalog outputs and still treats provider apiKey as required request-auth state; the PR body also supplies after-fix live output for a temp ensureOpenClawModelsJson run.

Review metrics: 2 noteworthy metrics.

  • Credential persistence paths: 3 changed. The diff changes merge-mode existing-key preservation, final generated catalog serialization, and auth-profile key projection, all of which affect upgrade-sensitive provider credentials.
  • Generated catalog outputs: 2 current-main output classes. Current main writes root models.json plus plugin-owned catalog sidecars, so credential redaction must be validated across both outputs before merge.

Stored data model
Persistent data-model change detected: serialized state: src/agents/models-config.providers.normalize-keys.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 open API-key exposure roadmap issue; overlapping PRs target the same generated model catalog credential leak, but none is a merged canonical replacement.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦞 diamond lobster
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

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

Rank-up moves:

  • Rebase or replace the branch against current main and cover both root and plugin-owned catalog writes.
  • Preserve or migrate loadable auth for config-only and plaintext-profile custom providers without persisting plaintext secrets.
  • Coordinate with maintainers on the canonical Layer 1 implementation among the overlapping PRs.

Risk before merge

  • [P1] GitHub reports the branch as conflicting with current main, so maintainers cannot evaluate the actual merged code until it is rebased or replaced.
  • [P1] Deleting every non-marker provider apiKey can make api-key custom-provider rows unloadable because current main still requires a catalog auth marker for rows with models.
  • [P1] Skipping plaintext auth-profile projection can leave profile-backed provider rows without the catalog auth signal needed before runtime auth resolution runs.
  • [P1] Current main writes root models.json and plugin-owned generated catalog sidecars; a one-output sanitizer can leave another prompt-visible generated catalog path unresolved.
  • [P1] Several open PRs target the same Layer 1 provider-secret leak, including a protected maintainer branch, so the permanent auth/upgrade policy still needs maintainer selection.

Maintainer options:

  1. Rebase and preserve the auth contract (recommended)
    Update this branch on current main, sanitize root and plugin-owned catalog writes, and prove custom-provider plus stale-upgrade auth still resolves without plaintext catalog secrets.
  2. Designate one canonical Layer 1 branch
    Compare the overlapping provider-key redaction PRs and choose a single implementation path before merging conflicting credential policy changes.
  3. Pause this contributor branch
    Keep this PR as source material until the protected maintainer branch or another current-main replacement settles the upgrade-safe secret-redaction design.

Next step before merge

  • [P2] Manual maintainer handling is needed because the PR conflicts with current main and the remaining blocker is a canonical auth/upgrade policy choice across overlapping security-fix PRs.

Security
Needs attention: The diff has no supply-chain expansion, but the credential hardening is incomplete against current main's generated catalog surfaces and can break auth loading.

Review findings

  • [P1] Sanitize plugin-owned catalog writes too — src/agents/models-config.plan.ts:200-201
  • [P1] Preserve loadable auth for custom provider rows — src/agents/models-config.plan.ts:116-118
  • [P1] Keep plaintext profile-backed rows loadable — src/agents/models-config.providers.secret-helpers.ts:309-311
Review details

Best possible solution:

Land one current-main canonical Layer 1 fix that redacts root and plugin-owned generated catalogs while preserving custom-provider and auth-profile upgrade behavior through a safe marker, runtime contract, or tested migration.

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

Yes. Source inspection shows current main serializes provider maps into root and plugin catalog outputs and still treats provider apiKey as required request-auth state; the PR body also supplies after-fix live output for a temp ensureOpenClawModelsJson run.

Is this the best way to solve the issue?

No, not as submitted. Stripping plaintext keys is the right security direction, but this branch needs a current-main rebase and an auth-preserving marker or migration path instead of deleting the only loadable credential signal for existing custom-provider/profile cases.

Full review comments:

  • [P1] Sanitize plugin-owned catalog writes too — src/agents/models-config.plan.ts:200-201
    This sanitizer is added on the older single-output planner path. Current main now serializes root providers and plugin-owned catalog sidecars separately, so a rebased fix must redact both outputs or plugin-owned generated catalogs can still persist provider keys.
    Confidence: 0.86
  • [P1] Preserve loadable auth for custom provider rows — src/agents/models-config.plan.ts:116-118
    Dropping every non-marker provider apiKey before serialization can make api-key custom providers with model rows unloadable. Current main still rejects those rows unless an apiKey or allowed non-api-key auth mode is present, so the fix needs a safe marker or migration path.
    Confidence: 0.87
  • [P1] Keep plaintext profile-backed rows loadable — src/agents/models-config.providers.secret-helpers.ts:309-311
    Skipping plaintext auth-profile projection leaves providers with model rows and only a plaintext profile key without any catalog apiKey. ModelRegistry.validateConfig runs before runtime auth can help, so these rows can fail to load unless the fix emits a safe marker or adds a tested migration path.
    Confidence: 0.83

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR targets plaintext provider credentials being persisted into prompt-visible generated model catalog data.
  • merge-risk: 🚨 compatibility: Changing generated models.json credential behavior can break existing custom-provider and upgrade paths that rely on catalog auth markers.
  • merge-risk: 🚨 auth-provider: The diff changes how provider credentials flow from config, auth profiles, env markers, and generated catalogs into runtime auth.
  • merge-risk: 🚨 security-boundary: The PR is a credential-exposure fix, and missing current-main generated catalog coverage can leave a prompt-visible secret persistence path unresolved.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes after-fix copied live output from an ensureOpenClawModelsJson run showing stale and runtime plaintext keys absent while a SecretRef marker remains.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix copied live output from an ensureOpenClawModelsJson run showing stale and runtime plaintext keys absent while a SecretRef marker remains.
Evidence reviewed

PR surface:

Source -8, Tests +67. Total +59 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 25 33 -8
Tests 3 72 5 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 97 38 +59

Security concerns:

  • [high] Generated plugin catalogs can remain unsanitized — src/agents/models-config.plan.ts:200
    Current main writes plugin-owned generated catalog sidecars separately from root models.json; a root-only redaction shape can leave provider credentials in another prompt-visible generated catalog output.
    Confidence: 0.86

What I checked:

  • Live PR state: GitHub reports this PR at head 8a22ac1 as CONFLICTING/DIRTY against main, so the actual merge result cannot be reviewed without a rebase or replacement. (8a22ac175ba0)
  • PR redaction location: The PR adds stripPlaintextApiKeys at the final root models.json serialization boundary on its older planner shape. (src/agents/models-config.plan.ts:106, 8a22ac175ba0)
  • Current main sidecar split: Current main splits final providers into root providers and plugin-owned catalog writes, so a rebased fix must sanitize both generated output classes. (src/agents/models-config.plan.ts:283, 816038e97a5d)
  • Registry auth contract: Current main still requires apiKey for api-key provider rows with custom models, except AWS SDK/OAuth auth modes. (src/agents/sessions/model-registry.ts:496, 816038e97a5d)
  • Current merge behavior: Current main preserves existing non-marker provider apiKey values during merge mode unless the next entry is already managed by a non-secret marker. (src/agents/models-config.merge.ts:190, 51e0997c2bbd)
  • Related canonical issue: The PR uses closing syntax for the open security roadmap issue, and that issue still tracks the broader credential-exposure problem and Layer 1 models.json leak.

Likely related people:

  • Vincent Koc: Current blame for the planner, merge helper, secret-helper, and model-registry lines central to this review points to recent current-main reshaping by Vincent Koc. (role: recent current-main area contributor; confidence: medium; commits: 51e0997c2bbd; files: src/agents/models-config.plan.ts, src/agents/models-config.merge.ts, src/agents/models-config.providers.secret-helpers.ts)
  • steipete: Git history shows extracted model-config merge helpers by Peter Steinberger, and the related protected maintainer PR fix(models): migrate catalog credentials into SQLite #87166 targets the same secret-preserving generated catalog behavior. (role: related branch owner and model-config refactor contributor; confidence: high; commits: 75e15216600b; files: src/agents/models-config.merge.ts, src/agents/models-config.plan.ts)
  • Josh Avant: History around SecretRef-safe models.json persistence and SecretRef runtime behavior is directly adjacent to the marker/auth contract this PR changes. (role: SecretRef and model-secret hardening contributor; confidence: high; commits: 1769fb2aa1d6, 8e20dd22d890; files: src/agents/model-auth-markers.ts, src/agents/models-config.providers.secret-helpers.ts, src/agents/model-auth.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.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 21, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. 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 May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Mossy Merge Sprite

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: watches the merge queue.
Image traits: location release reef; accessory miniature diff map; palette violet, aqua, and starlight; mood proud; pose holding its accessory up for inspection; shell brushed metal shell; lighting cool dashboard glow; background gentle dashboard dots.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Mossy Merge Sprite in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the focused redaction work and behavior proof. We’re consolidating this security boundary in maintainer-owned #87166. This branch now conflicts with main, removes compatibility paths that current custom-provider catalog loading still depends on, and predates plugin-owned generated catalog sidecars, leaving the fix one-sided against today’s writer. Closing as a superseded competing implementation; #11829 and #87166 remain open for the canonical solution.

@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security Roadmap: Protecting API Keys from Agent Access

2 participants