openclaw - ✅(Solved) Fix [Bug]: Beta blocker: core - OpenClaw Agents Can Self-Destruct Through Configuration Modification [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#65721Fetched 2026-04-14 05:40:36
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
cross-referenced ×2labeled ×2

OpenClaw agents can modify critical configuration files without safeguards, causing service failure requiring manual openclaw doctor --fix recovery.

Error Message

  1. OpenClaw gateway fails to start with "Config invalid" error Agent successfully added invalid env.shellEnv.vars field to configuration, causing gateway startup failure with error: env.shellEnv: Unrecognized key: "vars". Manual recovery required.

Root Cause

This incident (2026-04-13) follows a similar pattern from 2026-04-12 where agent configured itself into Docker sandbox, losing access to its own configuration. Both incidents demonstrate the same root cause: OpenClaw lacks basic self-protection mechanisms.

Fix Action

Fixed

PR fix notes

PR #65766: fix(config): auto-heal unrecognized keys during config load to prevent gateway crash

Description (problem / solution / changelog)

fix(config): auto-heal unrecognized keys during config load to prevent gateway crash

Summary

  • Problem: When an Agent (or external tool) modifies ~/.openclaw/openclaw.json directly via the filesystem and injects invalid fields into strict objects (e.g., writing vars into env.shellEnv), the gateway crashes on startup with a "Config invalid" error. This is a Beta release blocker (Issue #65721) because it requires manual intervention (openclaw doctor --fix) to recover.
  • Root Cause: loadConfig and readConfigFileSnapshotInternal use OpenClawSchema.safeParse() which correctly rejects unrecognized_keys in .strict() objects. However, the failure path immediately throws or returns invalid, offering no fault tolerance for stray keys injected by agents.
  • Fix: Introduced a self-healing mechanism (applyUnrecognizedKeyRecovery) in the validation failure path. If the only validation errors are unrecognized_keys, it precisely strips those keys from the raw config and re-validates. If successful, the gateway starts normally and logs an error-level diagnostic prompting the user to run openclaw doctor --fix to persist the cleanup.
  • What changed:
    • src/config/validation.ts: Added tryRecoverUnrecognizedKeys and applyUnrecognizedKeyRecovery to handle the stripping and re-validation logic.
    • src/config/validation.ts: Updated stripUnrecognizedKeysFromConfig to support array index traversal and added isBlockedObjectKey protection against prototype tampering (CWE-1321).
    • src/config/io.ts: Replaced immediate failure in loadConfig and readConfigFileSnapshotInternal with calls to applyUnrecognizedKeyRecovery.
    • src/config/config.unrecognized-key-recovery.test.ts: Added comprehensive regression tests for the recovery logic, namespace restrictions, and size guards.
  • What did NOT change (scope boundary):
    • The Zod schemas themselves were not relaxed; .strict() remains intact.
    • The on-disk config file is not mutated automatically; the healed config is in-memory only.
    • Non-unrecognized_keys errors (e.g., type mismatches) still cause immediate fail-closed crashes.

Reproduction

  1. Start the gateway with a valid config.
  2. Manually edit ~/.openclaw/openclaw.json and add "vars": { "PATH": "/usr/bin" } inside env.shellEnv.
  3. Restart the gateway.
  4. Before: Gateway crashes with "Config invalid".
  5. After: Gateway starts successfully, logs an error about the stripped key, and ignores the invalid field.

Risk / Mitigation

  • Risk: CWE-693 (Fail-open) - Auto-healing might silently strip security-relevant keys if a user downgrades to an older version where those keys are unrecognized.
  • Mitigation:
    1. Added allowedTopLevelKeys: ["agents", "meta", "env"] to restrict healing to specific namespaces. Security/gateway configs will still fail-closed.
    2. Healing logs at error level to ensure visibility.
    3. Path comparison is segment-wise to prevent dot-in-key bypasses (CWE-284).
  • Risk: CWE-400 (DoS) - Expensive structuredClone and re-validation on massive config files.
  • Mitigation: Added rawFileSize check. Healing is skipped if the config exceeds 2 MiB.
  • Risk: Silent coercion of union types (e.g., ACP bindings).
  • Mitigation: Removed invalid_union traversal entirely. The core issue (env.shellEnv.vars) does not involve unions, so we strictly avoid union-aware recovery to prevent unintended structural changes.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Gateway
  • Config
  • Validation

Changed files

  • src/config/config.unrecognized-key-recovery.test.ts (added, +197/-0)
  • src/config/io.ts (modified, +31/-2)
  • src/config/validation.ts (modified, +279/-0)

Code Example

413 09:41:13 f2048 node[1115161]: Config invalid
413 09:41:13 f2048 node[1115161]: File: ~/.openclaw/openclaw.json
413 09:41:13 f2048 node[1115161]: Problem:
413 09:41:13 f2048 node[1115161]:   - env.shellEnv: Unrecognized key: "vars"
413 09:41:13 f2048 node[1115161]: Run: openclaw doctor --fix
413 09:41:13 f2048 systemd[925]: openclaw-gateway.service: Main process exited, code=exited, status=1/FAILURE
RAW_BUFFERClick to expand / collapse

Bug type

Crash (process/app exits or hangs)

Beta release blocker

Yes

Summary

OpenClaw agents can modify critical configuration files without safeguards, causing service failure requiring manual openclaw doctor --fix recovery.

Steps to reproduce

  1. Start OpenClaw 2026.4.9 with default configuration
  2. Agent modifies ~/.openclaw/openclaw.json adding invalid configuration fields (e.g., env.shellEnv.vars which is unsupported)
  3. OpenClaw gateway fails to start with "Config invalid" error
  4. Manual openclaw doctor --fix required to restore service

Expected behavior

System should prevent agents from modifying critical configuration or provide validation to reject invalid changes before service failure occurs.

Actual behavior

Agent successfully added invalid env.shellEnv.vars field to configuration, causing gateway startup failure with error: env.shellEnv: Unrecognized key: "vars". Manual recovery required.

OpenClaw version

2026.4.9 (0512059)

Operating system

Ubuntu 22.04

Install method

npm global

Model

deepseek/deepseek-chat

Provider / routing chain

direct

Additional provider/model setup details

Default configuration with no security restrictions. Agent has full filesystem access to its own configuration.

Logs, screenshots, and evidence

413 09:41:13 f2048 node[1115161]: Config invalid
413 09:41:13 f2048 node[1115161]: File: ~/.openclaw/openclaw.json
413 09:41:13 f2048 node[1115161]: Problem:
413 09:41:13 f2048 node[1115161]:   - env.shellEnv: Unrecognized key: "vars"
413 09:41:13 f2048 node[1115161]: Run: openclaw doctor --fix
413 09:41:13 f2048 systemd[925]: openclaw-gateway.service: Main process exited, code=exited, status=1/FAILURE

Impact and severity

Affected: All OpenClaw users where agents have configuration access. Severity: Critical (causes service failure, requires manual recovery) Frequency: Reproducible when agents attempt configuration modifications Consequence: • Service downtime requiring manual intervention • Breaks automation reliability • Makes OpenClaw unsuitable for production deployments • Users will seek alternatives with self-protection mechanisms

Additional information

This incident (2026-04-13) follows a similar pattern from 2026-04-12 where agent configured itself into Docker sandbox, losing access to its own configuration. Both incidents demonstrate the same root cause: OpenClaw lacks basic self-protection mechanisms.

The system assumes agents won't break themselves, but real-world usage proves this assumption false. Without configuration safeguards, OpenClaw remains a proof-of-concept rather than a production-ready tool.

Required fixes:

  1. Configuration file protection (read-only by default for critical files)
  2. Configuration validation at write time, not just startup
  3. Automatic backups before configuration changes
  4. Gradient permissions system to control configuration access

Without these protections, OpenClaw cannot be trusted for production use where reliability is essential.

extent analysis

TL;DR

Implement configuration validation and protection mechanisms to prevent OpenClaw agents from modifying critical configuration files without safeguards.

Guidance

  • Validate configuration changes at write time to prevent invalid fields like env.shellEnv.vars from being added.
  • Set critical configuration files to read-only by default to prevent agents from modifying them directly.
  • Consider implementing automatic backups before configuration changes to allow for easy recovery in case of errors.
  • Develop a gradient permissions system to control configuration access and prevent unauthorized changes.

Example

No specific code example is provided as the issue focuses on the need for configuration protection and validation mechanisms rather than a specific code fix.

Notes

The required fixes mentioned in the issue, such as configuration file protection, validation at write time, automatic backups, and a gradient permissions system, are crucial for preventing similar incidents and making OpenClaw suitable for production deployments.

Recommendation

Apply a workaround by manually setting critical configuration files to read-only and implementing a basic validation script to check for invalid configuration fields until a permanent fix with built-in configuration protection and validation mechanisms is available. This is because the current version (2026.4.9) lacks these essential features, making it unreliable for production use.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

System should prevent agents from modifying critical configuration or provide validation to reject invalid changes before service failure occurs.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Beta blocker: core - OpenClaw Agents Can Self-Destruct Through Configuration Modification [1 pull requests, 1 participants]