MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / checkPermissions

Function checkPermissions

source code/tools/SkillTool/SkillTool.ts:434–580  ·  view source on GitHub ↗
(
    { skill, args },
    context,
  )

Source from the content-addressed store, hash-verified

432 },
433
434 async checkPermissions(
435 { skill, args },
436 context,
437 ): Promise<PermissionDecision> {
438 // Skills are just skill names, no arguments
439 const trimmed = skill.trim()
440
441 // Remove leading slash if present (for compatibility)
442 const commandName = trimmed.startsWith('/') ? trimmed.substring(1) : trimmed
443
444 const appState = context.getAppState()
445 const permissionContext = appState.toolPermissionContext
446
447 // Look up the command object to pass as metadata
448 const commands = await getAllCommands(context)
449 const commandObj = findCommand(commandName, commands)
450
451 // Helper function to check if a rule matches the skill
452 // Normalizes both inputs by stripping leading slashes for consistent matching
453 const ruleMatches = (ruleContent: string): boolean => {
454 // Normalize rule content by stripping leading slash
455 const normalizedRule = ruleContent.startsWith('/')
456 ? ruleContent.substring(1)
457 : ruleContent
458
459 // Check exact match (using normalized commandName)
460 if (normalizedRule === commandName) {
461 return true
462 }
463 // Check prefix match (e.g., "review:*" matches "review-pr 123")
464 if (normalizedRule.endsWith(':*')) {
465 const prefix = normalizedRule.slice(0, -2) // Remove ':*'
466 return commandName.startsWith(prefix)
467 }
468 return false
469 }
470
471 // Check for deny rules
472 const denyRules = getRuleByContentsForTool(
473 permissionContext,
474 SkillTool as Tool,
475 'deny',
476 )
477 for (const [ruleContent, rule] of denyRules.entries()) {
478 if (ruleMatches(ruleContent)) {
479 return {
480 behavior: 'deny',
481 message: `Skill execution blocked by permission rules`,
482 decisionReason: {
483 type: 'rule',
484 rule,
485 },
486 }
487 }
488 }
489
490 // Remote canonical skills are ant-only experimental — auto-grant.
491 // Placed AFTER the deny loop so a user-configured Skill(_canonical_:*)

Callers

nothing calls this directly

Calls 6

findCommandFunction · 0.85
getRuleByContentsForToolFunction · 0.85
ruleMatchesFunction · 0.85
entriesMethod · 0.80
getAllCommandsFunction · 0.70

Tested by

no test coverage detected