ScopeGuard architecture

A browser console, any WebSocket client, or another agent over MCP / A2A starts a scan; the FastAPI server queues it and runs the 15-step LangGraph pipeline. Every route ends in a tamper-evident audit record.

target sends in-scope requests to the website LLM calls Groq (optional, offline fallback) sandbox runs isolated human pauses for the operator disk writes under data/
Browser console · uv run pentest-agentone-time sign-in link → RS256 JWT in sessionStorage; strict CSP, no inline code; live counts merged per issue + URL like the report; parallel scan steps shown running side by side; risk grade = critical×10 + high×6 + medium×3 + low×1 (tooltip)
WebSocket clientscripts/ws_client.py · Postman · any WS client
Operator (human in the loop)picks what to test (website, code, both), signs in to SSO / enters the MFA code, gives the code when a scan pauses
Coding assistants · other agentsMCP (stdio via .mcp.json, or HTTP) · A2A 1.0; credentials by profile name only
JWT + scan request ↓   ·   ↑ queued · phase_update · input_required · complete + report URLs   ·   auth_response ↓

FastAPI server · websocket_server.py

/auth/token · /refreshRS256 JWT, single-use refresh, roles per client (RBAC) + per-subject attributes (ABAC)
/ws?session_id=…verify JWT · same-origin only · strict input · RBAC + ABAC · per-user 5-min result cache (replays the earlier report and its totals; force_refresh scans again) · sign-in pauses
/ · /ui/* · /api/*whitelisted console files; /api/info, /api/reports, /api/audit?trail=scans|code (audit:read)
/api/uploadsstore source code for a scan's code SAST step: .zip (name, MIME, signature) or code files (/api/uploads/files); Python only for now · analysed only in a scan's code_sast step (with the website, or code only) · pre-guardrails · Kubernetes Job (Python sandbox fallback, egress blocked) · post-guardrails · remediation
/reports/…no-script CSP viewer; HttpOnly cookie, never a token in the URL
/mcp · /a2aagent endpoints (scan_service.py): operator allowlist · JWT principal · task owner · untrusted output
Admission queues · admission.py1 scan and 1 HTTP call at a time (server-wide), 50 more wait in order, then 429; queued clients get their position every 5 s. Requests rejected before the graph are still audited.

LangGraph pipeline · graph.py · graph.astream(), thread = session_id

validaterefuses → audit
guardrails.py · rbac.py · abac.py · report_access.py · netpolicy.pyauthorization; per-user targets / profiles / scopes; own reports only; scope = host + www + allowed; metadata / link-local / reserved IPs refused
no network
choose_scopeinterrupt() · human in the loop
what to test: website + code · website only · code onlybefore any request; paused + checkpointed (or named: scan_scope); code scopes need scan:source; code only skips recon: auth, sandbox_check, dast and the probes pass straight on, so no request goes to any website (URL optional)
humanno network
reconcrawl + discovery
tools/recon.py · discovery.pyin-scope pages, robots, sitemap, .well-known; file links never fetched; ≤3 requests at once, each page once (no #fragment copies), one request fewer after each 429 / 5xx / slow answer (3 → 2 → 1); a failed page retried 3 times
target
authJWT · form login · SSO/MFA detection
tools/auth_flow.py · auth_detect.pynever signs in to identity providers; an MFA page is not a login
target
auth_challengeinterrupt() · human in the loop
SSO: hand over the session · MFA: one-time codepaused + checkpointed; answer validated; timeout → unauthenticated
humantarget
code_sourceinterrupt() · human in the loop
SAST step: code files · .zip · public .git link (+ branch/tag) · skippaused + checkpointed; pre-guardrails: authorization, scan:source, owner · git: .git link, allowlisted host, network policy, ls-remote reachable + ref exists, hardened shallow clone (1 retry) · then starts code_sast ∥ JS check ∥ dast in parallel (LangGraph Send, CPU count, 1-4 at once)
human
code_sastyour source code, sandboxed
code_upload.analyse_for_scan → Kubernetes Job (or the Python process sandbox)pre/post guardrails (sandbox + code step); no network; non-Python files marked partial; .exe/.bat/.cmd = warnings, .sh = notes; PEP 8 + ruff lint rules for Python; then code_tools on the host (static, never run): ruff, mypy, bandit, radon, semgrep + pip-audit on pinned requirements (only network: the vulnerability DB); one report · parallel with sandbox_check and dast
sandbox
sastonly if sandbox check is off
subagents/sast_subagent.py (subgraph)skipped while sandbox_check runs the same JavaScript rules
target
sandbox_checkwebsite JS SAST · parallel
Kubernetes Job scopeguard-job-<session_id>source + page/script text as a zip on stdin; deny-all NetworkPolicy; memory 5x, 10x on OOM retry (resumes from checkpoint); deleted after · no kubectl (auto-check at start) or cluster not ready → Python process sandbox
targetsandbox
dastsandboxed child process · parallel
scopeguard sandbox.py → worker.py → engine.pystarts from recon's pages, up to MAX_CRAWL_PAGES (60); failed pages retried 3 times; python -I, audit hook, pinned egress IPs; GET/HEAD/OPTIONS/TRACE; session cookie/bearer; headers, CORS, exposed files, GraphQL introspection, SRI, XSS/SSTI/SQLi/CRLF … (docs/SECURITY_CHECKS.md)
targetsandbox
plan_probesjoins the parallel scans · LLM plan
code_exec.plan_probes → codegen_subagent.pylarge context chunked (10% overlap) + summarized until it fits one chunk, then extracted as a validated ProbePlan of whitelisted probes, stored in state · deferred: runs once, after every scan branch; LLM steps from here on are sequential
LLM
run_probesruns the stored plan
tools/probe_runner.pyre-validates the plan; GET/OPTIONS only, no generated code; timeouts retried (tenacity: up to 5 tries, backoff 2-16 s, at least Retry-After, 180 s budget per scan)
target
aggregatedeterministic
pentest_agent/dedupe.py · scopeguard/citations.pyone finding per issue + URL (merged duplicates, highest severity), red flags, built-in summary citing [Sn]
reporthtml · md · json · docx
tools/report_tool.py · scopeguard report / docx_reportall four formats from the same structured data
disk
auditevery route ends here
audit_log.py → scopeguard/audit.pyhash-chained (HMAC) JSONL record: who, what, outcome, sign-in result, report hashes; no secrets
disk

Each step picks the next with Command(goto). State is checkpointed after every step (AES-encrypted with CHECKPOINT_ENCRYPTION_KEY), so {"resume": true} continues a run, including one paused for sign-in. A step past AGENT_MAX_ITERATIONS is skipped and the run moves on to the report and the audit record.

Outside the server

HTTP requests, in scope only
Target website
  • links outside scope recorded, never fetched
  • every connection: resolve → check IP → connect to that IP (no DNS rebinding)
  • cloud metadata / link-local always blocked
  • no file downloads; text capped, binaries discarded unread
  • 429 → Retry-After; no redirects followed
human in the loop
Operator's own browser
  • SSO sign-in at the identity provider
  • hands back only the target session
  • IdP password and MFA factor never reach the agent
optional
Groq LLM · llm.py
  • plan_probes only (the report keeps aggregate's cited summary)
  • ≤ PROBE_CONTEXT_CHUNK_CHARS (4000) of data per request; more is chunked, summarized, extracted
  • 413: limit learned, rebuilt smaller (tenacity, 3 tries)
  • paced to Groq's per-minute budget (x-ratelimit headers): waits for the reset instead of a 429
  • 429: waits exactly what Groq asks, 5 retries, ≤ 120 s, then fallback
  • ≥ 60 s between two summary calls (LLM_SUMMARY_DELAY_SECONDS)
  • no key or prompt file → deterministic output
optional
LangSmith
  • one trace per scan; tokens, keys, passwords, cookies redacted
local disk · data/
Files the server writes
  • reports/<session_id>/report.*
  • checkpoints/main.sqlite (AES at rest; async aiosqlite, WAL + busy timeout: server and MCP/A2A scans write it concurrently; older than CHECKPOINT_RETENTION_HOURS (24) deleted + VACUUM)
  • audit/audit.jsonl (pentest-audit verify)
  • audit/code_audit.jsonl (pentest-audit --trail code verify)
  • uploads/<id>/ (archive until scanned, checkpoint)
  • logs/pentest-agent.log