T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/validate_openclaw_env.py:218
- Finding
- Malformed Environment Lines Can Disclose Credentials Through Validation Output<![CDATA[ ## Vulnerability Details **File Location**: `scripts/validate_openclaw_env.py`, lines 68–79, 218, and 233–235 **Vulnerability Type**: Sensitive information exposure through diagnostic output **Risk Level**: Medium ### Vulnerable Code ```python for idx, raw_line in enumerate(env_path.read_text().splitlines(), start=1): line = raw_line.strip() if not line or line.startswith("#"): continue if "=" not in line: malformed.append((idx, raw_line)) continue key, value = line.split("=", 1) key = key.strip() value = value.strip() if not KEY_RE.match(key): malformed.append((idx, raw_line)) continue ``` The complete malformed line is subsequently included in JSON output: ```python "malformed_lines": [{"line": line_no, "content": line} for line_no, line in malformed], ``` It is also printed in human-readable output: ```python if malformed: print("\nMalformed lines:") for line_no, line in malformed: print(f" - line {line_no}: {line}") ``` ### Technical Analysis The validator is explicitly designed to process `.env` files containing gateway tokens, model-provider API keys, and cloud-provider credentials. When a line does not contain `=` or has an invalid key name, the implementation retains the complete original line in `malformed`. The raw line is then emitted through both supported output modes: - JSON output includes the line in the `content` field. - Human-readable output prints the line directly to standard output. Malformed environment lines may still contain valid secret values. For example, an operator could accidentally use a space instead of an equals sign: ```text OPENAI_API_KEY sk-sensitive-value ``` Although this line is invalid as environment-file syntax, its sensitive value remains present and will be copied verbatim into validation output. That output may be collected by CI systems, deployment logs, agent transcripts, terminal recording systems, or su ...[truncated 1664 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Never include the original content of malformed environment lines in output. 2. Report only the line number and a generic parsing reason: ```python malformed.append((idx, "missing assignment separator")) ``` 3. Change JSON output to exclude a `content` field: ```python "malformed_lines": [ {"line": line_no, "reason": reason} for line_no, reason in malformed ] ``` 4. Change human-readable output accordingly: ```python for line_no, reason in malformed: print(f" - line {line_no}: {reason}") ``` 5. If displaying content is operationally required, apply robust redaction before storage or output. Redaction should cover both conventional `KEY=value` syntax and malformed strings containing token-like values. 6. Add regression tests using malformed lines that contain canary secrets and assert that no part of each canary appears in JSON or terminal output. 7. Document that validator output may be logged and must never contain environment values. ]]>
