( context: ValidationContext, )
| 781 | } |
| 782 | |
| 783 | function 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 | |
| 823 | function validateDangerousVariables( |
| 824 | context: ValidationContext, |
nothing calls this directly
no test coverage detected