Skip to content

fix(doctor): stop scaffolding empty safeBinProfiles that override built-in defaults - #95385

Closed
BKF-Gitty wants to merge 1 commit into
openclaw:mainfrom
BKF-Gitty:fix/doctor-safe-bin-profiles-builtin-defaults
Closed

BKF-Gitty wants to merge 1 commit into
openclaw:mainfrom
BKF-Gitty:fix/doctor-safe-bin-profiles-builtin-defaults

Conversation

@BKF-Gitty

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where openclaw doctor --fix silently weakened exec safe-bin security for anyone who added a built-in stdin-only helper (cut, uniq, head, tail, tr, wc, grep, sort, jq) to tools.exec.safeBins. Doctor scaffolded an empty {} profile for these bins, and because resolveSafeBinProfiles merges user profiles over the built-ins by key (not a deep merge), the empty {} wiped the built-in maxPositional, allowedValueFlags, and deniedFlags. The result was the worst of both worlds: the safe stdin-only form was rejected (e.g. grep -e "pattern") while unsafe forms were allowed (e.g. grep pattern file.txt, grep -r /). The same empty-override hazard also lived in already-saved configs and was never repaired.

Why This Change Was Made

doctor now distinguishes built-in bins from custom bins:

  • Built-in bins are never scaffolded — their profile already applies at runtime. Plain doctor shows an informational note ("uses built-in profile (no custom override needed)") instead of a warning, and they are dropped from the --fix scaffold suggestion.
  • Custom bins scaffold { maxPositional: 0 } (a stdin-only default) instead of {}, matching the documented purpose of safeBins.
  • The safeBinProfiles holder is created lazily, so doctor no longer leaves an empty {} object behind when nothing is scaffolded.
  • An empty {} override of a built-in is flagged by plain doctor and removed by doctor --fix to restore the shipped profile. Detection is inheritance/fallback aware: it covers global scope, per-agent scope, agents that inherit the global safeBins list, and configs relying on the default safeBins set with no explicit safeBins key.

No config-shape, schema, or API change; no migration required (the runtime already reads the canonical shape — this only stops doctor from writing a harmful one and repairs existing harmful ones).

User Impact

  • Adding a built-in helper to safeBins keeps its built-in protections: the safe -e/stdin form works and unsafe file/recursive forms stay blocked.
  • doctor --fix self-heals existing broken configs that contain an empty {} override of a built-in.
  • Custom safeBins get a conservative stdin-only default scaffold instead of an unconstrained {}.

Evidence

Tests (new + updated):

  • src/commands/doctor/shared/exec-safe-bins.test.ts: built-in info note + no scaffold; custom { maxPositional: 0 } scaffold; empty-override warn + --fix removal; explicit non-empty override preserved; global-safeBins-fallback (agent with no own safeBins) removal; default-safeBins (no safeBins key) detection; and a regression asserting resolveSafeBinProfiles returns the intact built-in grep profile after --fix.
  • src/commands/doctor/shared/preview-warnings.test.ts: plain doctor warns about an empty built-in override even with no explicit safeBins.

Local validation (macOS):

  • ~298 tests green across exec-safe-bins, preview-warnings, doctor-config-flow, repair-sequencing, security audit, exec-safe-bin policy/runtime, and agent-tools safe-bins.
  • pnpm tsgo:core clean; pnpm tsgo:core:test clean for changed files (one unrelated pre-existing packages/sdk/src/package.e2e.test.ts error already on main).
  • oxfmt --check and oxlint clean on all changed files.

Review: the fix plan and the implementation were independently reviewed by Codex across three passes; all findings (inheritance/fallback detection gaps, message wording, and the plain-doctor preview gate for default-active safeBins) were addressed and confirmed resolved.

Notes: branched off latest main; independent of (and non-overlapping with) the other open PR on this fork.

…lt-in defaults

doctor --fix scaffolded empty {} entries for safeBins that already ship a
built-in profile (cut, uniq, head, tail, tr, wc, grep, sort, jq). Because
resolveSafeBinProfiles merges user fixtures over the built-ins by key, an
empty {} wiped the built-in maxPositional/allowedValueFlags/deniedFlags,
both blocking safe stdin-only usage and allowing unsafe file/recursive usage.

Now built-in bins are never scaffolded (plain doctor shows an info note),
custom bins scaffold { maxPositional: 0 } (stdin-only) instead of {}, the
safeBinProfiles holder is created lazily, and an empty {} override of a
built-in is warned in plain doctor and removed by doctor --fix across
global, agent, and inherited/default-safeBins scopes to restore the
shipped profile.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations size: M labels Jun 20, 2026
@clawsweeper

clawsweeper Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the contribution. I reviewed the branch, and this PR is not a good landing base for OpenClaw.

Close this stale PR: the latest review rated it F, it still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this PR rather than keeping an unmergeable branch open. A new narrow PR that carries only the useful part is welcome.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Yes, from source: an empty user fixture overwrites a shipped profile in resolveSafeBinProfiles, and the PR's new collector skips an equivalent empty override beneath agents.entries because it reads only agents.list. A focused regression should establish the failing Doctor repair before merge.

Is this the best way to solve the issue?

No, not as submitted. The central repair is appropriate, but it must be rebased onto the shared current roster abstraction and preserve the merged jq fail-closed policy rather than reviving legacy list-only behavior.

Security review:

Security review needs attention: The patch changes an execution-approval security boundary and currently fails to repair unsafe empty overrides in canonical keyed-agent configuration.

  • [high] Keyed agent safe-bin overrides are skipped — src/commands/doctor/shared/exec-safe-bins.ts:180
    The new repair and warning collector reads only the legacy agent list, so a current keyed-agent configuration can retain an empty override that removes built-in safe-bin restrictions.
    Confidence: 0.99

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-06-20T17:58:57Z, is older than 30 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • wangyan2026: Introduced the current agent-roster helper and moved Doctor safe-bin handling onto it, including the source-aware agents.entries path this branch must preserve. (role: recent area contributor; confidence: high; commits: 70394e190cf1; files: src/agents/agent-scope-config.ts, src/commands/doctor/shared/exec-safe-bins.ts)
  • pgondhi987: Authored the merged jq semantic hardening that establishes the current fail-closed contract the rebased repair and docs must retain. (role: safe-bin security contributor; confidence: high; commits: 5f04dc97e637; files: src/infra/exec-safe-bin-semantics.ts, src/commands/doctor/shared/exec-safe-bins.ts)
  • Vincent Koc: Recent safe-bin normalization refactoring is directly adjacent to the config-normalization boundary used by Doctor and runtime profile resolution. (role: adjacent normalization contributor; confidence: medium; commits: 7b313e4cc1e0; files: src/infra/exec-safe-bin-config.ts, src/infra/exec-safe-bin-runtime-policy.ts)

Codex review notes: model internal, reasoning high; reviewed against 807506381a03.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 20, 2026
@clawsweeper

clawsweeper Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

@BKF-Gitty thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward.

Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive.

Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it.

@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 27, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jul 30, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jul 31, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation 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: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant