Skip to content

fix(config): sanitize validation log output to prevent control character injection - #39116

Closed
powermaster888 wants to merge 1 commit into
openclaw:mainfrom
powermaster888:fix/config-log-sanitize
Closed

powermaster888 wants to merge 1 commit into
openclaw:mainfrom
powermaster888:fix/config-log-sanitize

Conversation

@powermaster888

Copy link
Copy Markdown
Contributor

Summary

  • Wraps config validation issue path and message fields with sanitizeTerminalText() before they are logged
  • Prevents ANSI escape sequences, control characters (newlines, carriage returns, tabs), and C1 control characters from being injected into log output via crafted config values
  • Uses the existing sanitizeTerminalText utility from src/terminal/safe-text.ts

Before: Validation issue paths/messages are logged raw — a config with embedded ANSI codes or control characters could corrupt terminal output or inject misleading log lines.

After: All untrusted issue content is sanitized before logging, while the Error object still contains the raw details for programmatic use.

Test plan

  • Verify pnpm build passes
  • Confirm config validation errors still display correctly in logs
  • Verify that a config with embedded control characters (e.g. \x1b[31m in a field name) produces clean log output

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR sanitizes config validation issue path and message fields using the existing sanitizeTerminalText() utility before they appear in log output, closing a terminal control-character injection vector where crafted config values (e.g., ANSI escape sequences in a field name) could corrupt terminal output or inject misleading log lines.

  • Sanitization is applied consistently to both the error-path (invalid config) and the warning-path, and the ConfigValidationIssue type guarantees both fields are string, so the calls are type-safe.
  • However, configPath itself is still passed to deps.logger.error and new Error(...) unsanitized (lines 725–727). On Unix-like systems, file paths can contain arbitrary bytes (excluding / and null), including ANSI sequences, so a maliciously-named config file would still corrupt terminal output. This should also be sanitized for consistency with the PR's stated goal.

Confidence Score: 4/5

  • Safe to merge pending the noted sanitization gap in configPath logging—the vulnerability vector is real but low-risk in practice since OS filesystems rarely permit control characters in paths.
  • The PR correctly addresses the primary attack surface (validation issue fields), and the sanitization logic is sound and type-safe. The unsanitized configPath in log output is a valid consistency gap that should be fixed, but the risk is mitigated by filesystem constraints. The change itself has no functional regression.
  • src/config/io.ts requires attention for unsanitized configPath on lines 725 and 727.

Comments Outside Diff (1)

  1. src/config/io.ts, line 725-727 (link)

    The PR sanitizes iss.path and iss.message before logging, but configPath is still logged unsanitized on both of these lines. On Unix-like systems, file paths can contain arbitrary bytes (excluding / and null), including ANSI escape sequences that could corrupt terminal output.

    For consistency with the PR's security goal, wrap configPath with sanitizeTerminalText():

    And similarly on line 727:

            const error = new Error(`Invalid config at ${sanitizeTerminalText(configPath)}:\n${details}`);
    

Last reviewed commit: 78ff430

steipete added a commit that referenced this pull request Mar 7, 2026
@steipete

steipete commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Landed manually on main.

What I did:

  • Applied the config-validation log sanitization change
  • Added changelog entry with PR + contributor credit
  • Ran full gate before commit: pnpm lint && pnpm build && pnpm test

Landed commit:

  • 4c2cb7305f8bd1646ab0e3dfa8393d50f2e1f58f

Attribution:

Thanks for the contribution.

@steipete steipete closed this Mar 7, 2026
vincentkoc pushed a commit to BryanTegomoh/openclaw-contrib that referenced this pull request Mar 8, 2026
openperf pushed a commit to openperf/moltbot that referenced this pull request Mar 8, 2026
mcaxtr pushed a commit to mcaxtr/openclaw that referenced this pull request Mar 8, 2026
GordonSH-oss pushed a commit to GordonSH-oss/openclaw that referenced this pull request Mar 9, 2026
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 21, 2026
alexey-pelykh added a commit to remoteclaw/remoteclaw that referenced this pull request Mar 21, 2026
…ter injection (openclaw#39116) (#1765)

(cherry picked from commit 4c2cb73)

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Bill <[email protected]>
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants