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

Function validateDangerousPatterns

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

Source from the content-addressed store, hash-verified

844}
845
846function validateDangerousPatterns(
847 context: ValidationContext,
848): PermissionResult {
849 const { unquotedContent } = context
850
851 // Special handling for backticks - check for UNESCAPED backticks only
852 // Escaped backticks (e.g., \`) are safe and commonly used in SQL commands
853 if (hasUnescapedChar(unquotedContent, '`')) {
854 return {
855 behavior: 'ask',
856 message: 'Command contains backticks (`) for command substitution',
857 }
858 }
859
860 // Other command substitution checks (include double-quoted content)
861 for (const { pattern, message } of COMMAND_SUBSTITUTION_PATTERNS) {
862 if (pattern.test(unquotedContent)) {
863 logEvent('tengu_bash_security_check_triggered', {
864 checkId:
865 BASH_SECURITY_CHECK_IDS.DANGEROUS_PATTERNS_COMMAND_SUBSTITUTION,
866 subId: 1,
867 })
868 return { behavior: 'ask', message: `Command contains ${message}` }
869 }
870 }
871
872 return { behavior: 'passthrough', message: 'No dangerous patterns' }
873}
874
875function validateRedirections(context: ValidationContext): PermissionResult {
876 const { fullyUnquotedContent } = context

Callers

nothing calls this directly

Calls 2

hasUnescapedCharFunction · 0.85
logEventFunction · 0.85

Tested by

no test coverage detected