MCPcopy Create free account
hub / github.com/freecodexyz/free-code / validateShellMetacharacters

Function validateShellMetacharacters

src/tools/BashTool/bashSecurity.ts:783–821  ·  view source on GitHub ↗
(
  context: ValidationContext,
)

Source from the content-addressed store, hash-verified

781}
782
783function validateShellMetacharacters(
784 context: ValidationContext,
785): PermissionResult {
786 const { unquotedContent } = context
787 const message =
788 'Command contains shell metacharacters (;, |, or &) in arguments'
789
790 if (/(?:^|\s)["'][^"']*[;&][^"']*["'](?:\s|$)/.test(unquotedContent)) {
791 logEvent('tengu_bash_security_check_triggered', {
792 checkId: BASH_SECURITY_CHECK_IDS.SHELL_METACHARACTERS,
793 subId: 1,
794 })
795 return { behavior: 'ask', message }
796 }
797
798 const globPatterns = [
799 /-name\s+["'][^"']*[;|&][^"']*["']/,
800 /-path\s+["'][^"']*[;|&][^"']*["']/,
801 /-iname\s+["'][^"']*[;|&][^"']*["']/,
802 ]
803
804 if (globPatterns.some(p => p.test(unquotedContent))) {
805 logEvent('tengu_bash_security_check_triggered', {
806 checkId: BASH_SECURITY_CHECK_IDS.SHELL_METACHARACTERS,
807 subId: 2,
808 })
809 return { behavior: 'ask', message }
810 }
811
812 if (/-regex\s+["'][^"']*[;&][^"']*["']/.test(unquotedContent)) {
813 logEvent('tengu_bash_security_check_triggered', {
814 checkId: BASH_SECURITY_CHECK_IDS.SHELL_METACHARACTERS,
815 subId: 3,
816 })
817 return { behavior: 'ask', message }
818 }
819
820 return { behavior: 'passthrough', message: 'No metacharacters' }
821}
822
823function validateDangerousVariables(
824 context: ValidationContext,

Callers

nothing calls this directly

Calls 1

logEventFunction · 0.85

Tested by

no test coverage detected