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

Function validateJqCommand

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

Source from the content-addressed store, hash-verified

740}
741
742function validateJqCommand(context: ValidationContext): PermissionResult {
743 const { originalCommand, baseCommand } = context
744
745 if (baseCommand !== 'jq') {
746 return { behavior: 'passthrough', message: 'Not jq' }
747 }
748
749 if (/\bsystem\s*\(/.test(originalCommand)) {
750 logEvent('tengu_bash_security_check_triggered', {
751 checkId: BASH_SECURITY_CHECK_IDS.JQ_SYSTEM_FUNCTION,
752 subId: 1,
753 })
754 return {
755 behavior: 'ask',
756 message:
757 'jq command contains system() function which executes arbitrary commands',
758 }
759 }
760
761 // File arguments are now allowed - they will be validated by path validation in readOnlyValidation.ts
762 // Only block dangerous flags that could read files into jq variables
763 const afterJq = originalCommand.substring(3).trim()
764 if (
765 /(?:^|\s)(?:-f\b|--from-file|--rawfile|--slurpfile|-L\b|--library-path)/.test(
766 afterJq,
767 )
768 ) {
769 logEvent('tengu_bash_security_check_triggered', {
770 checkId: BASH_SECURITY_CHECK_IDS.JQ_FILE_ARGUMENTS,
771 subId: 1,
772 })
773 return {
774 behavior: 'ask',
775 message:
776 'jq command contains dangerous flags that could execute code or read arbitrary files',
777 }
778 }
779
780 return { behavior: 'passthrough', message: 'jq command is safe' }
781}
782
783function validateShellMetacharacters(
784 context: ValidationContext,

Callers

nothing calls this directly

Calls 1

logEventFunction · 0.85

Tested by

no test coverage detected