Skip to content

Fix inherited XDG env for exec subprocesses#85139

Merged
joshavant merged 2 commits into
mainfrom
fix/xdg-host-env-inheritance
May 22, 2026
Merged

Fix inherited XDG env for exec subprocesses#85139
joshavant merged 2 commits into
mainfrom
fix/xdg-host-env-inheritance

Conversation

@joshavant

Copy link
Copy Markdown
Contributor

Summary

  • Preserve trusted inherited XDG base-directory environment variables for host exec subprocesses.
  • Keep those same XDG variables blocked as agent-supplied/request-scoped overrides.
  • Regenerate the macOS host env policy mirror and extend sanitizer/baseline coverage.

Fixes #84854.

Verification

  • node scripts/run-vitest.mjs src/infra/host-env-security.test.ts src/infra/host-env-security.policy-parity.test.ts src/infra/host-env-security.reported-baseline.test.ts
  • node scripts/generate-host-env-security-policy-swift.mjs --check
  • AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode auto
  • AWS Crabbox fix proof: provider aws, lease cbx_f1bec67ac152, run run_c8171b0694bf

Behavior addressed: inherited XDG_CONFIG_HOME, XDG_CONFIG_DIRS, and other XDG base-directory variables were stripped from host exec subprocess environments even when they came from the trusted OpenClaw process environment.
Real environment tested: AWS Crabbox Linux direct provider (cbx_f1bec67ac152) with a live openclaw agent --local turn using OpenAI API auth and the real exec tool path.
Exact steps or command run after this patch: ran a Crabbox script that set inherited XDG_CONFIG_HOME, XDG_CONFIG_DIRS, and XDG_DATA_HOME, configured an isolated PI/OpenAI agent, asked the live agent to invoke exec once, and asserted the subprocess output contained the exact inherited values.
Evidence after fix: ASSERTION_PASSED issue-84854 XDG inheritance preserved through live agent exec in Crabbox run run_c8171b0694bf.
Observed result after fix: the exec subprocess printed the configured inherited XDG values instead of <unset>.
What was not tested: full repository test suite; Telegram/Discord channel delivery was not needed for this exec environment inheritance bug.

@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos size: S maintainer Maintainer-authored PR labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Workflow note: Future ClawSweeper reviews update this same comment in place.

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.

Summary
This PR updates host exec environment policy to preserve inherited XDG base-directory variables, reject request-scoped XDG overrides, regenerate the macOS policy mirror, extend sanitizer/baseline tests, and add a changelog entry.

Reproducibility: yes. at source level: current main derives XDG_CONFIG_HOME and XDG_CONFIG_DIRS into blockedInheritedKeys, and the host exec path passes process.env through that sanitizer before spawning subprocesses. The PR body also reports a live AWS Crabbox agent exec proof showing the XDG values after the patch.

PR rating
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Summary: Small focused patch with strong live proof, capped by a host exec security and compatibility boundary that needs maintainer approval.

Rank-up moves:

  • Get explicit maintainer/security approval for trusting inherited XDG variables and blocking all request-scoped XDG overrides before merge.
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.

Real behavior proof
Sufficient (live_output): The PR body includes after-fix live AWS Crabbox proof of a real openclaw agent --local exec subprocess receiving inherited XDG values, with the passing assertion and run id recorded.

Risk before merge

  • Merging changes the host exec security boundary: inherited XDG roots become trusted when they come from the OpenClaw process environment, while request-scoped XDG overrides are rejected.
  • The PR also blocks request-scoped overrides for XDG variables that were previously not all blocked, so any existing workflow relying on per-call XDG_DATA_HOME, XDG_CACHE_HOME, XDG_RUNTIME_DIR, or XDG_STATE_HOME overrides would fail closed after upgrade.
  • The protected maintainer label requires explicit maintainer handling even though the code diff looks narrow and well tested.

Maintainer options:

  1. Merge after explicit security approval (recommended)
    A maintainer can land this as-is if they accept parent-process XDG variables as trusted and accept fail-closed behavior for request-scoped XDG overrides.
  2. Narrow the override behavior first
    If request-scoped non-config XDG overrides are a supported compatibility path, keep the inherited allowlist fix but adjust the new override block additions with tests and a documented migration story.
  3. Pause for policy ownership
    If the host exec environment trust model is not settled, pause this PR until the env sanitizer owners decide the permanent XDG inheritance and override contract.

Next step before merge
Needs maintainer/security review for the host exec environment policy and compatibility impact; there is no narrow ClawSweeper repair finding to queue.

Security
Needs attention: The diff is security-sensitive because it changes host exec environment trust semantics, but I did not find a concrete supply-chain or code-execution regression beyond the maintainer policy decision.

Review details

Best possible solution:

Land the policy, generated mirror, baseline, and regression tests once a maintainer explicitly accepts the trusted-parent-env boundary and the override hardening compatibility impact.

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

Yes, at source level: current main derives XDG_CONFIG_HOME and XDG_CONFIG_DIRS into blockedInheritedKeys, and the host exec path passes process.env through that sanitizer before spawning subprocesses. The PR body also reports a live AWS Crabbox agent exec proof showing the XDG values after the patch.

Is this the best way to solve the issue?

Yes, with maintainer approval: the PR changes the shared policy buckets instead of adding a bypass, keeps request overrides blocked, regenerates the macOS mirror, and adds focused regression coverage. The remaining question is policy ownership of the compatibility/security boundary, not a code-shape defect.

Label changes:

  • add P1: The PR fixes a deterministic host exec bug that can break persisted tool config and OAuth state for real containerized deployments.
  • add merge-risk: 🚨 compatibility: The diff rejects additional request-scoped XDG overrides, which can intentionally break existing per-call env override workflows after upgrade.
  • add merge-risk: 🚨 security-boundary: The diff changes which host exec environment variables are trusted from inherited process state versus rejected from untrusted request overrides.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix live AWS Crabbox proof of a real openclaw agent --local exec subprocess receiving inherited XDG values, with the passing assertion and run id recorded.
  • add rating: 🐚 platinum hermit: Current PR rating is 🐚 platinum hermit because proof is 🦞 diamond lobster, patch quality is 🐚 platinum hermit, and Small focused patch with strong live proof, capped by a host exec security and compatibility boundary that needs maintainer approval.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes after-fix live AWS Crabbox proof of a real openclaw agent --local exec subprocess receiving inherited XDG values, with the passing assertion and run id recorded.

Label justifications:

  • P1: The PR fixes a deterministic host exec bug that can break persisted tool config and OAuth state for real containerized deployments.
  • merge-risk: 🚨 compatibility: The diff rejects additional request-scoped XDG overrides, which can intentionally break existing per-call env override workflows after upgrade.
  • merge-risk: 🚨 security-boundary: The diff changes which host exec environment variables are trusted from inherited process state versus rejected from untrusted request overrides.
  • rating: 🐚 platinum hermit: Current PR rating is 🐚 platinum hermit because proof is 🦞 diamond lobster, patch quality is 🐚 platinum hermit, and Small focused patch with strong live proof, capped by a host exec security and compatibility boundary that needs maintainer approval.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes after-fix live AWS Crabbox proof of a real openclaw agent --local exec subprocess receiving inherited XDG values, with the passing assertion and run id recorded.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix live AWS Crabbox proof of a real openclaw agent --local exec subprocess receiving inherited XDG values, with the passing assertion and run id recorded.

Security concerns:

  • [medium] Confirm the trusted inherited XDG boundary — src/infra/host-env-security-policy.json:272
    Allowing inherited XDG roots is likely the right operator-owned boundary, but it lets the parent OpenClaw process environment steer subprocess config/data paths while rejecting per-call overrides; a maintainer should explicitly approve that trust split before merge.
    Confidence: 0.86

What I checked:

  • working tree clean: The review started from a clean current-main checkout at 7f49964. (7f499643b232)
  • current-main policy strips inherited XDG config vars: Current main lists XDG_CONFIG_HOME and XDG_CONFIG_DIRS in blockedOverrideOnlyKeys but not in allowedInheritedOverrideOnlyKeys, so the derivation treats them as inherited-blocked. (src/infra/host-env-security-policy.json:195, 7f499643b232)
  • current-main derivation explains the bug: derivePolicyArrays builds blockedInheritedKeys from blocked-everywhere keys plus override-only keys that are not inherited-allowed. (src/infra/host-env-security-policy.js:23, 7f499643b232)
  • current-main exec call path uses the sanitizer: The gateway exec path passes process.env as baseEnv and request params.env as overrides into sanitizeHostExecEnvWithDiagnostics, so policy buckets directly control subprocess inheritance and override rejection. (src/agents/bash-tools.exec.ts:1452, 7f499643b232)
  • PR policy change separates inheritance from overrides: The PR adds all XDG base-directory variables to the override block bucket and to allowedInheritedOverrideOnlyKeys, removing XDG_CONFIG_HOME and XDG_CONFIG_DIRS from derived inherited-blocked output while keeping request overrides blocked. (src/infra/host-env-security-policy.json:192, 599640f141a1)
  • PR tests cover both sides of the boundary: The sanitizer tests add inherited XDG expectations and override rejection coverage for XDG cache, config, data, runtime, and state variables; baseline and Swift parity artifacts are updated too. (src/infra/host-env-security.test.ts:548, 599640f141a1)

Likely related people:

  • joshavant: Commit 7abfff7 added host env override enforcement and added XDG_CONFIG_HOME to the affected policy path; this PR author also has prior merged history on the same sanitizer boundary. (role: introduced relevant override hardening; confidence: high; commits: 7abfff756d6c; files: src/infra/host-env-security-policy.json, src/infra/host-env-security.ts, src/agents/bash-tools.exec.path.test.ts)
  • pgondhi987: Commit 2d126fc added allowedInheritedOverrideOnlyKeys, derived blockedInheritedKeys, and reported-baseline enforcement on the affected host env security policy path. (role: introduced inherited-policy derivation; confidence: high; commits: 2d126fc62343; files: src/infra/host-env-security-policy.js, src/infra/host-env-security-policy.json, src/infra/host-env-security.reported-baseline.test.ts)
  • eleqtrizit: Commit fa82193 introduced the separate policy module and aligned inherited host exec environment filtering, so this history is directly adjacent to the current PR's boundary. (role: adjacent inherited-env policy contributor; confidence: medium; commits: fa82193c7273; files: src/infra/host-env-security-policy.js, src/infra/host-env-security-policy.json, src/infra/host-env-security.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 7f499643b232.

@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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 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.

@joshavant
joshavant merged commit cbe68ba into main May 22, 2026
122 of 126 checks passed
@joshavant
joshavant deleted the fix/xdg-host-env-inheritance branch May 22, 2026 01:01
@joshavant
joshavant restored the fix/xdg-host-env-inheritance branch May 23, 2026 00:36
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
galiniliev pushed a commit to galiniliev/openclaw that referenced this pull request May 25, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
SYU8384 pushed a commit to SYU8384/openclaw that referenced this pull request Jun 3, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix exec xdg env inheritance

* chore changelog xdg env fix
@steipete
steipete deleted the fix/xdg-host-env-inheritance branch July 15, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos maintainer Maintainer-authored PR proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

[Bug]: XDG Base Directory env vars are not inherited by subprocesses, breaking XDG-aware tools (gogcli, mcporter, others)

1 participant