Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIPentest CyberStrikeAI mcpToolAuthorizer

From Leeroopedia
Knowledge Sources
Domains Security, Authorization
Last Updated 2026-10-19 04:10 GMT

Overview

Concrete tool for per-tool RBAC authorization provided by the internal/app package.

Description

mcpToolAuthorizer returns a closure that, given a context, tool name, and args map, resolves the authenticated principal and checks the required permission + resource + project boundary for each builtin tool. externalMCPToolAuthorizer is the coarser gate for federated tools: it requires mcp:external:execute with global scope. The builtin switch covers webshell (read/write/delete), vulnerability (read/write), asset (read/write/delete), project fact (read/write), knowledge, C2 (read/write/delete by action), batch tasks, monitor, and agent execution. Builtin tools with no registered policy are refused; non-builtin tools require agent:local-execute.

Usage

  • First engagement: invoked before MCP tool execution to enforce per-tool permissions.
  • HITL pre-check: called alongside toolguard.Check before the HITL gate.
  • External MCP federation: externalMCPToolAuthorizer gates federated tool calls with the global-scope permission.

Code Reference

Source Location

  • Repository: CyberStrikeAI
  • File: internal/app/mcp_authorization.go
  • Lines: mcpToolAuthorizer L15-230, externalMCPToolAuthorizer L232-249, authorizeC2Action L251+

Signature

func mcpToolAuthorizer(db *database.DB) func(ctx context.Context, toolName string, args map[string]interface{}) error

func externalMCPToolAuthorizer() func(ctx context.Context, toolName string, args map[string]interface{}) error

func authorizeC2Action(ctx context.Context, principal authctx.Principal, db *database.DB,
    args map[string]interface{}, resourceType, argument string) error

func authorizeMCPProjectResourceBoundary(ctx context.Context, db *database.DB,
    resourceType, resourceID string) error

func authorizeProjectTool(ctx context.Context, principal authctx.Principal,
    db *database.DB, permission string) error

Import

// internal package — invoked via app.New wiring, not imported directly by callers

I/O Contract

Inputs

Name Type Required Description
db *database.DB Yes RBAC store for resource access checks
ctx context.Context Yes Carries authenticated principal + project filter
toolName string Yes Builtin or external tool name
args map[string]interface{} Yes Tool args (resource ID extracted by argument key)

Outputs

Name Type Description
returns error Nil = allow; descriptive error = deny

Usage Examples

Webshell Write Authorization

authz := mcpToolAuthorizer(db)
err := authz(ctx, "webshell_exec", map[string]interface{}{
    "connection_id": "conn-123",
})
// Checks: principal.HasPermission("webshell:write")
//   and db.UserCanAccessResource(uid, scope, "webshell", "conn-123")
//   and authorizeMCPProjectResourceBoundary(ctx, db, "webshell", "conn-123")

External MCP Tool Gate

extAuthz := externalMCPToolAuthorizer()
err := extAuthz(ctx, "external_tool_name", nil)
// Requires: principal.HasPermission("mcp:external:execute")
//   and ScopeFor(...) == database.RBACScopeAll

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment