Skip to content

fix(models): avoid persisting prompt-visible provider secrets - #83592

Closed
1507819106zxzx-crypto wants to merge 4 commits into
openclaw:mainfrom
1507819106zxzx-crypto:security/model-auth-persistence-headers
Closed

1507819106zxzx-crypto wants to merge 4 commits into
openclaw:mainfrom
1507819106zxzx-crypto:security/model-auth-persistence-headers

Conversation

@1507819106zxzx-crypto

@1507819106zxzx-crypto 1507819106zxzx-crypto commented May 18, 2026 •

Copy link
Copy Markdown

Summary

  • stop newly generated plaintext provider apiKey values from being written to models.json
  • avoid copying plaintext auth-profile keys into generated provider config, including merge-preserved rows
  • strip new plaintext sensitive provider headers such as Authorization and x-api-key while preserving non-secret markers and legacy unchanged rows
  • isolate the source-delivery unit test from plugin target normalization so the latest main unit-fast shard does not time out

Real behavior proof

Behavior or issue addressed: Provider credentials that are needed for runtime auth should not be duplicated into the prompt-visible models.json catalog when they are new plaintext apiKey values or sensitive header values.

Real environment tested: Local OpenClaw checkout on Windows 11, Node v24.13.0, pnpm 11.1.0, running the patched source through tsx against a real config-shaped provider entry.

Exact steps or command run after this patch: Ran a tsx script that calls the patched models.json planner with a custom provider containing plaintext apiKey, Authorization, and X-Api-Key values plus an OpenAI provider using non-secret markers.

Evidence after fix: Copied terminal output from that local run:

$ pnpm exec tsx -
{
  "action": "write",
  "customApiKeyPersisted": false,
  "customHeaders": {
    "X-Tenant": "tenant-a"
  },
  "openaiApiKey": "OPENAI_API_KEY",
  "openaiAuthorizationHeader": "secretref-env:OPENAI_PROXY_TOKEN"
}

Observed result after fix: The new plaintext provider apiKey was absent, the plaintext Authorization and X-Api-Key headers were removed, the safe X-Tenant header remained, and the non-secret env/SecretRef markers were preserved.

What was not tested: Full live provider request execution was not re-run; this PR only proves the persisted models.json planning path.

Validation

  • corepack pnpm exec vitest run --config test/vitest/vitest.gateway-methods.config.ts src/gateway/server-methods/config.shared-auth.test.ts
  • corepack pnpm exec vitest run --config test/vitest/vitest.agents.config.ts src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.providers.normalize-keys.test.ts src/agents/models-config.merge.test.ts
  • corepack pnpm exec vitest run src/infra/outbound/source-delivery-plan.test.ts
  • corepack pnpm exec 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.applies-config-env-vars.test.ts src/agents/models-config.providers.normalize-keys.test.ts
  • corepack pnpm exec oxlint src/infra/outbound/source-delivery-plan.test.ts
  • git diff --check

Refs #11829 (Layer 1 only; does not close the broader security roadmap).

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 18, 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 strips plaintext provider apiKey values, plaintext auth-profile keys, and sensitive provider headers from generated models.json planning, with focused regression tests and mock updates.

PR surface: Source +194, Tests +192. Total +386 across 7 files.

Reproducibility: yes. Source inspection shows current main writes root and plugin-owned generated model catalogs, and the PR body supplies after-fix terminal output for the planner path that strips plaintext apiKey and sensitive headers.

Review metrics: 2 noteworthy metrics.

  • Prompt-visible auth surfaces: 3 changed: provider apiKey, auth-profile apiKey, sensitive provider headers. These persistence surfaces are security-sensitive and must be redacted without breaking provider loadability or auth routing.
  • Generated catalog output classes: 2 current outputs: root models.json and plugin-owned catalog sidecars. Current main persists both output classes, so a complete 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.providers.normalize-keys.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #11829
Summary: This PR is one candidate Layer 1 fix for the open API-key exposure roadmap, with several overlapping PRs covering different slices of generated model catalog credential redaction.

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 replace the branch on current main so redaction covers both root models.json and plugin-owned generated catalogs.
  • [P2] Preserve or prove a safe non-secret runtime-auth path for redacted custom provider rows.

Risk before merge

  • [P1] A root-only sanitizer would leave current main's plugin-owned generated catalog sidecars able to persist provider auth material.
  • [P1] Deleting apiKey from model-bearing custom provider rows can make generated catalogs fail ModelRegistry validation unless a non-secret marker or auth mode is preserved and proven.
  • [P1] The branch is currently conflicting/dirty against main, so conflict resolution must deliberately carry the fix onto the current root/plugin catalog writer split.
  • [P1] Several open Layer 1 security PRs overlap this surface, including a maintainer-authored branch, so maintainers need to choose the canonical auth/catalog contract before landing.

