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

Function checkRuleBasedPermissions

src/utils/permissions/permissions.ts:1077–1162  ·  view source on GitHub ↗
(
  tool: Tool,
  input: { [key: string]: unknown },
  context: ToolUseContext,
)

Source from the content-addressed store, hash-verified

1075 * Caller must pre-check tool.requiresUserInteraction() — step 1e is not replicated.
1076 */
1077export async function checkRuleBasedPermissions(
1078 tool: Tool,
1079 input: { [key: string]: unknown },
1080 context: ToolUseContext,
1081): Promise<PermissionAskDecision | PermissionDenyDecision | null> {
1082 const appState = context.getAppState()
1083
1084 // 1a. Entire tool is denied by rule
1085 const denyRule = getDenyRuleForTool(appState.toolPermissionContext, tool)
1086 if (denyRule) {
1087 return {
1088 behavior: 'deny',
1089 decisionReason: {
1090 type: 'rule',
1091 rule: denyRule,
1092 },
1093 message: `Permission to use ${tool.name} has been denied.`,
1094 }
1095 }
1096
1097 // 1b. Entire tool has an ask rule
1098 const askRule = getAskRuleForTool(appState.toolPermissionContext, tool)
1099 if (askRule) {
1100 const canSandboxAutoAllow =
1101 tool.name === BASH_TOOL_NAME &&
1102 SandboxManager.isSandboxingEnabled() &&
1103 SandboxManager.isAutoAllowBashIfSandboxedEnabled() &&
1104 shouldUseSandbox(input)
1105
1106 if (!canSandboxAutoAllow) {
1107 return {
1108 behavior: 'ask',
1109 decisionReason: {
1110 type: 'rule',
1111 rule: askRule,
1112 },
1113 message: createPermissionRequestMessage(tool.name),
1114 }
1115 }
1116 // Fall through to let tool.checkPermissions handle command-specific rules
1117 }
1118
1119 // 1c. Tool-specific permission check (e.g. bash subcommand rules)
1120 let toolPermissionResult: PermissionResult = {
1121 behavior: 'passthrough',
1122 message: createPermissionRequestMessage(tool.name),
1123 }
1124 try {
1125 const parsedInput = tool.inputSchema.parse(input)
1126 toolPermissionResult = await tool.checkPermissions(parsedInput, context)
1127 } catch (e) {
1128 if (e instanceof AbortError || e instanceof APIUserAbortError) {
1129 throw e
1130 }
1131 logError(e)
1132 }
1133
1134 // 1d. Tool implementation denied (catches bash subcommand denies wrapped

Callers 1

Calls 7

getDenyRuleForToolFunction · 0.85
getAskRuleForToolFunction · 0.85
shouldUseSandboxFunction · 0.85
isSandboxingEnabledMethod · 0.80
logErrorFunction · 0.50

Tested by

no test coverage detected