Skip to content

Strip apiKey fields from generated models.json - #84465

Closed
javi-codeworks wants to merge 1 commit into
openclaw:mainfrom
javi-codeworks:codex/fix-models-json-api-key
Closed

javi-codeworks wants to merge 1 commit into
openclaw:mainfrom
javi-codeworks:codex/fix-models-json-api-key

Conversation

@javi-codeworks

@javi-codeworks javi-codeworks commented May 20, 2026 •

Copy link
Copy Markdown

Summary

  • Problem: generated models.json could persist apiKey fields from provider config rows.
  • Solution: strip apiKey recursively from the final models.json write payload.
  • What changed: provider/model metadata still writes, but provider-level and nested apiKey fields are omitted; tests now assert this contract.
  • What did NOT change (scope boundary): runtime auth resolution and provider discovery credential lookup remain outside the generated file.

Motivation

  • Prevent model config auth material from being persisted in a file that agent/runtime readers may inspect.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: generated models.json no longer includes provider-level or nested apiKey fields that could be exposed to agent/runtime readers.
  • Real environment tested: local Windows checkout using Node v24.14.0 from the Codex bundled runtime because the system Node v22.15.0 is below the repo requirement.
  • Exact steps or command run after this patch: ran the real ensureOpenClawModelsJson path against a temporary OpenClaw agent dir with a configured provider containing fake provider-level and model-level apiKey values, then read the generated models.json.
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output): copied live terminal output:
models_path=C:\Users\CAMILO\Documents\Codex\2026-05-20\you-are-my-autonomous-public-work\openclaw\.artifacts\proof-agent\models.json
provider_present=true
provider_apiKey_present=false
model_apiKey_present=false
secret_string_present=false
model_secret_string_present=false
model_id=proof-model
  • Observed result after fix: provider rows, base URLs, headers, and model metadata still write normally, while apiKey is omitted from models.json.
  • What was not tested: full repository test suite and live end-to-end agent prompt inspection.
  • Before evidence (optional but encouraged): not captured for this generated-file security hardening path; after-fix copied live output above shows the generated file no longer contains provider or model apiKey fields.

Root Cause (if applicable)

  • Root cause: planOpenClawModelsJsonWithDeps serialized the fully merged provider config directly, including auth fields that were needed for discovery/runtime setup but not safe to persist in models.json.
  • Missing detection / guardrail: tests asserted auth markers were persisted instead of asserting generated-file redaction.
  • Contributing context (if known): the existing pipeline already normalized several secret references, but final write serialization had no dedicated apiKey removal step.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: 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
  • Scenario the test should lock in: generated models.json keeps provider/model metadata but omits provider-level and nested apiKey fields.
  • Why this is the smallest reliable guardrail: it exercises the write-plan output directly and existing generated-file cases that previously expected auth markers.
  • Existing test that already covers this (if any): N/A.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

Generated models.json no longer contains apiKey properties.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? Yes, apiKey fields are stripped from generated models.json.
  • New/changed network calls? No

Verification

  • C:\Users\CAMILO\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe scripts\run-vitest.mjs 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 --run
  • node_modules\.bin\oxfmt.CMD --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
  • OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree C:\Users\CAMILO\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe scripts\run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
  • OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree C:\Users\CAMILO\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe scripts\run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo
  • git diff --check

@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, 4:17 PM ET / 20:17 UTC.

Summary
The PR adds recursive apiKey stripping before generated models.json serialization and updates model-config tests to expect provider and nested model apiKey fields to be absent.

PR surface: Source +26, Tests +40. Total +66 across 4 files.

Reproducibility: yes. Source inspection shows current generated catalogs serialize provider records after marker preservation, while this PR removes every apiKey at serialization, including documented markers and merge-mode credentials.

Review metrics: 2 noteworthy metrics.

  • Credential field handling: 1 field name recursively removed. The diff removes every generated apiKey key, including non-secret markers and existing merge-mode credentials.
  • Generated catalog outputs: 2 output classes on current main. Current main writes both root models.json and plugin-owned generated catalog shards, so a security fix must cover both before merge.

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 implementation candidate for the open Layer 1 models.json API-key exposure work, with several competing open PRs proposing different auth-marker 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 or rebuild on current main and cover both root models.json and plugin-owned catalog writes.
  • Replace blanket apiKey deletion with provenance-aware redaction that preserves non-secret markers or migrates credentials intentionally.

Risk before merge

  • [P1] The patch conflicts with current documented merge precedence and custom catalog validation unless maintainers intentionally choose a breaking credential-policy change.
  • [P1] Several open same-root-cause PRs propose different marker, migration, and sidecar coverage policies, so landing this branch would preempt an unresolved security/product decision.

