Skip to content

Avoid writing plaintext profile keys to models.json - #83296

Closed
jackspiece wants to merge 1 commit into
openclaw:mainfrom
jackspiece:fix/no-plaintext-profile-keys-models-json
Closed

jackspiece wants to merge 1 commit into
openclaw:mainfrom
jackspiece:fix/no-plaintext-profile-keys-models-json

Conversation

@jackspiece

@jackspiece jackspiece commented May 17, 2026 •

Copy link
Copy Markdown

Summary

This keeps plaintext auth-profile API keys out of generated models.json.

The provider normalization path already preserves env and SecretRef-backed credentials as markers. Plaintext auth-profile keys could still be copied into the generated provider config when a provider had models but no configured apiKey, when a generated provider apiKey matched the plaintext profile key, or when merge mode preserved an existing models.json value after the first normalization pass.

This PR skips plaintext profile keys for models.json persistence, strips matching plaintext values during provider normalization, and re-normalizes after merge mode preserves existing provider fields. The strip also applies to merge-preserved provider entries with no model rows, so old plaintext profile keys do not survive just because models is empty. Unrelated user-managed provider keys stay intact.

Real behavior proof

Behavior or issue addressed: plaintext auth-profile API keys should not be persisted into generated models.json provider entries, including merge-mode regeneration from an existing models.json and merge-preserved provider entries with models: [].

Real environment tested: local OpenClaw checkout on Android/arm64 Termux with Node v24.13.0. I used a temp agent directory with a real auth-profiles.json entry containing a plaintext openai:default key. The merge-mode proof used an existing parsed models.json with an OpenAI provider whose apiKey matched that plaintext profile key, models: [], plus a separate custom provider with an unrelated user-managed key.

Exact steps or command run after this patch: ran a node --import tsx --input-type=module script that saved the plaintext auth profile, called planOpenClawModelsJsonWithDeps in models.mode = \"merge\", parsed the generated contents, and printed whether the merged OpenAI provider still had an apiKey property and whether the unrelated custom provider key was preserved.

Evidence after fix: terminal output from the proof command:

{
  "action": "write",
  "openaiModelsLength": 0,
  "openaiHasApiKeyProperty": false,
  "openaiApiKeyValue": null,
  "customApiKeyPreserved": true,
  "providerIds": [
    "openai",
    "custom"
  ]
}

Observed result after fix: merge mode keeps the OpenAI and custom provider entries, removes the OpenAI apiKey value that matched the plaintext auth profile even though the OpenAI provider has no models, and preserves the unrelated custom provider apiKey.

What was not tested: full native tsgo in this environment, because @typescript/native-preview-android-arm64 is unavailable. Plain tsc on the full core test project also ran out of heap locally.

Tests

  • node_modules/.bin/vitest run --config test/vitest/vitest.agents.config.ts src/agents/models-config.providers.normalize-keys.test.ts
  • node_modules/.bin/vitest 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
  • node_modules/.bin/oxlint src/agents/models-config.plan.ts src/agents/models-config.providers.normalize.ts src/agents/models-config.providers.secret-helpers.ts src/agents/models-config.providers.normalize-keys.test.ts
  • git diff --check

Addresses #11829

@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 17, 2026
@clawsweeper

clawsweeper Bot commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 1, 2026, 2:22 AM ET / 06:22 UTC.

Summary
The branch changes models.json provider normalization and planning to avoid persisting plaintext auth-profile apiKey values, strip matching merge-preserved plaintext values, and add regression tests.

PR surface: Source +46, Tests +208. Total +254 across 4 files.

Reproducibility: yes. from current source inspection: current main can still fill a model-bearing provider apiKey from a plaintext auth profile, and the current planner only writes model-bearing providers when an apiKey remains. I did not run tests because this cleanup review is read-only.

Review metrics: 2 noteworthy metrics.

  • Credential persistence paths changed: 2 changed. The diff changes both missing auth-profile apiKey insertion and merge-preserved matching apiKey stripping, which affects auth upgrade behavior.
  • Current planner gates to reconcile: 2 current-main gates. Writable-provider filtering and plugin-owned catalog splitting now run before serialization and must survive a rebase.

Root-cause cluster
Relationship: partial_overlap
Canonical: #11829
Summary: This PR is one Layer 1 candidate in the broader API-key protection roadmap; several sibling PRs target the same models.json credential-persistence surface with different upgrade semantics.

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 preserve writable-provider filtering plus plugin catalog splitting.
  • Preserve a prompt-safe marker for profile-backed model rows, or explicitly change and test the writable-provider contract.
  • Coordinate with maintainers on the canonical Layer 1 branch and upgrade policy before landing overlapping credential-persistence fixes.

Risk before merge

  • [P1] A direct rebase that removes plaintext profile apiKey values can make current main's writable-provider filter drop model-bearing providers authenticated only by auth profiles.
  • [P1] Removing matching merge-preserved plaintext keys changes upgrade behavior for users whose existing models.json entry is their current credential source; maintainers need a marker, migration, or explicit documented policy.
  • [P1] Several open Layer 1 branches target the same credential-persistence surface with different stripping and migration semantics, so landing this one without choosing a canonical approach risks conflicting behavior.

Maintainer options:

  1. Rebase Through Current Planner (recommended)
    Port the stripping behavior onto current main and prove profile-backed providers with model rows remain discoverable through a non-secret marker or an intentional writable-provider contract change.
  2. Choose One Layer 1 Branch
    Maintainers can pick the canonical credential-persistence branch before landing overlapping implementations with different migration semantics.
  3. Document Or Migrate Existing Keys
    If matching merge-preserved plaintext keys should be removed, document and test the upgrade behavior or migrate those credentials out of models.json first.

Next step before merge

  • [P2] The remaining action is maintainer/author rebase plus a canonical Layer 1 and upgrade-policy choice, not a safe automated repair on this stale conflicting branch.

Security
Cleared: The diff is security-sensitive and narrows plaintext credential persistence; I found no new dependencies, workflows, downloaded code, or broadened secret access.

Review findings

  • [P1] Preserve a marker for profile-backed model rows — src/agents/models-config.providers.secret-helpers.ts:309-311
Review details

Best possible solution:

Land one rebased canonical Layer 1 fix that keeps plaintext secrets out of prompt-visible model catalogs while preserving provider rows, env/SecretRef markers, plugin catalog splitting, and explicit upgrade behavior for existing keys.

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

Yes, from current source inspection: current main can still fill a model-bearing provider apiKey from a plaintext auth profile, and the current planner only writes model-bearing providers when an apiKey remains. I did not run tests because this cleanup review is read-only.

Is this the best way to solve the issue?

No, not as-is against current main. The safer fix is to keep plaintext out of models.json while preserving a prompt-safe marker or adding an explicit, tested change to the writable-provider contract and upgrade policy.

Full review comments:

  • [P1] Preserve a marker for profile-backed model rows — src/agents/models-config.providers.secret-helpers.ts:309-311
    Current main writes model-bearing providers only when they still have baseUrl and apiKey. This change makes plaintext auth-profile credentials resolve to no apiKey, so a straightforward rebase can drop the provider row instead of preserving a non-secret marker; preserve a marker or intentionally change and test the filter.
    Confidence: 0.86

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 0c7bac34ae68.

Label changes

Label justifications:

  • P1: The PR addresses provider credentials being duplicated into prompt-visible generated model catalog data, which can expose real user API keys.
  • merge-risk: 🚨 compatibility: Changing generated models.json apiKey persistence can break existing users who rely on merge-mode provider auth fallback or model catalog rows.
  • merge-risk: 🚨 auth-provider: The diff changes how auth-profile credentials flow into generated provider config and model discovery/runtime auth assumptions.
  • 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 a real local Termux checkout showing the matching plaintext profile key removed and an unrelated custom provider key preserved.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from a real local Termux checkout showing the matching plaintext profile key removed and an unrelated custom provider key preserved.
Evidence reviewed

PR surface:

Source +46, Tests +208. Total +254 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 52 6 +46
Tests 1 209 1 +208
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 261 7 +254

What I checked:

  • Root repository policy read: Read the full 283-line root AGENTS.md; the provider/config compatibility, security, full-path review, and best-fix guidance directly affected this review. (AGENTS.md:1, 0c7bac34ae68)
  • Scoped agents policy read: Read the scoped src/agents guide; the touched tests are in the agent area, and the guide reinforces preserving production composition when changing agent test seams. (src/agents/AGENTS.md:1, 0c7bac34ae68)
  • PR changes plaintext profile key persistence: The PR changes resolveMissingProviderApiKey so plaintext auth-profile resolutions are no longer used as generated provider apiKey values, and adds a helper to delete matching plaintext provider apiKey values. (src/agents/models-config.providers.secret-helpers.ts:309, 80de67dc02cf)
  • Current main writable-provider gate: Current main only writes model-bearing provider entries when baseUrl and apiKey are present, so omitting a profile-backed apiKey without a replacement marker can remove the provider row from generated models.json. (src/agents/models-config.plan.ts:180, 0c7bac34ae68)
  • Current main serialization gates: Current main now normalizes with manifest plugin data, enforces source-managed secrets, filters writable providers, and splits plugin-owned provider catalogs before serializing root models.json; the old branch must preserve these gates during rebase. (src/agents/models-config.plan.ts:249, 0c7bac34ae68)
  • Current main still has source-level leak path: Current main still falls back to params.profileApiKey.apiKey when filling missing provider apiKey values for model-bearing providers, which includes plaintext auth-profile credentials. (src/agents/models-config.providers.secret-helpers.ts:348, 0c7bac34ae68)

Likely related people:

  • steipete: Live path history shows repeated recent work on models.json planning, provider normalization, model auth helpers, and the large agent-runtime refactor that changed the same surfaces this PR must rebase through. (role: planner and provider-normalization area contributor; confidence: high; commits: 51b5f75b92f7, bb46b79d3c14, 3e8fd4944fe1; files: src/agents/models-config.plan.ts, src/agents/models-config.providers.normalize.ts, src/agents/models-config.providers.secret-helpers.ts)
  • vincentkoc: Recent path history includes provider helper export cleanup and coauthored blank-base-url behavior around the models.json planner and writable-provider path. (role: recent adjacent contributor; confidence: medium; commits: e93996378491, 98e239d01201; files: src/agents/models-config.plan.ts, src/agents/models-config.providers.secret-helpers.ts)
  • lawrence3699: Recent history for the merge surface includes the baseUrl-preservation change in models-config.merge.ts, which is adjacent to this PR's merge-preserved credential behavior. (role: merge-preservation contributor; confidence: medium; commits: 35fb3f7e1c7b; files: src/agents/models-config.merge.ts, src/agents/models-config.plan.ts)
  • 849261680: Recent history on the secret-helper path includes the Vertex ADC catalog-auth marker work, which shares the same requirement to prove provider availability without persisting plaintext secrets. (role: provider auth marker contributor; confidence: medium; commits: a4f7e4cbb946; files: src/agents/models-config.providers.secret-helpers.ts, src/agents/models-config.providers.normalize.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: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 17, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. P1 High-priority user-facing bug, regression, or broken workflow. impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. labels May 17, 2026
@jackspiece
jackspiece force-pushed the fix/no-plaintext-profile-keys-models-json branch from a5338a9 to 7f79418 Compare May 17, 2026 22:42
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 17, 2026
@jackspiece

Copy link
Copy Markdown
Author

Thanks, addressed the merge-mode finding. The updated patch re-normalizes after merge-mode preservation so existing values matching plaintext auth-profile keys are stripped, while unrelated user-managed provider keys stay intact. Added a regression test through planOpenClawModelsJsonWithDeps for that exact path.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 17, 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 the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 17, 2026
@jackspiece
jackspiece force-pushed the fix/no-plaintext-profile-keys-models-json branch from 7f79418 to 80de67d Compare May 17, 2026 23:01
@jackspiece

Copy link
Copy Markdown
Author

Thanks, addressed the no-model-row gap from the latest review. The strip path now resolves the plaintext auth profile whenever the provider already has an apiKey, even if models is empty. I added a merge-mode regression for an existing OpenAI provider with models: [] and a matching plaintext profile key, while preserving an unrelated custom provider key.

Checks run locally:

  • node_modules/.bin/vitest run --config test/vitest/vitest.agents.config.ts src/agents/models-config.providers.normalize-keys.test.ts
  • node_modules/.bin/vitest 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
  • node_modules/.bin/oxlint src/agents/models-config.plan.ts src/agents/models-config.providers.normalize.ts src/agents/models-config.providers.secret-helpers.ts src/agents/models-config.providers.normalize-keys.test.ts
  • git diff --check

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 17, 2026
@clawsweeper

clawsweeper Bot commented May 17, 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 the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 17, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 17, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 17, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels May 18, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. labels Jun 15, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 19, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 22, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the careful follow-ups and regression coverage. We’re consolidating this security-sensitive behavior under #88562 and the maintainer-owned direction in #87166.

Current main now filters model-bearing providers on apiKey and writes both root models.json and plugin-owned catalog sidecars. This branch removes profile-backed auth before that current writable-provider contract, which can drop provider rows after rebase, and it does not cover the sidecar writer.

Closing this older competing implementation so the marker, runtime-auth, migration, and both-output contract can be solved once against current main. The underlying bug remains open; concrete new evidence should go to #88562. Thank you for the useful tests and proof.

@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. 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