Skip to content

fix: strip plaintext model api keys from models json - #84557

Closed
Kzics wants to merge 1 commit into
openclaw:mainfrom
Kzics:fix/models-json-existing-plaintext-api-keys
Closed

Kzics wants to merge 1 commit into
openclaw:mainfrom
Kzics:fix/models-json-existing-plaintext-api-keys

Conversation

@Kzics

@Kzics Kzics commented May 20, 2026 •

Copy link
Copy Markdown

Summary

  • Strip plaintext provider apiKey values from generated models.json before prompt-visible serialization.
  • Preserve SecretRef/env-managed markers and known non-secret auth markers.
  • Add regression coverage for configured plaintext keys, existing merge-mode models.json plaintext keys, and SecretRef markers.

Refs #11829

Verification

  • pnpm format:check src/agents/models-config.plan.ts src/agents/models-config.applies-config-env-vars.test.ts
  • node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/models-config.plan.ts src/agents/models-config.applies-config-env-vars.test.ts
  • node scripts/run-vitest.mjs run src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.merge.test.ts --passWithNoTests=false
  • pnpm tsgo:core
  • pnpm tsgo:core:test

Real behavior proof

Behavior addressed: Generated models.json no longer persists plaintext provider apiKey values from active config or old merge-mode models.json entries.

Real environment tested: Windows 11/PowerShell, Node v23.11.0, pnpm 11.1.0, local OpenClaw source checkout.

Exact steps or command run after this patch:

  • node --import tsx .artifacts/proof-models-json.mts
  • pnpm format:check src/agents/models-config.plan.ts src/agents/models-config.applies-config-env-vars.test.ts
  • node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/models-config.plan.ts src/agents/models-config.applies-config-env-vars.test.ts
  • node scripts/run-vitest.mjs run src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.merge.test.ts --passWithNoTests=false
  • pnpm tsgo:core
  • pnpm tsgo:core:test

Evidence after fix: Terminal output from a local OpenClaw source checkout invoking the patched models.json planner. The command used a fake plaintext provider apiKey value and printed the generated provider JSON after the patch:

{
  "action": "write",
  "providerKeys": [
    "custom"
  ],
  "customHasApiKey": false,
  "planContainsPlaintext": false,
  "modelIds": [
    "proof-model"
  ],
  "writtenModelsJson": {
    "providers": {
      "custom": {
        "baseUrl": "https://example.invalid/v1",
        "api": "openai-responses",
        "models": [
          {
            "id": "proof-model",
            "name": "Proof Model",
            "input": [
              "text"
            ],
            "reasoning": false,
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 8192,
            "maxTokens": 2048
          }
        ]
      }
    }
  }
}

Observed result after fix: The command exited 0. The generated provider JSON contains the custom provider and model, but customHasApiKey is false and planContainsPlaintext is false, confirming the plaintext apiKey was not written into models.json.

What was not tested: Full suite, live gateway/model provider calls, and cross-platform Testbox/Crabbox proof.

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

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed June 30, 2026, 5:41 AM ET / 09:41 UTC.

Summary
The branch adds a models.json provider sanitizer that removes non-marker apiKey values before serialization and adds regression tests for configured, merge-preserved, and SecretRef-managed provider keys.

PR surface: Source +28, Tests +152. Total +180 across 2 files.

Reproducibility: yes. at source level. The PR removes apiKey from generated custom-provider rows while current ModelRegistry rejects custom model providers without apiKey unless an explicit auth mode allows it.

Review metrics: 2 noteworthy metrics.

  • Persisted provider credential behavior: 1 apiKey serialization path removed. The PR removes a credential field that current docs, merge behavior, and runtime validation still treat as a provider auth source.
  • Generated catalog outputs: 2 output classes on current main. Current main writes root models.json plus plugin-owned catalog sidecars, so the redaction policy has to cover both before merge.

Stored data model
Persistent data-model change detected: serialized state: src/agents/models-config.applies-config-env-vars.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #11829
Summary: This PR is a candidate Layer 1 fix for the open API-key exposure roadmap, but the broader issue remains canonical and overlapping PRs are not safe superseding landing paths yet.

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:

  • [P1] Add an auth-preserving marker, migration, or maintainer-approved fail-closed path with fresh-install and upgrade coverage.
  • Rebase or fold the work into a current-main branch that sanitizes both root models.json and plugin-owned catalog sidecars.

Risk before merge

  • [P1] Existing users whose only custom-provider credential is a plaintext apiKey in per-agent models.json or generated provider config can lose runtime auth or model availability after regeneration.
  • [P1] The branch is conflicting and predates current main's plugin-owned catalog sidecars, so the final redaction policy must cover both root models.json and plugin catalog writes.
  • [P1] Several overlapping Layer 1 credential-persistence PRs remain open, and maintainers still need to choose one canonical marker, migration, or fail-closed policy before landing a variant.

Maintainer options:

  1. Select and rebase one canonical Layer 1 fix (recommended)
    Choose a single landing branch and update it against current main so root models.json, plugin catalog sidecars, runtime auth, and upgrade behavior are covered together.
  2. Approve an explicit fail-closed upgrade policy
    Maintainers can intentionally remove models.json-only plaintext auth only with visible upgrade guidance and tests proving the intended failure mode.
  3. Park this branch as source material
    If another branch becomes canonical, preserve this PR's useful regression cases there and leave this conflicting branch unmerged.

Next step before merge

  • [P2] Manual maintainer handling is needed because the remaining blocker is credential/auth upgrade policy and selection among overlapping Layer 1 branches, not a narrow mechanical patch.

Security
Needs attention: The direction is security-positive, but the credential stripping still lacks an auth-preserving contract and current generated-catalog coverage before merge.

Review findings

  • [P1] Preserve runtime auth when stripping provider apiKeys — src/agents/models-config.plan.ts:205-208
Review details

Best possible solution:

Land one current-main Layer 1 fix that redacts prompt-visible provider credentials across root and plugin-generated catalogs while preserving or explicitly migrating runtime auth through a tested credential contract.

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

Yes, at source level. The PR removes apiKey from generated custom-provider rows while current ModelRegistry rejects custom model providers without apiKey unless an explicit auth mode allows it.

Is this the best way to solve the issue?

No, not as submitted. Stripping prompt-visible secrets is the right direction, but this patch needs a tested auth-preserving migration or approved fail-closed policy and coverage for current plugin catalog sidecars.

Full review comments:

  • [P1] Preserve runtime auth when stripping provider apiKeys — src/agents/models-config.plan.ts:205-208
    The sanitizer removes provider.apiKey after merge-mode preservation while keeping custom model rows in the generated catalog. Current ModelRegistry rejects providers with custom models and no apiKey unless an explicit auth mode allows it, so regeneration can make existing custom models disappear or lose auth; add a marker, migration, or maintainer-approved fail-closed path before stripping the only credential.
    Confidence: 0.9

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 738b2be4b49b.

Label changes

Label justifications:

  • P1: The PR targets provider API key exposure in prompt-visible model catalog data, with security and auth workflow consequences.
  • merge-risk: 🚨 compatibility: Changing persisted models.json apiKey behavior can break existing custom-provider setups and upgrade/regeneration flows.
  • merge-risk: 🚨 auth-provider: The diff changes how provider credentials move from config and models.json into runtime model request auth.
  • merge-risk: 🚨 security-boundary: Generated model catalogs are prompt-visible credential surfaces, and incomplete coverage can leave sensitive provider material exposed or break the intended credential boundary.
  • 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 copied terminal output from a local Windows OpenClaw checkout showing a fake plaintext apiKey absent from generated provider JSON after the patch; it proves redaction, but not the upgrade/auth path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied terminal output from a local Windows OpenClaw checkout showing a fake plaintext apiKey absent from generated provider JSON after the patch; it proves redaction, but not the upgrade/auth path.
Evidence reviewed

PR surface:

Source +28, Tests +152. Total +180 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 29 1 +28
Tests 1 152 0 +152
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 181 1 +180

