Skip to content

fix(models): strip plaintext API keys from models.json - #83294

Closed
dzkjdxhbgog wants to merge 4 commits into
openclaw:mainfrom
dzkjdxhbgog:taskbounty-strip-models-json-api-keys
Closed

dzkjdxhbgog wants to merge 4 commits into
openclaw:mainfrom
dzkjdxhbgog:taskbounty-strip-models-json-api-keys

Conversation

@dzkjdxhbgog

@dzkjdxhbgog dzkjdxhbgog commented May 17, 2026 •

Copy link
Copy Markdown

Part of #11829.

Summary

  • Strip newly generated/configured plaintext provider apiKey values from generated models.json before writing it.
  • Preserve non-secret auth markers such as OPENAI_API_KEY and secretref-managed so env/secret-ref based provider setup keeps working.
  • Preserve SecretRef-managed provider apiKey markers, including custom env var names such as OPENCLAW_MODEL_LITELLM_API_KEY.
  • Preserve plaintext apiKey values that already exist in models.json during merge mode to avoid deleting a user's only current auth before a maintainer-approved migration path exists.
  • Add coverage for configured provider input, existing merged models.json entries, and marker preservation.

Real behavior proof

Behavior addressed: Generated models.json no longer persists newly configured plaintext provider apiKey values while preserving source-managed SecretRef markers and existing merge-mode plaintext auth entries.

Real environment tested: Blacksmith Testbox through Crabbox on Linux/Node 24, plus focused local OpenClaw tests.

Exact steps or command run after this patch: Ran pnpm check:changed through Testbox, then built the branch in Testbox and executed ensureOpenClawModelsJson against a temp agent directory seeded with merge-mode existing auth, one fresh plaintext provider, and one custom env SecretRef provider.

Evidence after fix: Testbox tbx_01ksktrrnfdbf54jx1fsjj87zf passed pnpm check:changed. Testbox tbx_01kskv2nshbd6ej6venxpgg4r2 passed build plus generated-models assertion and emitted {"customOmitted":true,"litellmMarker":"OPENCLAW_MODEL_LITELLM_API_KEY","existingPreserved":true,"litellmModels":["litellm-model"]}.

Observed result after fix: Newly configured plaintext auth is omitted from generated models.json, the custom env SecretRef marker is persisted, the pre-existing merge-mode plaintext entry is preserved, and the configured model row remains present.

What was not tested: No migration from existing plaintext models.json auth into a separate secret store; that still needs maintainer/security policy.

Tests

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-core.config.ts src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.uses-first-github-copilot-profile-env-tokens.test.ts src/agents/models-config.runtime-source-snapshot.test.ts
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo
  • pnpm check:changed via Testbox-through-Crabbox tbx_01ksktrrnfdbf54jx1fsjj87zf
  • Build plus generated models.json real scenario via Testbox-through-Crabbox tbx_01kskv2nshbd6ej6venxpgg4r2
  • autoreview helper --mode local

@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

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: this is a focused security-sensitive fix for prompt-visible provider credentials, and I found no blocking code defect in the diff, but current-head real behavior proof and maintainer policy review are still needed before merge.

Canonical path: Close this PR as superseded by #83592.

So I’m closing this here and keeping the remaining discussion on #83592.

Review details

Best possible solution:

Close this PR as superseded by #83592.

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

Yes by source inspection: current main serializes finalProviders directly into models.json, while the PR test demonstrates the plaintext-key case and expected sanitized output. I did not run the proof locally because this review is read-only.

Is this the best way to solve the issue?

Mostly yes for the narrow Layer 1 boundary: a final persistence sanitizer is maintainable and well scoped. The unresolved choice is whether preserving legacy plaintext models.json auth is the intended compatibility bridge or should be replaced by a migration-first sibling.

Security review:

Security review cleared: Security-sensitive credential persistence was reviewed and I found no concrete new security or supply-chain regression in the patch itself.

