Implementation:0xSteph Pentest ai replay capsule
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Verification |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Concrete function that re-runs a capsule's oracle against the live target to independently re-confirm the verdict, with fail-closed scope enforcement.
Description
replay_capsule re-builds the oracle from the capsule's finding and verification recipe, then runs the real verifier to earn a fresh Receipt. This IS the trust mechanism: a skeptic replays the recipe against the live target and watches the verdict re-confirm.
Scope contract (fail-closed): replay drives live requests at hosts read from possibly-hostile capsule JSON. Before building or running any oracle, EVERY host the oracle could request (finding target + recipe URL fields: url, victim_url, url_template) must appear in allowed_hosts. If allowed_hosts is None, it refuses outright — there is no implicit "replay anywhere" mode.
Defense-in-depth: when exactly one host is allowed, the session gets a strict_scope context so the primitive layer blocks any off-host request even if a future oracle followed a cross-host redirect.
OAST capsules are not live-replayable (the original out-of-band callback cannot be re-triggered); replay returns None for those.
Usage
Import this when you need to:
- Independently verify a capsule's verdict by replaying it
- Re-confirm findings during retest
- Allow a third party to verify your proof
Code Reference
Source Location
- Repository: pentest-ai
- File: engine/capsule.py
Signature
class CapsuleScopeError(Exception):
"""Raised when a capsule replay targets a host outside the allowlist."""
async def replay_capsule(
capsule: dict[str, Any],
session: Any,
intensity: str = "normal",
allowed_hosts: list[str] | None = None,
) -> Receipt | None:
"""Re-run the capsule's oracle against the live target.
Returns None for non-replayable capsules (OAST).
Raises CapsuleScopeError if any request host is off-allowlist."""
Import
from engine.capsule import replay_capsule, CapsuleScopeError
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| capsule | dict[str, Any] | Yes | Capsule dict from build_capsule |
| session | Any | Yes | aiohttp.ClientSession |
| intensity | str | No | Replay N: stealth=2, normal=3, aggressive=5 |
| allowed_hosts | None | Yes | Hostname allowlist (fail-closed; None = refuse) |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | None | Fresh Receipt re-confirming verdict; None for OAST |
| raises | CapsuleScopeError | If any request host is off the allowlist |
Usage Examples
Replaying a Capsule
import aiohttp
from engine.capsule import replay_capsule, CapsuleScopeError
async with aiohttp.ClientSession() as session:
try:
receipt = await replay_capsule(
capsule=my_capsule,
session=session,
intensity="normal",
allowed_hosts=["vulnerable-app.example.com"],
)
if receipt is None:
print("OAST capsule — not live-replayable")
elif receipt.verdict.value == "verified":
print("Verdict re-confirmed!")
else:
print(f"Replay could not re-prove: {receipt.verdict}")
except CapsuleScopeError as e:
print(f"Refused: {e}")