Exec: harden host env override handling across gateway and node#51207
Conversation
🔒 Aisle Security AnalysisWe found 2 potential security issue(s) in this PR:
1. 🔵 Log/control-character injection via reflected invalid env override keys in system.run denial message (Node)
Description
Key points:
Vulnerable code (sink): message: `SYSTEM_RUN_DENIED: environment override rejected (${details.join("; ")})`where RecommendationAvoid reflecting untrusted key material verbatim in error messages/logs. Options:
function escapeForDiagnostic(s: string): string {
// Replace control chars (including newlines/escapes) with visible escapes
return s.replace(/[\u0000-\u001F\u007F]/g, (ch) => {
const code = ch.codePointAt(0)!.toString(16).padStart(2, "0");
return `\\x${code}`;
});
}
const safeInvalid = envOverrideDiagnostics.rejectedOverrideInvalidKeys.map(escapeForDiagnostic);
Apply the same escaping anywhere rejected keys are included in diagnostics (source lists are built in 2. 🔵 Log/control-character injection via reflected invalid env override keys in system.run denial message (macOS Swift)
DescriptionThe macOS node runtime rejects blocked/invalid environment override keys and reflects the rejected key names inside an error message returned to callers. The invalid key strings are derived from untrusted JSON dictionary keys ( Impact:
Vulnerable code: invalid.append(candidate.isEmpty ? rawKey : candidate)
...
message: "SYSTEM_RUN_DENIED: environment override rejected (\(details.joined(separator: "; ")) )"where RecommendationDo not embed untrusted strings verbatim into diagnostic messages. Recommended fix:
Example escaping helper: func escapeForDiagnostic(_ s: String) -> String {
var out = ""
for scalar in s.unicodeScalars {
if scalar.value < 0x20 || scalar.value == 0x7F {
out += String(format: "\\x%02X", scalar.value)
} else {
out.unicodeScalars.append(scalar)
}
}
return out
}
let safeInvalid = envOverrideDiagnostics.invalidKeys.map(escapeForDiagnostic)Then use Also apply similar escaping in Analyzed PR: #51207 at commit Last updated on: 2026-03-20T21:55:49Z |
Greptile SummaryThis PR hardens host environment variable override handling across the gateway ( Key changes and observations:
Confidence Score: 3/5
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f706096e3
ℹ️ 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".
|
Follow-up pushed in ff0c326 to address review feedback:
Targeted tests run: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff0c326a2b
ℹ️ 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".
cbc3b05 to
1de1487
Compare
Signed-off-by: joshavant <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb2b239367
ℹ️ 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".
| "GEM_PATH", | ||
| "BUNDLE_GEMFILE", | ||
| "COMPOSER_HOME", | ||
| "XDG_CONFIG_HOME" |
There was a problem hiding this comment.
Don't strip inherited XDG_CONFIG_HOME from host execs
Adding XDG_CONFIG_HOME to blockedKeys means both sanitizeHostExecEnvWithDiagnostics() in src/infra/host-env-security.ts and the macOS HostEnvSanitizer.sanitize() now remove it from the inherited process environment for every gateway/node execution, even when the request did not ask for any env override. In deployments that start OpenClaw with a non-default XDG config root (common in containers and service units), commands like git, gh, or ssh will suddenly run against the wrong config or logged-out state. If the goal here is to reject request-scoped poisoning, this key needs to be blocked only for overrides, not for inherited host env.
Useful? React with 👍 / 👎.
…claw#51207) * Exec: harden host env override enforcement and fail closed * Node host: enforce env override diagnostics before shell filtering * Env overrides: align Windows key handling and mac node rejection
…claw#51207) * Exec: harden host env override enforcement and fail closed * Node host: enforce env override diagnostics before shell filtering * Env overrides: align Windows key handling and mac node rejection
…claw#51207) * Exec: harden host env override enforcement and fail closed * Node host: enforce env override diagnostics before shell filtering * Env overrides: align Windows key handling and mac node rejection
…claw#51207) * Exec: harden host env override enforcement and fail closed * Node host: enforce env override diagnostics before shell filtering * Env overrides: align Windows key handling and mac node rejection
…claw#51207) * Exec: harden host env override enforcement and fail closed * Node host: enforce env override diagnostics before shell filtering * Env overrides: align Windows key handling and mac node rejection
…claw#51207) * Exec: harden host env override enforcement and fail closed * Node host: enforce env override diagnostics before shell filtering * Env overrides: align Windows key handling and mac node rejection
…claw#51207) * Exec: harden host env override enforcement and fail closed * Node host: enforce env override diagnostics before shell filtering * Env overrides: align Windows key handling and mac node rejection
Summary
Validation
pnpm test -- src/infra/host-env-security.test.ts src/agents/bash-tools.exec.path.test.ts src/node-host/invoke-system-run.test.tspnpm buildpnpm check(currently fails in unrelated pre-existing file:docs/plugins/sdk-migration.mdformatting)OPENCLAW_TEST_PROFILE=low OPENCLAW_TEST_SERIAL_GATEWAY=1 pnpm test(currently fails in unrelated pre-existing extension deps:fake-indexeddb/autoinextensions/matrix)