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:0xSteph Pentest ai build enforcer

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Authorization
Last Updated 2026-10-23 12:00 GMT

Overview

Concrete factory function that builds a ScopeEnforcer from CLI/MCP engagement parameters, seeding the allow-list from engagement targets and merging explicit allow/exclude entries and config scope.

Description

build_enforcer is the factory used by the CLI (`ptai start`) and MCP server (`start_engagement`) to construct a ScopeEnforcer from engagement parameters. It:

  • Seeds the allow-list: Extracts the hostname from each engagement target (URLs collapse to hostname, CIDRs and bare IPs pass through)
  • Merges explicit allow/exclude: From `--scope-allow` / `--scope-exclude` CLI flags
  • Merges config scope: From `config.scope.allowed_targets` / `config.scope.excluded_targets`
  • Fail-closed: If nothing resolves to an allow-list entry, the returned enforcer denies by default

Wildcard and CIDR patterns in the allow/exclude lists are passed through verbatim so the enforcer's own wildcard/CIDR handling applies.

Usage

Import this when you need to:

  • Build a scope enforcer from CLI parameters or MCP engagement options
  • Construct the enforcer for a playbook engagement

Code Reference

Source Location

Signature

def build_enforcer(
    targets: str | list[str] | None = None,
    *,
    allowed: list[str] | None = None,
    excluded: list[str] | None = None,
    allowed_ports: list[int] | None = None,
    config_scope: dict[str, Any] | None = None,
    mode: str = "strict",
) -> ScopeEnforcer:
    """Build a ScopeEnforcer for a CLI/MCP engagement.

    Seeds the allow-list with the host of each engagement target, then merges
    explicit allow/exclude entries and any config.scope.
    """

Import

from engine.scope import build_enforcer

I/O Contract

Inputs

Name Type Required Description
targets list[str] | None No Engagement target(s)
allowed None No Explicit in-scope entries (--scope-allow)
excluded None No Explicit out-of-scope entries (--scope-exclude)
allowed_ports None No Allowed port list
config_scope None No Config scope with allowed_targets/excluded_targets
mode str No strict/permissive (default: strict)

Outputs

Name Type Description
returns ScopeEnforcer Fail-closed enforcer (denies if no allow-list)

Usage Examples

Building from CLI Parameters

from engine.scope import build_enforcer

# From ptai start --target https://app.example.com --scope-allow *.example.com --scope-exclude admin.example.com
enforcer = build_enforcer(
    targets="https://app.example.com",
    allowed=["*.example.com"],
    excluded=["admin.example.com"],
    mode="strict",
)
# app.example.com is allowed (seeded from target + wildcard match)
# admin.example.com is excluded
# evil.com is denied (not in allow-list)

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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