feat(exec): mark child command env with OPENCLAW_CLI#41411
feat(exec): mark child command env with OPENCLAW_CLI#41411vincentkoc merged 2 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR introduces a consistent One issue found:
Confidence Score: 3/5
Last reviewed commit: 71febcc |
| args.push("--user", params.cfg.user); | ||
| } | ||
| const envSanitization = sanitizeEnvVars(params.cfg.env ?? {}); | ||
| const envSanitization = sanitizeEnvVars(markOpenClawExecEnv(params.cfg.env ?? {})); |
There was a problem hiding this comment.
Marker injected before sanitization — fragile ordering
markOpenClawExecEnv is called on the raw cfg.env input before it is passed to sanitizeEnvVars. The sanitizer's ALLOWED_ENV_VAR_PATTERNS allowlist does not include OPENCLAW_CLI, so if sanitizeEnvVars is ever invoked with strictMode: true (or any caller adds that option at this call-site), OPENCLAW_CLI will be classified as a blocked variable, a warning will be emitted ("Blocked sensitive environment variables: OPENCLAW_CLI"), and the marker will be silently dropped from the container environment — exactly the opposite of the intended behaviour.
All other injection points in this PR (host-env-security.ts, exec.ts) correctly apply markOpenClawExecEnv after sanitization. The Docker path should follow the same pattern:
| const envSanitization = sanitizeEnvVars(markOpenClawExecEnv(params.cfg.env ?? {})); | |
| const envSanitization = sanitizeEnvVars(params.cfg.env ?? {}); |
Then apply the marker after sanitization, immediately before pushing --env args:
for (const [key, value] of Object.entries(markOpenClawExecEnv(envSanitization.allowed))) {
args.push("--env", `${key}=${value}`);
}This also makes the test in sandbox-create-args.test.ts correctly reflect the real execution path.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/sandbox/docker.ts
Line: 369
Comment:
**Marker injected before sanitization — fragile ordering**
`markOpenClawExecEnv` is called on the raw `cfg.env` input **before** it is passed to `sanitizeEnvVars`. The sanitizer's `ALLOWED_ENV_VAR_PATTERNS` allowlist does not include `OPENCLAW_CLI`, so if `sanitizeEnvVars` is ever invoked with `strictMode: true` (or any caller adds that option at this call-site), `OPENCLAW_CLI` will be classified as a blocked variable, a warning will be emitted ("Blocked sensitive environment variables: OPENCLAW_CLI"), and the marker will be silently dropped from the container environment — exactly the opposite of the intended behaviour.
All other injection points in this PR (`host-env-security.ts`, `exec.ts`) correctly apply `markOpenClawExecEnv` **after** sanitization. The Docker path should follow the same pattern:
```suggestion
const envSanitization = sanitizeEnvVars(params.cfg.env ?? {});
```
Then apply the marker after sanitization, immediately before pushing `--env` args:
```typescript
for (const [key, value] of Object.entries(markOpenClawExecEnv(envSanitization.allowed))) {
args.push("--env", `${key}=${value}`);
}
```
This also makes the test in `sandbox-create-args.test.ts` correctly reflect the real execution path.
How can I resolve this? If you propose a fix, please make it concise.* main: (33 commits) Exec: mark child command env with OPENCLAW_CLI (openclaw#41411) fix(plugins): expose model auth API to context-engine plugins (openclaw#41090) Add HTTP 499 to transient error codes for model fallback (openclaw#41468) Logging: harden probe suppression for observations (openclaw#41338) fix(discord): apply effective maxLinesPerMessage in live replies (openclaw#40133) build(protocol): regenerate Swift models after pending node work schemas (openclaw#41477) Agents: add fallback error observations (openclaw#41337) acp: harden follow-up reliability and attachments (openclaw#41464) fix(agents): probe single-provider billing cooldowns (openclaw#41422) acp: add regression coverage and smoke-test docs (openclaw#41456) acp: forward attachments into ACP runtime sessions (openclaw#41427) acp: enrich streaming updates for ide clients (openclaw#41442) Sandbox: import STATE_DIR from paths directly (openclaw#41439) acp: restore session context and controls (openclaw#41425) acp: fail honestly in bridge mode (openclaw#41424) Gateway: tighten node pending drain semantics (openclaw#41429) Gateway: add pending node work primitives (openclaw#41409) fix(auth): reset cooldown error counters on expiry to prevent infinite escalation (openclaw#41028) fix(cron): do not misclassify empty/NO_REPLY as interim acknowledgement (openclaw#41401) iOS: reconnect gateway on foreground return (openclaw#41384) ...
- environment.md: add OPENCLAW_CLI=1 runtime marker (landed in openclaw#41411 without docs update) - acp.md: document --provenance flag with off/meta/meta+receipt modes (landed in openclaw#40473 without Options section update) - onboarding.md: document remote gateway token field added in 6b338dd - gmail-pubsub.md: standardize hook token to ${OPENCLAW_HOOKS_TOKEN} to match webhook.md (was using literal "OPENCLAW_HOOK_TOKEN")
(cherry picked from commit b48291e)
(cherry picked from commit b48291e)
Summary
system.run, and sandboxed command surfaces.OPENCLAW_CLI=1marker helper and applied it at CLI startup, host exec env sanitization, genericrunCommandWithTimeoutenv resolution, and sandbox Docker env injection, plus focused regression tests.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
OPENCLAW_CLI=1, including host exec flows and Docker sandboxes.Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) YesYes/No) NoYes, explain risk + mitigation:This changes child-process environment contents by adding a single non-secret marker variable. Risk is limited to tooling that reacts to the presence of
OPENCLAW_CLI; mitigation is the value is explicit, stable, and covered by focused tests on host env sanitization, generic exec env resolution, and sandbox env creation.Repro + Verification
Environment
Steps
runCommandWithTimeout, node-hostsystem.run, or sandbox container creation.OPENCLAW_CLI=1is present.Expected
OPENCLAW_CLI=1marker.Actual
Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
pnpm test src/process/exec.test.ts src/infra/host-env-security.test.ts src/agents/sandbox-create-args.test.tsin the PR worktree; all passed.Review Conversations
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
Yes/No) YesYes/No) YesYes/No) NoFailure Recovery (if this breaks)
src/entry.ts,src/infra/host-env-security.ts,src/process/exec.ts, andsrc/agents/sandbox/docker.tsOPENCLAW_CLIis present.Risks and Mitigations
OPENCLAW_CLIfor an unrelated purpose.