Skip to content

fix: reject control characters in PATH_TO_CLAUDE_CODE_EXECUTABLE#1161

Closed
qozle wants to merge 1 commit into
anthropics:mainfrom
qozle:fix/github-path-injection
Closed

fix: reject control characters in PATH_TO_CLAUDE_CODE_EXECUTABLE#1161
qozle wants to merge 1 commit into
anthropics:mainfrom
qozle:fix/github-path-injection

Conversation

@qozle

@qozle qozle commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Problem

PATH_TO_CLAUDE_CODE_EXECUTABLE is passed through dirname() and written directly to the GITHUB_PATH file without sanitizing control characters:

const claudeDir = dirname(customExecutable);
await appendFile(githubPath, `${claudeDir}\n`);

GITHUB_PATH is newline-delimited — each line becomes a directory added to PATH for subsequent steps. If customExecutable contains an embedded newline (e.g. set from an untrusted workflow input), dirname() passes it through and appendFile writes two lines, injecting an attacker-controlled directory into the runner PATH for all subsequent job steps.

Fix

Add a fail-closed guard before the appendFile call that throws if claudeDir contains any control characters (\x00–\x1f, \x7f):

if (/[\x00-\x1f\x7f]/.test(claudeDir)) {
  throw new Error(
    `PATH_TO_CLAUDE_CODE_EXECUTABLE contains invalid control characters: ${JSON.stringify(claudeDir)}`,
  );
}

Fail-closed rather than silently stripping: a path with embedded control characters is almost certainly a misconfiguration or injection attempt. Throwing loudly is better than quietly sanitizing and continuing — the latter hides the problem.

All 653 existing tests continue to pass.

Fixes #1160

An embedded newline in PATH_TO_CLAUDE_CODE_EXECUTABLE would propagate
through dirname() and be written to GITHUB_PATH, injecting an attacker-
controlled directory into the runner PATH for all subsequent job steps.

Add a fail-closed guard that throws if the derived claudeDir contains
any control characters (0x00-0x1f, 0x7f). A valid filesystem path
should never contain these; rejecting loudly is better than silent
sanitization that hides misconfiguration.

Fixes anthropics#1160

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@qozle

qozle commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Closing — duplicate of #1185 which was already merged.

@qozle qozle closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: PATH_TO_CLAUDE_CODE_EXECUTABLE newline injection into GITHUB_PATH

1 participant