Maintainer options:

  1. Rebase Onto Current Catalog Writers (recommended)
    Update or replace the branch so redaction is applied before both root models.json and plugin-owned generated catalog writes, with focused proof for each output.
  2. Preserve Loadable Runtime Auth
    Keep a non-secret marker or explicit auth mode that current model loading accepts, and prove custom provider rows still load after redaction.
  3. Fold Into The Maintainer Layer 1 Path
    If maintainers choose the overlapping maintainer branch, carry this PR's auth-profile and sensitive-header coverage into that path before closing duplicate attempts.

Next step before merge

  • [P2] Manual maintainer handling is needed because the branch is conflicting and overlaps other Layer 1 branches, and the remaining blocker is the canonical security/auth catalog contract rather than a narrow automated repair.

Security
Needs attention: The diff targets a real credential-exposure boundary, but stale current-main coverage and auth/loadability gaps remain security-relevant blockers.

Review findings

  • [P1] Preserve loadable auth for redacted custom providers — src/agents/models-config.plan.ts:209
  • [P1] Sanitize plugin catalog sidecars too — src/agents/models-config.plan.ts:343
Review details

Best possible solution:

Land one maintainer-selected Layer 1 implementation that sanitizes both root and plugin-owned generated catalogs while preserving a non-secret runtime-auth/loadability contract for custom providers.

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

Yes. Source inspection shows current main writes root and plugin-owned generated model catalogs, and the PR body supplies after-fix terminal output for the planner path that strips plaintext apiKey and sensitive headers.

Is this the best way to solve the issue?

No. The direction is useful, but this branch is stale against the current catalog writer split and must preserve or prove a safe runtime-auth path before it is the best fix.

Full review comments:

  • [P1] Preserve loadable auth for redacted custom providers — src/agents/models-config.plan.ts:209
    This deletes apiKey from generated provider rows that can still contain models. Current main rejects model-bearing providers unless apiKey is present or auth explicitly allows missing provider keys, so the redaction needs a non-secret marker or equivalent loadable auth contract before merge.
    Confidence: 0.88
  • [P1] Sanitize plugin catalog sidecars too — src/agents/models-config.plan.ts:343
    This branch only serializes the older single root models.json payload. Current main also writes plugin-owned generated catalog sidecars from the same provider set, so a root-only conflict resolution would leave another prompt-visible catalog output able to persist provider secrets.
    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 0c7bac34ae68.

Label changes

Label justifications:

  • P1: The PR targets prompt-visible provider credential exposure and can affect real provider auth behavior.
  • merge-risk: 🚨 compatibility: Removing or changing persisted apiKey values can break existing custom provider catalog rows and upgrades unless a loadable replacement contract is proven.
  • merge-risk: 🚨 auth-provider: The diff changes provider credential persistence, auth-profile key handling, and model provider auth behavior.
  • merge-risk: 🚨 security-boundary: Incomplete generated-catalog coverage would leave a credential persistence path in a security-sensitive surface.
  • 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 after-fix terminal output from a local planner run showing plaintext apiKey and sensitive headers stripped while safe markers are preserved; it does not prove the unresolved sidecar/auth blockers.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied after-fix terminal output from a local planner run showing plaintext apiKey and sensitive headers stripped while safe markers are preserved; it does not prove the unresolved sidecar/auth blockers.
Evidence reviewed

PR surface:

Source +194, Tests +192. Total +386 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 200 6 +194
Tests 4 192 0 +192
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 392 6 +386

Security concerns:

  • [high] Generated plugin catalogs can remain unsanitized — src/agents/models-config.plan.ts:343
    Current main writes plugin-owned generated catalog sidecars separately from root models.json, so a root-only sanitizer can leave plaintext provider keys in another generated catalog file.
    Confidence: 0.9
  • [high] Redaction can remove the only loadable auth field — src/agents/models-config.plan.ts:209
    Deleting provider apiKey without preserving a non-secret marker or explicit runtime-auth mode can make custom model rows fail validation after generation.
    Confidence: 0.88

What I checked:

  • Repository policy applied: Root policy was read fully; auth/provider config, persisted preferences, fallback behavior, and security boundaries are treated as compatibility-sensitive review surfaces. (AGENTS.md:20, 0c7bac34ae68)
  • Scoped agents guide applied: The scoped agents guide was read; this PR touches agent model config and test performance paths. (src/agents/AGENTS.md:1, 0c7bac34ae68)
  • PR removes provider apiKey before persistence: The PR head deletes non-marker provider apiKey fields before serializing generated model config. (src/agents/models-config.plan.ts:209, f879e1365952)
  • PR serializes only the older root catalog shape: The PR head writes a single root { providers } payload and has no pluginCatalogWrites handling. (src/agents/models-config.plan.ts:343, f879e1365952)
  • Current main has plugin-owned catalog sidecars: Current main splits providers into rootProviders and pluginProviders, then builds pluginCatalogWrites separately from root models.json. (src/agents/models-config.plan.ts:283, 0c7bac34ae68)
  • Current main persists plugin catalog writes: ensureOpenClawModelsJson writes plan.pluginCatalogWrites after the root models.json write, making sidecars part of the generated persistence surface. (src/agents/models-config.ts:452, 0c7bac34ae68)

Likely related people:

  • steipete: Recent history includes moving plugin model catalogs into plugin state and opening the overlapping maintainer Layer 1 branch for the same generated models.json secret work. (role: feature-history owner and adjacent branch author; confidence: high; commits: 51b5f75b92f7, b78ebacb18fe, a088aa693d76; files: src/agents/models-config.plan.ts, src/agents/models-config.ts, src/agents/sessions/model-registry.ts)
  • vincentkoc: Recent commits touched provider config helper exports and model auth marker regression coverage in the same model config/auth marker path. (role: recent area contributor; confidence: medium; commits: e93996378491, 64f9f3c278db, a44a3f9171eb; files: src/agents/models-config.plan.ts, src/agents/models-config.providers.secret-helpers.ts, src/agents/model-auth-markers.ts)
  • shakkernerd: Recent model provider discovery and plugin metadata changes overlap the current-main catalog writer and marker paths this branch must rebase onto. (role: recent adjacent contributor; confidence: medium; commits: 4ceae8262f86, 4e7de4b5c9ed, 1a193b2d9666; files: src/agents/models-config.plan.ts, src/agents/model-auth-markers.ts)
  • joshavant: Earlier SecretRef hardening work introduced related provider secret persistence and marker behavior that this PR must preserve. (role: earlier secret-hardening contributor; confidence: medium; commits: 36d2ae2a2235; files: src/agents/model-auth-markers.ts, src/agents/models-config.providers.secret-helpers.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 18, 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels May 18, 2026
@1507819106zxzx-crypto
1507819106zxzx-crypto force-pushed the security/model-auth-persistence-headers branch from 453bb51 to c963d1f Compare May 18, 2026 12:54
@1507819106zxzx-crypto
1507819106zxzx-crypto requested a review from a team as a code owner May 18, 2026 12:54
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels May 18, 2026
@1507819106zxzx-crypto
1507819106zxzx-crypto force-pushed the security/model-auth-persistence-headers branch from c963d1f to f0948f5 Compare May 18, 2026 12:57
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. proof: supplied External PR includes structured after-fix real behavior proof. and removed gateway Gateway runtime proof: supplied External PR includes structured after-fix real behavior proof. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 18, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@1507819106zxzx-crypto

Copy link
Copy Markdown
Author

Updated per review:

  • aligned persisted provider header stripping with the audit-classified sensitive header set, including token/secret/password/credential fragments
  • added regression coverage for X-Auth-Token and X-Secret-Key stripping while preserving unchanged legacy headers

Validation:

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents.config.ts src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.providers.normalize-keys.test.ts src/agents/models-config.merge.test.ts
  • corepack pnpm exec oxlint src/agents/models-config.plan.ts src/agents/models-config.applies-config-env-vars.test.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 25, 2026
@1507819106zxzx-crypto

Copy link
Copy Markdown
Author

Follow-up for the new doctor shard failure after CI reran:\n\n- updated the doctor migration test plugin registry mock to include the current diagnostics field\n\nAdditional validation:\n- node scripts/run-vitest.mjs run --config test/vitest/vitest.commands.config.ts src/commands/doctor-legacy-config.migrations.test.ts\n- node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-core.config.ts src/agents/models-config.runtime-source-snapshot.test.ts src/agents/models-config.applies-config-env-vars.test.ts src/agents/models-config.providers.normalize-keys.test.ts src/agents/models-config.merge.test.ts\n- node_modules\.bin\oxlint.CMD src/agents/models-config.plan.ts src/agents/models-config.runtime-source-snapshot.test.ts src/commands/doctor-legacy-config.migrations.test.ts\n- git diff --check

@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label May 25, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels May 25, 2026
@1507819106zxzx-crypto

Copy link
Copy Markdown
Author

All latest head checks are green after the follow-up fixes on f879e13. The branch now includes the provider-runtime mock export, source-managed env apiKey marker preservation, and the doctor registry diagnostics mock update.\n\nLatest validation already posted above:\n- doctor migration shard: 49 passed\n- models config shard: 38 passed\n- oxlint: 0 warnings/errors\n- git diff --check: clean\n\n@clawsweeper re-review

@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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 25, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 14, 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 18, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 16, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations 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: M stale Marked as stale due to inactivity 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