Maintainer options:

  1. Rebase With Marker-Aware Redaction (recommended)
    Rework on current main so plaintext secrets are removed from both root and plugin catalog outputs while supported markers and upgrade credentials are preserved or explicitly migrated.
  2. Adopt A Breaking Auth Policy
    Maintainers could intentionally retire generated models.json credentials, but the PR should document the operator action and prove fresh-install plus upgrade recovery paths before merge.
  3. Fold Into One Canonical Branch
    If another same-topic branch becomes the chosen implementation, preserve this PR's useful redaction test intent there and close this branch only after the replacement is viable or merged.

Next step before merge

  • [P2] The remaining blocker is a maintainer security/product decision across competing Layer 1 policies, not a narrow safe automation repair for this stale branch.

Security
Needs attention: The diff is security-positive in intent but changes credential persistence and auth semantics in a way that needs maintainer resolution before merge.

Review findings

  • [P1] Preserve supported auth markers when redacting apiKeys — src/agents/models-config.plan.ts:203-204
Review details

Best possible solution:

Land one maintainer-selected Layer 1 fix that removes plaintext secrets from root and plugin generated catalogs while preserving or migrating supported auth markers and models.json-only credentials.

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

Yes. Source inspection shows current generated catalogs serialize provider records after marker preservation, while this PR removes every apiKey at serialization, including documented markers and merge-mode credentials.

Is this the best way to solve the issue?

No. Serialization-boundary redaction is the right layer, but this implementation is too broad and misses current plugin-owned catalog sidecar behavior.

Full review comments:

  • [P1] Preserve supported auth markers when redacting apiKeys — src/agents/models-config.plan.ts:203-204
    This sanitizer runs after source-managed markers and merge-mode credentials have been preserved. Current docs, tests, and registry validation still treat generated provider apiKey values as valid markers or custom-provider auth, so deleting every apiKey can make generated providers fail or lose credentials on regeneration; preserve known non-secret markers and migrate or preserve models.json-only credentials instead.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.9

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 can also break real provider auth paths during upgrade.
  • merge-risk: 🚨 compatibility: The diff changes generated catalog credential fields that current docs, tests, and merge-mode behavior intentionally keep.
  • merge-risk: 🚨 auth-provider: Generated provider apiKey values still participate in provider auth and custom catalog availability decisions.
  • merge-risk: 🚨 security-boundary: The PR changes credential persistence in prompt-visible catalog files and must avoid leaving root/plugin or upgrade paths inconsistent.
  • 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 (live_output): The PR body includes copied live terminal output from an after-fix generated models.json path showing fake provider and model apiKey values absent.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied live terminal output from an after-fix generated models.json path showing fake provider and model apiKey values absent.
Evidence reviewed

PR surface:

Source +26, Tests +40. Total +66 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 27 1 +26
Tests 3 54 14 +40
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 81 15 +66

Security concerns:

  • [medium] Blanket redaction erases auth markers — src/agents/models-config.plan.ts:203
    Removing every apiKey after marker preservation can turn secret hardening into an auth break for existing custom-provider or marker-backed setups.
    Confidence: 0.9

What I checked:

Likely related people:

  • joshavant: Commit history shows this person authored the source-managed SecretRef marker persistence behavior that this PR would remove from generated output. (role: introduced marker behavior; confidence: high; commits: 0bcb95e8fa5e; files: src/agents/models-config.plan.ts, src/agents/models-config.providers.ts, src/agents/models-config.runtime-source-snapshot.test.ts)
  • steipete: Commit history shows this person split the models-config merge and source-managed helpers that define the current auth preservation boundary. (role: area refactor owner; confidence: high; commits: 75e15216600b, 5c52824d3efe; files: src/agents/models-config.merge.ts, src/agents/models-config.providers.source-managed.ts)
  • eleqtrizit: Current-line blame for the central model-config and registry files points to this recent broad commit, so they are relevant for the current-main shape even if not the original feature author. (role: recent broad current-main contributor; confidence: medium; commits: 6ead09230284; files: src/agents/models-config.plan.ts, src/agents/models-config.merge.ts, src/agents/models-config.providers.source-managed.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: 🧂 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. 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 the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jun 19, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jun 19, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jun 20, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for addressing the generated-catalog exposure. We’re consolidating this security work in maintainer-owned #87166. This branch’s recursive removal also strips supported non-secret auth markers, can make custom-provider model rows fail current catalog validation, and predates the root plus plugin-owned catalog split now on main. Closing as a superseded competing implementation; #11829 and #87166 remain open for the canonical auth and upgrade policy.

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

Security Roadmap: Protecting API Keys from Agent Access

3 participants