Security concerns:

  • [high] Credential stripping lacks an auth-preserving contract — src/agents/models-config.plan.ts:205
    Removing provider apiKey values from generated catalogs without a replacement marker, migration, or approved fail-closed path can break model auth while appearing to complete the security hardening.
    Confidence: 0.88
  • [medium] Plugin catalog sidecars need the same redaction policy — src/agents/models-config.plan.ts:287
    Current main serializes plugin-owned provider catalogs separately from root models.json, so a current landing path must prove sidecars cannot keep prompt-visible provider credentials.
    Confidence: 0.84

What I checked:

  • Repository policy applied: Root policy was read fully and treats provider routing, auth/session state, persisted preferences, config loading, migrations, setup, startup checks, and fallback behavior as compatibility-sensitive review surfaces. (AGENTS.md:35, 738b2be4b49b)
  • Scoped agent guidance read: The scoped agent guide was read fully; it asks reviewers to keep agent tests runtime-light but preserve exact production composition when moving coverage. (src/agents/AGENTS.md:1, 738b2be4b49b)
  • PR strips apiKey at serialization boundary: The PR adds stripPlaintextProviderApiKeysForModelsJson and calls it around the final provider payload before JSON.stringify. (src/agents/models-config.plan.ts:205, 53783c05801e)
  • PR tests preserve custom model rows while removing apiKey: The new tests assert the generated custom provider has no apiKey while its model row is still serialized, creating the auth-preservation compatibility question. (src/agents/models-config.applies-config-env-vars.test.ts:322, 53783c05801e)
  • Current main rejects custom models without apiKey: Current ModelRegistry throws for custom model providers with models but no apiKey unless the provider auth mode explicitly allows missing keys. (src/agents/sessions/model-registry.ts:496, 738b2be4b49b)
  • Current main tests lock in no-apiKey rejection: A current regression test asserts custom api-key models without apiKey are rejected and unavailable. (src/agents/sessions/model-registry.test.ts:133, 738b2be4b49b)

Likely related people:

  • steipete: Git history shows repeated models-config planning/refactor commits, and the related maintainer branch contains Peter Steinberger fixups for this same Layer 1 area. (role: model-config refactor contributor and related branch author; confidence: high; commits: c29b09874416, 75e15216600b, 9e8151f34720; files: src/agents/models-config.plan.ts, src/agents/models-config.merge.ts, src/agents/models-config.applies-config-env-vars.test.ts)
  • joshavant: History around SecretRef-safe models.json persistence and source-managed marker enforcement defines the marker contract this PR must preserve. (role: SecretRef and model-secret hardening contributor; confidence: high; commits: 8e20dd22d890, 36d2ae2a2235, 0bcb95e8fa5e; files: src/agents/model-auth-markers.ts, src/agents/models-config.plan.ts, src/agents/models-config.providers.source-managed.ts)
  • vincentkoc: Recent history touches agent model discovery, provider normalization, and nearby marker/config surfaces that overlap the current-main path this branch must rebase onto. (role: recent adjacent model/auth contributor; confidence: medium; commits: 74e7b8d47b18, 86135d5889df, aa69b12d0086; files: src/agents/model-auth-markers.ts, src/agents/sessions/model-registry.ts, src/agents/models-config.plan.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. 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 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🔥 Warming up: real-behavior proof passed; findings, security review, or rank-up moves are still in progress.

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.
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. labels May 20, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 20, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jun 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the implementation and Windows proof. We’re consolidating this security-sensitive behavior under #88562 and the maintainer-owned direction in #87166.

This branch strips configured and merge-preserved plaintext apiKey values while preserving known markers. On current main, ordinary custom model rows still require an auth marker and are filtered or rejected without one, so the change can remove models or break existing auth. It also sanitizes only the old root writer and does not cover plugin-owned catalog sidecars.

Closing this older competing implementation so the marker, migration, request-auth, and both-output behavior can be designed and proved together. The underlying issue remains open in #88562. Thank you for the regression cases 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. 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.

3 participants