Skip to content

fix(infra): expand host env security policy denylist [AI] - #63277

Merged
pgondhi987 merged 15 commits into
openclaw:mainfrom
pgondhi987:fix/fix-376
Apr 10, 2026
Merged

pgondhi987 merged 15 commits into
openclaw:mainfrom
pgondhi987:fix/fix-376

Conversation

@pgondhi987

@pgondhi987 pgondhi987 commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: sanitizeHostExecEnv() previously missed a broad set of dangerous environment variables
    across startup hooks, interpreter init, orchestration/config loaders, credential redirection, and
    compiler/runtime injection surfaces.
  • Why it matters: A prompt-injected agent could smuggle high-risk env vars through exec calls (for
    example startup-hook or credential/orchestration variables) and get unsafe behavior inside otherwise
    approved command flows.
  • What changed:
    • Expanded src/infra/host-env-security-policy.json denylist coverage (now
      blockedEverywhereKeys=90, blockedOverrideOnlyKeys=142).
    • Added inherited-env policy semantics in src/infra/host-env-security-policy.js/.d.ts:
      • blockedInheritedKeys
      • blockedInheritedPrefixes
      • allowedInheritedOverrideOnlyKeys (explicit inherited exceptions)
    • Updated runtime sanitization logic in src/infra/host-env-security.ts so inherited base env is
      filtered by isDangerousHostInheritedEnvVarName(...).
    • Updated host exec runtime enforcement in src/agents/bash-tools.exec-runtime.ts to apply inherited-
      env dangerous checks.
    • Updated macOS parity:
      • apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift
      • apps/macos/Sources/OpenClaw/HostEnvSanitizer.swift
      • scripts/generate-host-env-security-policy-swift.mjs
    • Added/expanded tests:
      • 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
      • src/infra/host-env-security.reported-baseline.json (fixed reported baseline: 232 entries)
  • What did NOT change:
    • No safeBins changes.
    • No exec approval model changes.
    • This is still denylist-based hardening (not a full env allowlist model).
  • AI-assisted: This PR was generated by OpenAI Codex and reviewed for correctness. JSON↔Swift parity
    is covered by tests.

Change Type (select all)

  • Bug fix
  • Security hardening

Scope (select all touched areas)

  • Skills / tool execution
  • Auth / tokens

Linked Issue/PR

  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: host-env-security-policy.json coverage and inherited-env semantics were insufficient for
    the reported dangerous-env class.
  • Missing detection / guardrail: No fixed reported-baseline completeness gate existed to prevent
    regressions in dangerous-env coverage.
  • Contributing context (if known): Exec env is LLM-controlled input; incomplete policy + inherited
    gaps allowed risky env influence in child processes.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
  • Target test or file:
    • src/infra/host-env-security.test.ts
    • src/infra/host-env-security.reported-baseline.test.ts
    • src/infra/host-env-security.policy-parity.test.ts
  • Scenario the test should lock in:
    • Reported dangerous baseline entries are blocked in override flow.
    • Inherited flow blocks dangerous entries except explicit, rationale-documented inherited exceptions.
    • TS policy and generated Swift policy stay in sync.
  • Why this is the smallest reliable guardrail:
    • Direct policy/runtime unit assertions plus parity and baseline completeness checks.
  • Existing test that already covers this (if any):
    • Prior tests covered subsets but not fixed baseline completeness + inherited exception rationale.
  • If no new test is added, why not:
    • N/A (new tests added).

User-visible / Behavior Changes

  • Exec env overrides for newly covered dangerous vars are now rejected.
  • Inherited host env is now filtered more strictly for dangerous keys.
  • Explicit inherited exceptions remain allowed for selected operator/runtime knobs (for example proxy/
    TLS/cert-path style variables), while still blocked as untrusted overrides.

Diagram (if applicable)

Before:
[LLM override/inherited dangerous env] -> sanitizeHostExecEnv() -> may pass through -> unsafe child
behavior

After:
[LLM override/inherited dangerous env] -> inherited+override classifiers -> blocked (with explicit
inherited exceptions only) -> safer child behavior

## Security Impact (required)

- New permissions/capabilities? No
- Secrets/tokens handling changed? Yes — broader credential/orchestration env classes are blocked from
  override injection; inherited handling is stricter.
- New/changed network calls? No
- Command/tool execution surface changed? Yes — host exec env sanitization is stricter for inherited +
  override paths.
- Data access scope changed? No
- Risk + mitigation: More restrictive filtering can affect workflows that relied on risky env injection
  patterns; explicit inherited exceptions and tests reduce compatibility fallout.

## Repro + Verification

### Environment

- OS: Linux (Ubuntu)
- Runtime/container: Node 22 / Bun
- Model/provider: N/A (policy/runtime sanitization change)
- Integration/channel (if any): N/A
- Relevant config (redacted): N/A

### Steps

1. Before fix: dangerous inherited and override env entries could survive in more cases than intended.
2. After fix:
    - inherited base env uses isDangerousHostInheritedEnvVarName(...)
    - override env uses dangerous override/everywhere checks
    - fixed reported baseline coverage is asserted by tests
3. Parity check: JSON policy derivation and generated Swift policy arrays are validated by parity tests.

### Expected

- Reported baseline (232) remains covered by inherited + override sanitization semantics.
- Inherited exceptions are explicit, rationale-documented, and enforced.
- TS/Swift policy parity remains enforced.

### Actual

- pnpm test src/infra/host-env-security.test.ts src/infra/host-env-security.reported-baseline.test.ts
  src/infra/host-env-security.policy-parity.test.ts
- Result: 3 test files passed, 34 tests passed.

## Evidence

- [x] Passing targeted tests for sanitizer behavior, baseline completeness, and TS↔Swift parity.

## Human Verification (required)

- Verified scenarios:
    - inherited vs override behavior for dangerous env classes
    - explicit inherited exception enforcement
    - policy derivation and generated Swift parity
- Edge cases checked:
    - override-prefix behavior (TF_VAR_*) vs inherited behavior
    - dangerous shell/function and loader-style env handling
- What you did not verify:
    - full pnpm test suite
    - live macOS subprocess behavior end-to-end

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

## Compatibility / Migration

- Backward compatible? Mostly yes, with stricter env filtering behavior.
- Config/env changes? No config migration; runtime env sanitization behavior is stricter.
- Migration needed? No formal migration. Consumers relying on risky exec env injection may need to
  adjust.

## Risks and Mitigations

- Risk: Some integrations may rely on env override patterns now blocked.
- Mitigation: Keep only intentional inherited exceptions; block untrusted override injection.
- Risk: Denylist model requires ongoing maintenance as new dangerous vars emerge.
- Mitigation: Fixed reported-baseline tests + policy parity tests reduce regression risk and drift.

@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos size: L maintainer Maintainer-authored PR labels Apr 8, 2026
@greptile-apps

greptile-apps Bot commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR expands host-env-security-policy.json with ~156 new blocked entries across blockedEverywhereKeys and blockedOverrideOnlyKeys, introduces a new allowedInheritedOverrideOnlyKeys allowlist, and wires up a new isDangerousHostInheritedEnvVarName function used when filtering the host's inherited environment. The key semantic improvement is that sanitizeHostExecEnv and sanitizeHostBaseEnv now apply the combined both-buckets-minus-allowlist check to inherited env instead of the narrower everywhere-only check, closing a class of bypass where vars like ANSIBLE_CONFIG, ERL_AFLAGS, VIMINIT, or HOSTALIASES in the operator's own env could flow into child processes.

Confidence Score: 5/5

Safe to merge — pure denylist expansion with no runtime logic regressions; well-covered by new baseline and parity tests.

All remaining findings are P2 or lower. CARGO_HOME removal in the diff is a deduplication (it was duplicated in the old file, still present once in blockedOverrideOnlyKeys). The new allowedInheritedOverrideOnlyKeys mechanism is correctly implemented and tested. No P0/P1 issues identified.

No files require special attention; the baseline test in host-env-security.reported-baseline.test.ts provides strong regression coverage for the new policy entries.

Reviews (7): Last reviewed commit: "fix: address PR review feedback" | Re-trigger Greptile

Comment thread src/infra/host-env-security-policy.json Resolved
@pgondhi987

Copy link
Copy Markdown
Contributor Author

@codex review

@pgondhi987

Copy link
Copy Markdown
Contributor Author

@greptile review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81b292a6a5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/host-env-security-policy.json Resolved
@pgondhi987

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cd061e0fc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/host-env-security-policy.json Resolved
Comment thread src/infra/host-env-security-policy.json Resolved
@pgondhi987

Copy link
Copy Markdown
Contributor Author

@codex review

@pgondhi987

Copy link
Copy Markdown
Contributor Author

@greptile review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/host-env-security-policy.json Resolved
@pgondhi987

Copy link
Copy Markdown
Contributor Author

@greptile review

1 similar comment
@pgondhi987

Copy link
Copy Markdown
Contributor Author

@greptile review

@pgondhi987

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: L and removed size: M labels Apr 9, 2026
@pgondhi987

Copy link
Copy Markdown
Contributor Author

@greptile review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66434c122f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/host-env-security-policy.js Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c7dfe2e13

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/host-env-security-policy.js Resolved
@pgondhi987
pgondhi987 merged commit 2d126fc into openclaw:main Apr 10, 2026
wongcyrus pushed a commit to wongcyrus/openclaw that referenced this pull request Apr 10, 2026
…3277)

* fix: address issue

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: close host env inherited sanitization gap

* fix: enforce host env reported baseline coverage

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* docs: add changelog entry for PR merge
steipete pushed a commit that referenced this pull request Apr 10, 2026
* fix: address issue

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: close host env inherited sanitization gap

* fix: enforce host env reported baseline coverage

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* docs: add changelog entry for PR merge
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…3277)

* fix: address issue

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: close host env inherited sanitization gap

* fix: enforce host env reported baseline coverage

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* docs: add changelog entry for PR merge
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…3277)

* fix: address issue

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: close host env inherited sanitization gap

* fix: enforce host env reported baseline coverage

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* docs: add changelog entry for PR merge
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…3277)

* fix: address issue

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: close host env inherited sanitization gap

* fix: enforce host env reported baseline coverage

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* docs: add changelog entry for PR merge
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…3277)

* fix: address issue

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: close host env inherited sanitization gap

* fix: enforce host env reported baseline coverage

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* docs: add changelog entry for PR merge
@clawsweeper clawsweeper Bot mentioned this pull request Jun 11, 2026
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…3277)

* fix: address issue

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: close host env inherited sanitization gap

* fix: enforce host env reported baseline coverage

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* docs: add changelog entry for PR merge
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…3277)

* fix: address issue

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* fix: close host env inherited sanitization gap

* fix: enforce host env reported baseline coverage

* fix: address PR review feedback

* fix: address PR review feedback

* fix: address PR review feedback

* docs: add changelog entry for PR merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: macos App: macos maintainer Maintainer-authored PR scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant