MCPcopy Create free account
hub / github.com/Noumena-Network/code / matchingRulesForInput

Function matchingRulesForInput

src/tools/BashTool/bashPermissions.ts:938–987  ·  view source on GitHub ↗
(
  input: z.infer<typeof BashTool.inputSchema>,
  toolPermissionContext: ToolPermissionContext,
  matchMode: 'exact' | 'prefix',
  { skipCompoundCheck = false }: { skipCompoundCheck?: boolean } = {},
)

Source from the content-addressed store, hash-verified

936}
937
938function matchingRulesForInput(
939 input: z.infer<typeof BashTool.inputSchema>,
940 toolPermissionContext: ToolPermissionContext,
941 matchMode: 'exact' | 'prefix',
942 { skipCompoundCheck = false }: { skipCompoundCheck?: boolean } = {},
943) {
944 const denyRuleByContents = getRuleByContentsForTool(
945 toolPermissionContext,
946 BashTool,
947 'deny',
948 )
949 // SECURITY: Deny/ask rules use aggressive env var stripping so that
950 // `FOO=bar denied_command` still matches a deny rule for `denied_command`.
951 const matchingDenyRules = filterRulesByContentsMatchingInput(
952 input,
953 denyRuleByContents,
954 matchMode,
955 { stripAllEnvVars: true, skipCompoundCheck: true },
956 )
957
958 const askRuleByContents = getRuleByContentsForTool(
959 toolPermissionContext,
960 BashTool,
961 'ask',
962 )
963 const matchingAskRules = filterRulesByContentsMatchingInput(
964 input,
965 askRuleByContents,
966 matchMode,
967 { stripAllEnvVars: true, skipCompoundCheck: true },
968 )
969
970 const allowRuleByContents = getRuleByContentsForTool(
971 toolPermissionContext,
972 BashTool,
973 'allow',
974 )
975 const matchingAllowRules = filterRulesByContentsMatchingInput(
976 input,
977 allowRuleByContents,
978 matchMode,
979 { skipCompoundCheck },
980 )
981
982 return {
983 matchingDenyRules,
984 matchingAskRules,
985 matchingAllowRules,
986 }
987}
988
989/**
990 * Checks if the subcommand is an exact match for a permission rule

Callers 5

bashToolCheckPermissionFunction · 0.70
checkSandboxAutoAllowFunction · 0.70
checkEarlyExitDenyFunction · 0.70
checkSemanticsDenyFunction · 0.70

Calls 2

getRuleByContentsForToolFunction · 0.85

Tested by

no test coverage detected