AGENTS.md: found and applied where relevant.

What I checked:

  • linked superseding PR: fix(models): avoid persisting prompt-visible provider secrets #83592 (fix(models): avoid persisting prompt-visible provider secrets) is still open as the canonical replacement.
  • cluster evidence: the durable review links that PR in the work cluster or recommended risk path.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Peter Steinberger has the heaviest shortlog presence across the implicated models/auth files and authored the latest PR branch commit preserving SecretRef markers. (role: recent area contributor and PR branch follow-up; confidence: high; commits: fdd8013399ed, 75e15216600b; files: src/agents/models-config.plan.ts, src/agents/models-config.merge.ts, src/agents/model-auth-markers.ts)
  • joshavant: Josh Avant authored earlier SecretRef custom/provider persistence hardening that directly overlaps the marker and credential-persistence contract this PR relies on. (role: SecretRef/auth hardening contributor; confidence: medium; commits: 36d2ae2a2235; files: src/agents/models-config.providers.secret-helpers.ts, src/agents/model-auth-markers.ts, src/agents/models-config.merge.ts)
  • eleqtrizit: Agustin Rivera is the blamed author for the current main copy of the central planner, merge, and marker files after the latest source movement on this area. (role: recent current-main source carrier; confidence: medium; commits: c1151ea8993c; files: src/agents/models-config.plan.ts, src/agents/models-config.merge.ts, src/agents/model-auth-markers.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 5371b96af12b.

@clawsweeper clawsweeper Bot added 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
@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. impact:data-loss Can lose, corrupt, or silently drop user/session/config data. labels May 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. labels May 17, 2026
@dzkjdxhbgog

Copy link
Copy Markdown
Author

@clawsweeper re-review

I pushed 5b1095c to address the P1 data-loss concern: new plaintext provider keys are stripped, while existing merge-mode models.json plaintext auth is preserved until a maintainer-approved migration path exists. The PR body has updated proof and tests.

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

@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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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 17, 2026

Copy link
Copy Markdown
Author

Hi maintainers, following up on this PR for #11829.

The bot review currently says this needs human maintainer review mainly for the security/compatibility policy and ordering with #83296. Could you confirm whether this PR is still wanted/in scope for #11829 / the TaskBounty-linked work, and what change or decision is needed for acceptance?

If this is no longer eligible for bounty/award because a different fix landed first, please let me know so I can close or redirect the work.

@steipete steipete self-assigned this May 27, 2026
@steipete
steipete force-pushed the taskbounty-strip-models-json-api-keys branch from 5b1095c to fdd8013 Compare May 27, 2026 04:36
@openclaw-barnacle openclaw-barnacle Bot added triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. labels May 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. impact:data-loss Can lose, corrupt, or silently drop user/session/config data. 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 27, 2026
@clawsweeper

clawsweeper Bot commented May 27, 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.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels May 27, 2026
@clawsweeper

clawsweeper Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@steipete

Copy link
Copy Markdown
Contributor

Thanks for the PR. I did a deeper pass through the OpenClaw + PI model-registry path and found one more issue: removing a newly generated plaintext apiKey entirely makes PI reject non-built-in custom providers that define model rows, because PI requires an apiKey field for those providers.

I could not update this fork branch further because maintainer edits are disabled, so I recreated the corrected stack in #87166 with your commits plus a maintainer fixup. The replacement keeps plaintext secrets out of generated models.json, preserves SecretRef/env markers, uses a non-secret OpenClaw-managed marker for config-owned plaintext keys so PI validation still passes, and adds regression proof against the real PI registry.

Proof on the replacement PR: Testbox-through-Crabbox tbx_01kskw2wgxe8999xxqamy1m5c2, https://github.com/openclaw/openclaw/actions/runs/26491356820, passed focused tests plus check:changed.

For future PRs, enabling GitHub's "Allow edits by maintainers" lets us push small fixups directly while preserving your branch.

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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants