Skip to content

[codex] fix: omit provider api keys from generated models.json - #84566

Closed
piaoguodeafei wants to merge 1 commit into
openclaw:mainfrom
piaoguodeafei:codex/omit-models-json-api-keys
Closed

piaoguodeafei wants to merge 1 commit into
openclaw:mainfrom
piaoguodeafei:codex/omit-models-json-api-keys

Conversation

@piaoguodeafei

Copy link
Copy Markdown

Summary

Fixes #11829.

This prevents generated models.json files from persisting provider-level apiKey fields. The sanitization happens at the serialization boundary, after provider discovery/normalization/merge, so provider catalog metadata remains available while credentials stay out of the prompt-visible model catalog.

Covered cases:

  • implicit provider env markers, such as OPENAI_API_KEY
  • literal configured provider keys
  • stale provider keys preserved from an existing models.json in merge mode

Root cause

planOpenClawModelsJsonWithDeps() built the final provider catalog and serialized it directly. Earlier steps could add apiKey values or preserve them from an existing models.json, so secrets or secret markers were written back into the agent model catalog.

Validation

  • corepack pnpm exec oxfmt --check --threads=1 src/agents/models-config.plan.ts src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.runtime-source-snapshot.test.ts src/agents/models-config.skips-writing-models-json-no-env-token.test.ts
  • corepack pnpm check:test-types
  • node scripts/test-projects.mjs $(rg --files src/agents | rg 'models-config.*\.test\.ts$')

@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: needs real behavior proof before merge. Reviewed June 30, 2026, 4:20 PM ET / 20:20 UTC.

Summary
The PR adds a planner helper that omits provider-level apiKey fields from generated models.json output and updates related models-config tests to expect those fields to be absent.

PR surface: Source +20, Tests +84. Total +104 across 4 files.

Reproducibility: yes. Source inspection shows current generated catalog planning still carries apiKey markers/credentials into writable provider rows, and the registry requires or uses that field for custom-provider discovery and request auth.

Review metrics: 2 noteworthy metrics.

  • Credential Field Handling: 1 provider field removed globally. The diff changes every generated provider row carrying apiKey, including marker and upgrade cases.
  • Generated Catalog Outputs: 2 current-main output classes. Root models.json and plugin-owned generated catalog sidecars both need sanitizer coverage before this security fix can land.

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

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #11829
Summary: This PR is one candidate implementation for the open API-key exposure roadmap's Layer 1 generated models.json work; overlapping open PRs are related but not merged canonical replacements.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof is added.

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

Rank-up moves:

  • [P1] Add redacted real behavior proof showing sanitized generated output and continued supported auth/model discovery.
  • Rebase on current main and cover both root models.json and plugin-owned generated catalog sidecars.
  • Preserve or migrate supported models.json credentials and non-secret markers before stripping plaintext output.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body lists validation commands only; it needs redacted terminal output, generated-file contents, logs, or a linked artifact from a real setup showing sanitized output and continued auth/model discovery. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Blanket apiKey deletion can erase supported env/SecretRef markers and models.json-only credentials, making existing custom providers unloadable or unauthenticated after regeneration.
  • [P1] The branch is draft and conflicting with current main, whose generated catalog path now includes root models.json plus plugin-owned sidecar catalogs.
  • [P1] The PR body lists validation commands only and lacks redacted real setup output showing sanitized generated files plus continued auth/model discovery.
  • [P1] Several overlapping PRs propose different Layer 1 auth, marker, and migration policies, so maintainers need one current-main canonical direction before merge.

Maintainer options:

  1. Rebase With Marker-Aware Redaction (recommended)
    Rework on current main so plaintext secrets are removed from every generated catalog output while supported markers and upgrade credentials are preserved or explicitly migrated.
  2. Choose One Layer 1 Branch
    Compare the overlapping generated-catalog credential PRs and designate a single canonical implementation before investing more review in conflicting branches.
  3. Accept Breaking Auth Policy Explicitly
    Maintainers can intentionally retire generated auth values only with documented operator action and proof of fresh-install plus upgrade recovery paths.

Next step before merge

  • [P1] Manual maintainer handling is needed because the branch is draft/conflicting and the remaining blocker is a canonical security/auth upgrade policy choice across overlapping PRs.

Security
Needs attention: The direction is security-positive, but the diff changes credential persistence without proving auth compatibility or current-main catalog coverage.

Review findings

  • [P1] Preserve supported auth values before stripping apiKeys — src/agents/models-config.plan.ts:120
Review details

Best possible solution:

Land one current-main Layer 1 fix that redacts plaintext generated catalog secrets across root and plugin-owned outputs while preserving or migrating supported credentials and non-secret markers.

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

Yes. Source inspection shows current generated catalog planning still carries apiKey markers/credentials into writable provider rows, and the registry requires or uses that field for custom-provider discovery and request auth.

Is this the best way to solve the issue?

No, not as written. Serialization-boundary redaction is the right layer, but deleting every apiKey after marker and merge handling is too broad without a preservation or migration policy and current-main sidecar coverage.

Full review comments:

  • [P1] Preserve supported auth values before stripping apiKeys — src/agents/models-config.plan.ts:120
    This deletes every provider apiKey after merge-mode and source-marker handling have intentionally preserved supported auth values. Current main still requires apiKey for ordinary custom model rows and falls back to provider apiKey for request auth, so regeneration can make existing providers unloadable or unauthenticated unless safe markers are preserved or credentials are migrated.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 640258d7b31d.

Label changes

Label justifications:

  • P1: The PR targets prompt-visible provider credential exposure, but the current patch can also break provider authentication during upgrade.
  • merge-risk: 🚨 compatibility: Removing generated apiKey fields changes documented merge-mode and marker-persistence behavior that existing installs may rely on.
  • merge-risk: 🚨 auth-provider: The diff changes persisted provider credential material that runtime auth resolution still treats as a valid custom-provider auth source.
  • merge-risk: 🚨 security-boundary: The PR changes a credentials boundary and must prove all generated catalog outputs are covered without leaving or misrouting sensitive auth material.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body lists validation commands only; it needs redacted terminal output, generated-file contents, logs, or a linked artifact from a real setup showing sanitized output and continued auth/model discovery. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +20, Tests +84. Total +104 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 21 1 +20
Tests 3 99 15 +84
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 120 16 +104

Security concerns:

  • [medium] Credential redaction lacks upgrade policy — src/agents/models-config.plan.ts:120
    Blanket removal of apiKey after preserved credentials and source markers have been merged can turn a secret-hardening patch into an auth break for upgraded custom-provider installs.
    Confidence: 0.9

What I checked:

  • PR diff deletes every provider apiKey before serialization: The proposed helper removes any own apiKey property from provider rows without distinguishing plaintext secrets, env/SecretRef markers, OAuth/local markers, or models.json-only credentials. (src/agents/models-config.plan.ts:120, 371e7f8ced1e)
  • Current main filters writable custom model providers by apiKey: Current main requires providers with model rows to have both baseUrl and apiKey before writing them, so blanket removal conflicts with current catalog validity rules. (src/agents/models-config.plan.ts:180, 640258d7b31d)
  • Current main writes root and plugin-owned generated catalogs: Current main splits provider writes into root models.json and generated plugin catalog sidecars, so a current fix must account for both output classes after rebase. (src/agents/models-config.plan.ts:283, 640258d7b31d)
  • Merge-mode apiKey preservation is an existing contract: Current merge logic preserves existing non-empty apiKey values for non-SecretRef-managed providers, while docs describe the same precedence behavior. (src/agents/models-config.merge.ts:190, 640258d7b31d)
  • Model registry still requires apiKey for most custom model rows: Current registry validation rejects custom provider model rows without apiKey unless an explicit missing-key auth mode is configured, and request auth still falls back to provider apiKey. (src/agents/sessions/model-registry.ts:496, 640258d7b31d)
  • Public docs describe marker and merge behavior: The docs state that non-empty existing apiKey wins in merge mode when not SecretRef-managed, and SecretRef-managed provider keys are refreshed as non-secret markers. Public docs: docs/concepts/models.md. (docs/concepts/models.md:351, 640258d7b31d)

Likely related people:

  • steipete: Path history shows large model-config/runtime refactors, including plugin catalog movement and the agent runtime internalization that defines the current merge target. (role: model-config and agent runtime refactor contributor; confidence: high; commits: 51b5f75b92f7, bb46b79d3c14; files: src/agents/models-config.plan.ts, src/agents/sessions/model-registry.ts)
  • vincentkoc: Recent path history shows provider config helper export cleanup and marker-regression stabilization near this auth/model-config surface. (role: recent area contributor; confidence: medium; commits: e93996378491, 64f9f3c278db; files: src/agents/models-config.plan.ts, src/agents/model-auth-markers.ts)
  • yetval: Recent planner history includes a blank-provider-baseUrl fix in the same generated models-config planning path. (role: adjacent bugfix contributor; confidence: medium; commits: 98e239d01201; files: 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

🎁 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: 🧂 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 19, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jun 24, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 24, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for tackling the generated credential exposure. We’re consolidating this cluster under #88562 and the maintainer-owned direction in #87166.

This branch removes every provider apiKey at the serialization boundary. Current model discovery requires ordinary custom model rows to retain an auth marker, and the planner filters model-bearing providers without one, so this approach can make configured models disappear. It also predates the separate plugin catalog sidecar writer.

Closing this incorrect competing implementation. The underlying security issue remains open; the current-main fix needs a non-secret marker with explicit runtime-auth semantics and coverage for both root and plugin-owned generated catalogs. Thank you for the contribution.

@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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security Roadmap: Protecting API Keys from Agent Access

3 participants