Skip to content

fix: validate path_script env vars and output to prevent shell injection#422

Open
kexi wants to merge 1 commit into
developfrom
fix/vals
Open

fix: validate path_script env vars and output to prevent shell injection#422
kexi wants to merge 1 commit into
developfrom
fix/vals

Conversation

@kexi
Copy link
Copy Markdown
Owner

@kexi kexi commented Apr 28, 2026

Summary

Defense-in-depth hardening of the path_script execution path so that user-controlled values (branch name, repo name, etc.) cannot smuggle shell metacharacters into a naively written script.

The executePathScript function previously passed VIBE_BRANCH_NAME, VIBE_REPO_NAME, VIBE_SANITIZED_BRANCH, and VIBE_REPO_ROOT to a user script without validation. A branch name containing newlines, NULs, or shell metacharacters could be exploited when the script's author forgot to double-quote variables (or used eval).

Three layers added:

Layer Where Action
1 All four VIBE_* fields Hard-reject ASCII control chars (\x00-\x1f\x7f) with a hex-encoded error
2 branch / repo / sanitizedBranch fields Warn (don't block) on shell metacharacters ($, `, ;, `
3 Script stdout (pre-trim) Hard-reject control chars; allow exactly one trailing newline

A new buildPathScriptEnv collector centralises env construction so adding a future VIBE_* field automatically routes through validation. Layer 3 explicitly excludes path-traversal semantics (tracked separately in #419).

User-facing security guidance is added to vibe-toml.mdx (en/ja).

Fixes #415

Test Plan

  • Added 32 unit tests in packages/core/src/utils/worktree-path-validation.test.ts covering control-char boundaries (\x1f/\x20/\x7e/\x7f), metachar detection, dedup keys, output validation (leading/trailing newline edge cases)
  • Added 10 integration tests in packages/core/src/utils/worktree-path.test.ts covering control-char rejection per field, metachar warnings across multiple fields, dedup behaviour, and stdout rejection
  • All 49 worktree-path tests pass; full pnpm run check:all passes (451 tests, lint, typecheck, docs, video)

Checklist

  • Tests added/updated
  • pnpm run check:all passes
  • Docs updated (if needed)

Fixes #415

Add defense-in-depth validation around the path_script execution path so
that user-controlled values (branch name, repo name, etc.) cannot smuggle
shell metacharacters into a naively written script:

- Reject control characters (0x00-0x1f, 0x7f) in any VIBE_* field
- Warn on shell metacharacters ($, `, ;, |, &, <, >, \, ", ') in branch
  and repo fields, with dedup and an actionable double-quote hint
- Reject control characters in the script's stdout before trimming
- Document the security model in vibe-toml.mdx (en/ja)

Closes #415

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@kexi kexi self-assigned this Apr 28, 2026
@kexi kexi marked this pull request as ready for review April 28, 2026 13:55
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][Critical] Environment variable injection in path script execution

1 participant