Skip to content

Harden update environment path resolution#77470

Merged
drobison00 merged 2 commits into
openclaw:mainfrom
drobison00:fix-update-env-path
May 4, 2026
Merged

Harden update environment path resolution#77470
drobison00 merged 2 commits into
openclaw:mainfrom
drobison00:fix-update-env-path

Conversation

@drobison00

Copy link
Copy Markdown
Contributor

Harden update environment path resolution

Summary

  • Problem: Workspace dotenv loading allowed a Windows local app-data root variable to enter process env, and update path setup could use a supplied env object to locate portable Git.
  • Why it matters: The update flow later runs Git commands, so the executable search path must not be derived from workspace-controlled values.
  • What changed: Workspace dotenv now blocks the Windows local app-data key, and portable Git path discovery reads the process-local value only.
  • What did NOT change (scope boundary): No updater command sequence, package manager behavior, CI, release, or workflow files changed.

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

Root Cause (if applicable)

  • Root cause: Workspace .env filtering did not block the Windows local app-data key, and portable Git discovery trusted an explicit env object before process.env.
  • Missing detection / guardrail: Existing tests covered other workspace-controlled host roots, but not the Windows local app-data root used by the update path.
  • Contributing context (if known): The update env helper prepends existing portable Git directories on Windows before update commands run.

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/infra/dotenv.test.ts, src/infra/update-global.test.ts
  • Scenario the test should lock in: Workspace dotenv cannot set the Windows local app-data key, and portable Git prepends are resolved only from the trusted process-local value.
  • Why this is the smallest reliable guardrail: The bug is in env filtering and update env construction, so unit tests directly cover both branches without running a full update.
  • Existing test that already covers this (if any): Existing workspace dotenv blocklist tests covered nearby host-root variables but not this key.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Windows update path setup no longer derives portable Git directories from a workspace-provided local app-data value.

Diagram (if applicable)

Before:
[workspace .env] -> [local app-data env] -> [portable Git PATH prepend]

After:
[workspace .env] -> [blocked key]
[process env] -> [portable Git PATH prepend]

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (Yes)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation: The command resolution surface is narrowed by preventing workspace dotenv values from selecting the portable Git root used during updates.

Repro + Verification

Environment

  • OS: Linux 6.8.0-110-generic x86_64
  • Runtime/container: Node v22.14.0, pnpm 10.33.2
  • Model/provider:
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. Create a workspace .env containing a Windows local app-data key that points at an attacker-controlled portable Git tree.
  2. Trigger update env construction for the Windows update flow.
  3. Run the targeted infra unit tests.

Expected

  • Workspace dotenv drops the local app-data key.
  • Portable Git path prepends are derived from the trusted process-local value, not an injected env object.
  • Targeted tests pass.

Actual

  • The key is blocked from workspace dotenv.
  • The update env helper ignores injected local app-data values when resolving portable Git paths.
  • src/infra/dotenv.test.ts and src/infra/update-global.test.ts passed under the infra Vitest config.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Targeted validation:

pnpm exec vitest run --config test/vitest/vitest.infra.config.ts --reporter=verbose src/infra/dotenv.test.ts src/infra/update-global.test.ts
Test Files  2 passed (2)
Tests  52 passed (52)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: Workspace dotenv blocking for the Windows local app-data key; portable Git path resolution ignores injected env values and honors the trusted process-local value.
  • Edge cases checked: Mixed-case and uppercase dotenv keys; no process-local value present; both injected and trusted portable Git directories existing.
  • What you did not verify: A full Windows openclaw update run.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: A user expected workspace .env to supply this Windows host-root variable for update behavior.
    • Mitigation: Workspace .env is untrusted for host-root controls; trusted shell or global config remains the source for process-local update environment values.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels May 4, 2026
@clawsweeper

clawsweeper Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

Summary
The branch blocks LOCALAPPDATA in workspace dotenv, resolves Windows portable Git prepends from process-local LOCALAPPDATA, and adds targeted infra unit tests.

Reproducibility: yes. from source inspection: current main omits LOCALAPPDATA from the workspace dotenv blocklist and prefers explicit env.LOCALAPPDATA when building the portable Git PATH prepend. I did not run tests because this review is read-only.

Next step before merge
The only concrete blocker found is a narrow changelog omission that an automated repair can add without touching runtime code.

Security
Cleared: The diff narrows Windows update command resolution and does not add dependencies, workflow permissions, network calls, secret handling, or release-script changes.

Review findings

  • [P3] Add the required changelog entry — src/infra/dotenv.ts:31
Review details

Best possible solution:

Keep the infra hardening in the owner files, add a single-line Unreleased changelog entry, then let maintainer/security review and CI decide landing.

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

Yes, from source inspection: current main omits LOCALAPPDATA from the workspace dotenv blocklist and prefers explicit env.LOCALAPPDATA when building the portable Git PATH prepend. I did not run tests because this review is read-only.

Is this the best way to solve the issue?

Yes, mostly: blocking workspace LOCALAPPDATA and deriving portable Git paths from process-local env is the narrow maintainable fix for the stated command-resolution risk. The safer landing path is to add the required changelog entry without broadening the runtime change.

Full review comments:

  • [P3] Add the required changelog entry — src/infra/dotenv.ts:31
    This hardening changes user-visible update behavior and is marked as a bug/security fix, but the PR only touches infra code and tests. Repo policy requires a single-line CHANGELOG.md entry for user-facing fixes before landing.
    Confidence: 0.9

Overall correctness: patch is correct
Overall confidence: 0.86

Acceptance criteria:

  • git diff --check
  • Review CHANGELOG.md manually for one-line bullet style and allowed attribution

What I checked:

  • Current dotenv behavior: Current main normalizes workspace dotenv keys and checks a fixed blocklist, but LOCALAPPDATA is not present in BLOCKED_WORKSPACE_DOTENV_KEYS. (src/infra/dotenv.ts:16, 8c7ec5d1f9ff)
  • Current portable Git lookup: Current main resolves portable Git paths from env?.LOCALAPPDATA before falling back to process.env.LOCALAPPDATA, matching the PR's stated attack surface. (src/infra/update-global.ts:277, 8c7ec5d1f9ff)
  • PR dotenv change: The PR diff adds LOCALAPPDATA to the workspace dotenv blocklist and extends the Windows shell trust-root dotenv test for LocalAppData/LOCALAPPDATA. (src/infra/dotenv.ts:31, 8e7411a2b34f)
  • PR update-env coverage: The PR adds a unit test proving injected LOCALAPPDATA is ignored for portable Git prepends while the trusted process-local value is honored. (src/infra/update-global.test.ts:150, 8e7411a2b34f)
  • Changelog gap: The active Unreleased section has no entry for this user-visible update/security hardening, and the PR file list does not include CHANGELOG.md. (CHANGELOG.md:48, 8c7ec5d1f9ff)
  • Related item check: The body's Related #544 points to a closed Cloud Code Assist API-errors PR, not the update environment path resolution surface, so it does not supersede this PR.

Likely related people:

  • Michael Appel: Path history for the touched infra files points to adjacent Windows env trust-root hardening in commits that updated workspace dotenv and host env security behavior. (role: recent adjacent env-security maintainer; confidence: medium; commits: 7b8315d18e3c, c1da0ddd5452; files: src/infra/dotenv.ts, src/infra/dotenv.test.ts, src/infra/host-env-security.ts)
  • vincentkoc: Recent main history shows current changelog maintenance and multiple update-flow entries in the active Unreleased section, which is relevant to the missing changelog placement rather than runtime ownership. (role: recent changelog/release-note maintainer; confidence: low; commits: 8c7ec5d1f9ff; files: CHANGELOG.md)

Remaining risk / open question:

  • The PR has targeted unit-test evidence but no full Windows openclaw update smoke proof.
  • CHANGELOG.md is missing the required user-facing fix/security-hardening entry before landing.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 8c7ec5d1f9ff.

drobison00 added 2 commits May 4, 2026 13:40
Adds the user-facing Unreleased Fixes entry for the workspace LOCALAPPDATA
blocklist + portable Git path-prepend hardening change in this PR.
@drobison00
drobison00 force-pushed the fix-update-env-path branch from 8e7411a to 479ee5d Compare May 4, 2026 19:45
@drobison00
drobison00 merged commit 8b2bf7b into openclaw:main May 4, 2026
93 checks passed
lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
* Harden update environment path resolution

* docs(changelog): credit windows update env path hardening

Adds the user-facing Unreleased Fixes entry for the workspace LOCALAPPDATA
blocklist + portable Git path-prepend hardening change in this PR.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* Harden update environment path resolution

* docs(changelog): credit windows update env path hardening

Adds the user-facing Unreleased Fixes entry for the workspace LOCALAPPDATA
blocklist + portable Git path-prepend hardening change in this PR.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* Harden update environment path resolution

* docs(changelog): credit windows update env path hardening

Adds the user-facing Unreleased Fixes entry for the workspace LOCALAPPDATA
blocklist + portable Git path-prepend hardening change in this PR.
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* Harden update environment path resolution

* docs(changelog): credit windows update env path hardening

Adds the user-facing Unreleased Fixes entry for the workspace LOCALAPPDATA
blocklist + portable Git path-prepend hardening change in this PR.
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* Harden update environment path resolution

* docs(changelog): credit windows update env path hardening

Adds the user-facing Unreleased Fixes entry for the workspace LOCALAPPDATA
blocklist + portable Git path-prepend hardening change in this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant