T09 · Insecure Skill Coding Practices
- Location
scripts/agent_memory.py:178- Finding
Managed Configuration Mirrors May Be Created with Unsafe Permissions and Symlink Following
- Content
View full analysis
Vulnerability Details
File Location:
scripts/agent_memory.py, lines 178-180 and 225-232
Vulnerability Type: Insecure file creation and unsafe symbolic-link handling
Risk Level: MediumVulnerable Code
python def save_config(cfg: dict, path: Path) -> None: with open(path, "w") as f: json.dump(cfg, f, indent=2, ensure_ascii=False)The vulnerable function is used to write complete configuration data to managed mirror paths:
python for dest in CONTAINER_SYNC_TARGETS: if dest.parent.exists(): if dry_run: synced.append(f"{dest} (DRY-RUN)") else: try: save_config(cfg, dest) synced.append(str(dest))Technical Analysis
save_config()opens the destination with Python's standard"w"mode without explicitly setting restrictive permissions or protecting against symbolic links.When a managed mirror file does not exist, its permissions are derived from the process umask. In common environments, this can create a file with mode
0644, allowing other local users or container processes to read it. The script writes the complete OpenClaw configuration to each mirror, rather than only the modified memory settings. If that configuration contains API keys, access tokens, credentials, or other sensitive values, those values may therefore become locally accessible.The operation also follows symbolic links. The script checks only whether the destination's parent directory exists; it does not verify that the destination is a regular file, reject symbolic links, or validate the ownership and permissions of the parent directory. If a less-trusted actor can modify one of the managed mirror directories, that actor could replace
openclaw.jsonwith a symbolic link before the script runs.Attack Path
- An attacker obtains write access to
/app/clawconfig/or/app/k8s-config/clawconfig/. - The attacker removes the expected
openclaw.jsonmirr ...[truncated 1274 chars]
- An attacker obtains write access to
- Remediation
View remediation
Remediation Suggestions
- Create configuration files with an explicit restrictive mode such as
0600, rather than relying on the process umask. - Use
os.open()with appropriate flags, includingO_WRONLY,O_CREAT,O_TRUNC, andO_NOFOLLOWwhere supported. - Reject destinations that are symbolic links or non-regular files by validating them with
lstat()before writing. - Validate that each managed mirror directory has trusted ownership and is not writable by untrusted users or groups.
- Perform atomic writes:
- Create a temporary file securely in the destination directory.
- Apply mode
0600. - Write and flush the JSON data.
- Call
os.fsync()where durability is required. - Atomically replace the destination with
os.replace().
- Preserve restrictive permissions when replacing an existing configuration file.
- Consider verifying the destination again immediately before replacement to reduce time-of-check/time-of-use exposure.
- Create configuration files with an explicit restrictive mode such as
