Skip to content

Strip resolved provider api keys from models.json - #84689

Closed
Trojan7210 wants to merge 2 commits into
openclaw:mainfrom
Trojan7210:codex/strip-models-json-api-keys
Closed

Trojan7210 wants to merge 2 commits into
openclaw:mainfrom
Trojan7210:codex/strip-models-json-api-keys

Conversation

@Trojan7210

@Trojan7210 Trojan7210 commented May 20, 2026 •

Copy link
Copy Markdown

Summary

  • Replace runtime-resolved provider apiKey values with the non-secret SecretRef marker before writing planned models.json contents.
  • Keep merge-mode behavior for user-authored existing provider keys while preventing newly resolved plaintext keys from being serialized.
  • Add regression coverage for replace-mode stale plaintext removal and merge-mode new provider sanitization.

Real behavior proof

Behavior or issue addressed: Generated models.json should not persist a runtime-resolved provider apiKey; it should write the existing non-secret marker while preserving the provider/model entry.

Real environment tested: Local checkout of openclaw/openclaw at PR head 3410456354, Node v26.1.0, pnpm 11.1.0, Linux x86_64, temporary agent dir /tmp/openclaw-real-proof-qmMXI3.

Exact steps or command run after this patch:

  1. Ran the real ensureOpenClawModelsJson writer with a provider config containing apiKey: "sk-live-proof-value".
  2. Read the written <temp-agent-dir>/models.json file.
  3. Parsed providers.liveproof.apiKey and checked whether the serialized output contained the input key.

Evidence after fix:

$ node --import tsx --input-type=module --eval <real models.json writer proof>
{
  "wrote": true,
  "agentDir": "/tmp/openclaw-real-proof-qmMXI3",
  "serializedApiKey": "secretref-managed",
  "containsSecret": false,
  "modelCount": 1
}

Observed result after fix: models.json was written with providers.liveproof.apiKey equal to secretref-managed; the serialized file did not contain sk-live-proof-value.

What was not tested: Full OpenClaw gateway runtime with a live external provider request was not exercised; this proof covers the actual models.json writer path and serialization result.

Validation

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents.config.ts src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.merge.test.ts -> 22 passed
  • git diff --check

Refs #11829

Payment or bounty payout details can be coordinated privately if this is accepted.

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

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Summary
The PR replaces newly resolved provider apiKey strings with the secretref-managed marker before writing planned models.json, preserves selected merge-mode existing keys, adds regression tests, and makes a small OpenRouter routing cleanup.

PR surface: Source +82, Tests +121. Total +203 across 3 files.

Reproducibility: yes. at source level: current main serializes plugin-owned provider maps directly into generated plugin catalog sidecars, and the PR proof covers only the older root writer path. I did not run a mutating repro because this review is read-only.

Review metrics: 2 noteworthy metrics.

  • Generated Catalog Outputs: 2 output classes. Current main writes both root models.json and plugin-owned catalog sidecars, so credential redaction must cover both before merge.
  • Persisted apiKey Policy: 1 preserved plaintext path. The PR keeps selected merge-mode existing plaintext keys, which affects upgrade compatibility and credential residue.

Stored data model
Persistent data-model change detected: serialized state: src/agents/models-config.applies-config-env-vars.test.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #88562
Summary: This PR is one candidate fix for the generated provider credential persistence cluster; the concrete canonical issue remains open, and sibling branches target overlapping root/plugin catalog redaction and migration policies.

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 onto current main and sanitize provider keys before both root and plugin catalog serialization.
  • [P2] Add focused regression coverage or real proof for plugin-owned catalog sidecars.
  • Get maintainer direction on preserving, scrubbing, or migrating existing merge-mode plaintext keys.

Risk before merge

  • [P1] If this branch is rebased without moving redaction before the root/plugin split or applying it to both outputs, plugin-owned generated plugins/<id>/catalog.json sidecars can still persist plaintext provider apiKey values.
  • [P1] The PR preserves selected merge-mode existing plaintext apiKey values, which may protect existing local auth but leaves credential residue unless maintainers explicitly accept, scrub, or migrate that state.
  • [P1] The branch is currently conflicting and there are multiple sibling candidate PRs for the same credential-persistence cluster, so maintainers need to choose one canonical security fix and upgrade policy.

Maintainer options:

  1. Rebase And Sanitize Every Generated Catalog (recommended)
    Rebase onto current main and apply redaction before both root models.json and plugin-owned catalog serialization, with sidecar regression coverage.
  2. Choose Existing-Key Upgrade Policy
    Maintainers should decide whether existing plaintext generated keys are temporarily preserved, scrubbed, or migrated into auth storage before this lands.
  3. Adopt A Cleaner Canonical Branch
    If a sibling branch becomes the clean proof-positive landing path, pause or close this PR only after that replacement is viable or merged.

Next step before merge

  • [P2] This is security-sensitive and has conflicting sibling candidate branches, so maintainers need to choose the canonical fix, rebase path, and existing-plaintext upgrade policy rather than queueing autonomous repair.

Security
Needs attention: The diff narrows plaintext secret persistence for the root writer path, but current-main plugin catalog sidecar serialization and existing plaintext-key policy remain unresolved.

Review findings

  • [P1] Sanitize every generated catalog output — src/agents/models-config.plan.ts:259-263
Review details

Best possible solution:

Land one current-main fix that redacts plaintext provider credentials before the root/plugin catalog split or in both writers, preserves documented non-secret markers, and explicitly implements the chosen upgrade path for existing plaintext keys.

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

Yes, at source level: current main serializes plugin-owned provider maps directly into generated plugin catalog sidecars, and the PR proof covers only the older root writer path. I did not run a mutating repro because this review is read-only.

Is this the best way to solve the issue?

No, not as submitted. Sanitizing generated catalog output is the right layer, but the branch must cover current-main plugin sidecars and settle the existing-plaintext upgrade policy before it is the best fix.

Full review comments:

  • [P1] Sanitize every generated catalog output — src/agents/models-config.plan.ts:259-263
    Current main writes plugin-owned generated plugins/<id>/catalog.json sidecars from the same provider map. This patch sanitizes only the root models.json payload from the older planner shape, so after rebase a plugin-owned provider can still serialize a plaintext apiKey through buildPluginCatalogWrites; sanitize before the split or apply the same sanitizer to both outputs.
    Confidence: 0.87

Overall correctness: patch is incorrect
Overall confidence: 0.87

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 provider credential exposure in generated agent-readable model catalog files.
  • merge-risk: 🚨 compatibility: Changing or preserving generated apiKey values can alter upgrade behavior for existing custom-provider setups.
  • merge-risk: 🚨 auth-provider: The diff changes persisted provider credential material and must still leave runtime auth resolution working across root and plugin catalogs.
  • merge-risk: 🚨 security-boundary: Incomplete redaction coverage can leave plaintext credentials in generated files readable by agent/runtime paths.
  • 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 (terminal): The PR body includes after-fix terminal output from the real root writer path showing the input plaintext key absent and secretref-managed written, but that proof does not cover the current-main plugin sidecar gap.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from the real root writer path showing the input plaintext key absent and secretref-managed written, but that proof does not cover the current-main plugin sidecar gap.
Evidence reviewed

PR surface:

Source +82, Tests +121. Total +203 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 88 6 +82
Tests 1 121 0 +121
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 209 6 +203

Security concerns:

  • [high] Generated plugin catalogs can remain unsanitized — src/agents/models-config.plan.ts:89
    Current main serializes plugin-owned provider maps into generated catalog sidecars; a sanitizer that only wraps the root payload can still leave plaintext provider keys in agent-readable sidecar files.
    Confidence: 0.86
  • [medium] Existing plaintext keys remain policy-sensitive — src/agents/models-config.plan.ts:143
    The PR preserves selected existing merge-mode plaintext keys, which may protect compatibility but can also keep credential material in generated catalog files unless maintainers explicitly accept or migrate that state.
    Confidence: 0.78

What I checked:

  • Repository policy read: Root and scoped agent/extension AGENTS.md files were read; their provider-auth, persisted config, plugin-boundary, and security-sensitive review guidance affected this verdict. (AGENTS.md:20, 816038e97a5d)
  • Live PR state: GitHub reports this PR open, non-draft, maintainer-editable, head 55e52ae, and mergeable=CONFLICTING / mergeStateStatus=DIRTY. (55e52aeef793)
  • PR sanitizer scope: The PR diff adds a sanitizer immediately before serializing the root models.json payload, but its patch was written against the old single-output planner shape. (src/agents/models-config.plan.ts:251, 55e52aeef793)
  • Current main plugin sidecar writer: Current main serializes plugin-owned provider maps directly into generated plugin catalog sidecar contents, so provider credential redaction must cover this output too. (src/agents/models-config.plan.ts:83, 816038e97a5d)
  • Current main root/plugin split: Current main splits finalProviders into root providers and plugin-owned providers before writing root models.json, creating two generated output classes from the same provider map. (src/agents/models-config.plan.ts:283, 816038e97a5d)
  • Plugin catalog write path: ensureOpenClawModelsJson writes the planned plugin catalog sidecars under the agent directory after root models.json, so unsanitized sidecar contents persist to disk. (src/agents/models-config.ts:231, 816038e97a5d)

Likely related people:

  • vincentkoc: Current blame for the plugin catalog writer, root/plugin split, merge preservation helper, marker definition, and touched OpenRouter routing lines points to commit 51e0997. (role: recent current-main carrier; confidence: high; commits: 51e0997c2bbd; files: src/agents/models-config.plan.ts, src/agents/models-config.merge.ts, src/agents/model-auth-markers.ts)
  • steipete: History for the models-config planning boundary includes the pure planner split and merge-helper extraction that define where this PR applies its serialization change. (role: planner and merge-helper refactor contributor; confidence: medium; commits: c29b09874416, 75e15216600b; files: src/agents/models-config.plan.ts, src/agents/models-config.ts, src/agents/models-config.merge.ts)
  • joshavant: Symbol history ties SecretRef-safe custom/provider secret persistence and secretref-managed behavior to prior merged SecretRef hardening work. (role: SecretRef hardening contributor; confidence: medium; commits: 36d2ae2a2235; files: src/agents/model-auth-markers.ts, src/agents/models-config.providers.source-managed.ts, src/agents/models-config.runtime-source-snapshot.test.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 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Brave Branchling

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: sniffs out flaky tests.
Image traits: location merge queue dock; accessory little merge flag; palette amber, ink, and glacier blue; mood mischievous; pose peeking out from the egg shell; shell matte ceramic shell; lighting golden review-room light; background tiny shells and proof notes.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Brave Branchling 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.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels May 20, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 20, 2026
@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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 15, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the implementation and writer-path proof. We’re consolidating this credential-persistence cluster under #88562 and the maintainer-owned direction in #87166.

This branch sanitizes the older root models.json payload after provider planning. Current main splits the same provider map into root output and plugin-owned catalog sidecars, so this placement leaves the sidecar path uncovered. Reusing secretref-managed for arbitrary resolved values also loses the credential provenance needed by runtime auth and migration.

Closing this competing implementation rather than carrying an incomplete security contract forward. The bug remains open in #88562; a current fix must cover both outputs and prove request auth and upgrade behavior. Thank you for the proof and regression cases.

@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 extensions: openrouter 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: M 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.

2 participants