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:3641397194 wq Gpt6 Astra scopeCheck

From Leeroopedia
Knowledge Sources
Domains Security, Access_Control, AI_Safety
Last Updated 2026-10-26 12:00 GMT

Overview

Concrete tool for validating AI-selected tool arguments against the declared target scope, preventing autonomous agents from operating outside user-specified boundaries.

Description

The scopeCheck function is the safety gate between an AI model's tool-selection decision and actual tool execution. It validates four categories of arguments — URLs, hosts, files, and IDA requirements — against the declared target and the accumulated `derived` set of files created during the current agent session.

The function throws an `Error` if any argument escapes scope; it returns `void` on pass. The errors are caught by the `runAgent` loop and recorded as failed calls, allowing the model to see the scope violation and adjust.

Usage

  • Agent loop: called by `runAgent` before `engine.execute` on every tool decision.
  • Direct validation: can be called directly to validate arguments before manual tool execution.
  • Testing: the `derived` Set parameter allows testing scope expansion without running the full agent loop.

Code Reference

Source Location

Signature

function scopeCheck(name, args, target, derived = new Set(), idaUrl) -> void
// Throws Error on scope escape; returns void on pass.

Import

const { scopeCheck } = require('./toolbox/agent');

I/O Contract

Inputs

Name Type Required Description
name string Yes Tool name (e.g., 'inspect_http', 'ida_call', 'run_workflow')
args object Yes /// Tool arguments to validate
target string Yes Declared target URL or file path; throws if missing
derived Set No Set of derived file paths (created by prior tools); default: empty Set
idaUrl string No IDA MCP server URL; required for ida_ tools

Outputs

Name Type Description
returns void Passes (returns undefined) if all arguments are in scope
throws Error Throws if any argument escapes scope (message describes the violation)

Usage Examples

Web URL Scope

const { scopeCheck } = require('./toolbox/agent');

const target = 'https://example.com';
const derived = new Set();

// Valid: same origin
scopeCheck('inspect_http', { url: 'https://example.com/path/page' }, target, derived);

// Valid: different path, same origin
scopeCheck('crawl_site', { url: 'https://example.com/blog' }, target, derived);

// Invalid: different origin
try {
  scopeCheck('inspect_http', { url: 'https://evil.com' }, target, derived);
} catch (error) {
  console.log(error.message); // 'AI 地址超出本次目标'
}

Host Scope

const { scopeCheck } = require('./toolbox/agent');

// Valid: host matches target hostname
scopeCheck('resolve_host', { host: 'example.com' }, 'https://example.com', new Set());

// Invalid: host differs
try {
  scopeCheck('resolve_host', { host: 'evil.com' }, 'https://example.com', new Set());
} catch (error) {
  console.log(error.message); // 'AI 主机超出本次目标'
}

// Valid: IPv6 with brackets
scopeCheck('scan_ports', { host: '[::1]' }, 'http://[::1]:8080', new Set());

File Scope with Derived Set

const { scopeCheck } = require('./toolbox/agent');

const target = 'samples/abc123-suspicious.exe';
const derived = new Set(['patched/uuid1-suspicious.exe']);

// Valid: file is the target
scopeCheck('analyze_binary', { file: target }, target, derived);

// Valid: 'other' is a derived file (created by patch_bytes)
scopeCheck('diff_files',
  { file: target, other: 'patched/uuid1-suspicious.exe' },
  target, derived);

// Invalid: file is neither target nor derived
try {
  scopeCheck('analyze_binary', { file: '/etc/passwd' }, target, derived);
} catch (error) {
  console.log(error.message); // 'AI 文件超出本次样本与派生文件'
}

IDA Scope

const { scopeCheck } = require('./toolbox/agent');

const idaUrl = 'http://localhost:13337/mcp';

// Valid: ida_ tool with matching url
scopeCheck('ida_connect', { url: idaUrl }, 'samples/sample.exe', new Set(), idaUrl);

// Invalid: ida_ tool without idaUrl
try {
  scopeCheck('ida_call', { name: 'get_function_list' }, 'samples/sample.exe', new Set());
} catch (error) {
  console.log(error.message); // '本次任务未设置 IDA 地址'
}

// Invalid: ida url mismatch
try {
  scopeCheck('ida_connect', { url: 'http://evil:13337/mcp' },
    'samples/sample.exe', new Set(), idaUrl);
} catch (error) {
  console.log(error.message); // 'AI IDA 地址超出本次设置'
}

Related Pages

Implements Principle

Requires Environment

Page Connections

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