Principle:0xSteph Pentest ai Scope Enforcement
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Authorization |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
A non-negotiable safety mechanism that prevents any tool from hitting targets outside the declared scope, enforced at the execution chokepoint so even a hallucinating LLM cannot bypass it.
Description
Scope Enforcement is the principle that offensive security tooling must have a single, unambiguous enforcement point that blocks out-of-scope requests regardless of what the LLM or agent proposes. It solves the legal and ethical problem that unauthorized scanning is not just a bug — it is a crime (CFAA, Computer Misuse Act, equivalents).
The principle is enforced at the SecurityTool.execute() chokepoint, not at the agent level. This means:
- Every tool invocation passes through a scope check before executing
- Wildcard domains (*.example.com), CIDR ranges, and explicit exclusions are supported
- Hostname normalization (lowercase, port-stripped, scheme-stripped) prevents bypass via URL variants
- IP resolution allows hostname-based targets to be checked against CIDR allowlists
- Violations are recorded with timestamp, target, and tool name for audit
The build_enforcer factory seeds the allow-list from engagement targets, then merges explicit allow/exclude entries and config scope. It is fail-closed: if nothing resolves to an allow-list entry, the enforcer denies by default.
Usage
Use this principle when:
- Designing offensive security tooling that takes user-specified targets
- An LLM proposes tool invocations that could target arbitrary hosts
- You need to support bug-bounty programs with complex in-scope/out-of-scope rules
- Legal compliance requires provable scope boundaries (CFAA defense, audit trail)
Theoretical Basis
Scope check is a function:
Hostname matching supports wildcards:
# Abstract matching (NOT real implementation)
def is_allowed(hostname):
for pattern in allowed_domains:
if pattern.startswith("*."):
suffix = pattern[1:] # ".example.com"
if hostname.endswith(suffix) or hostname == pattern[2:]:
return True
elif hostname == pattern:
return True
return False
Contextvar plumbing exposes scope to handlers without threading it through every function:
# Scope is set once per engagement; handlers read it via contextvar
token = set_current_scope(scope_enforcer)
# ... handlers call get_current_scope() ...
reset_current_scope(token)
Practical Guide
- Enforcement at the chokepoint means the LLM cannot bypass scope — it proposes, the gate decides
- Use an allowlist (fail-closed), not a denylist (fail-open)
- Wildcard domains (*.example.com) match the apex and all subdomains
- CIDR ranges work for IP-based targets; hostname targets are DNS-resolved and checked against CIDRs
- The scope contextvar must be reset on exit to prevent leaking scope to the next engagement
Related Pages
Implemented By
- Implementation:0xSteph_Pentest_ai_ScopeEnforcer
- Implementation:0xSteph_Pentest_ai_build_enforcer
- Implementation:0xSteph_Pentest_ai_http_request_mcp
- Implementation:0xSteph_Pentest_ai_import_scope