Implementation:0xSteph Pentest ai build capsule
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Verification |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Concrete function that assembles a tamper-evident portable proof capsule for one verified finding, bundling the finding, its verification recipe, and the verifier's receipt with a SHA-256 integrity digest.
Description
build_capsule creates a self-contained JSON capsule from a verified finding and its Receipt. The capsule is the share-unit of the "no proof, no finding" philosophy — anyone can replay it against the live target and watch the oracle re-confirm the verdict.
The capsule includes:
- Finding subset: id, title, target, severity, bug_class, evidence (truncated to 2000 chars), verification_recipe
- Receipt: The full receipt data (verdict, oracle_kind, evidence, replay)
- Integrity SHA-256: SHA-256 over the canonical JSON with the integrity field removed (drift-detection, not adversarial authenticity)
Authenticity comes from re-running the proof, not from the digest. The system deliberately does not sign capsules.
Usage
Import this when you need to:
- Bundle a verified finding into a portable, replayable artifact
- Share proof with third parties (bug-bounty triagers, auditors)
- Persist a tamper-evident record of a verified finding
Code Reference
Source Location
- Repository: pentest-ai
- File: engine/capsule.py
Signature
CAPSULE_SCHEMA_VERSION = 1
def build_capsule(
finding: dict[str, Any],
receipt: Any,
*,
ptai_version: str = "",
created_at: str | None = None,
) -> dict[str, Any]:
"""Assemble a portable proof capsule for one verified finding."""
def capsule_integrity(capsule: dict[str, Any]) -> str:
"""sha256 over the canonical capsule with integrity field removed."""
def verify_capsule_integrity(capsule: dict[str, Any]) -> bool:
"""True if the stored integrity_sha256 matches a fresh computation."""
def is_replayable(capsule: dict[str, Any]) -> bool:
"""True if capsule has a recipe and an http target."""
Import
from engine.capsule import build_capsule, capsule_integrity, verify_capsule_integrity, is_replayable
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| finding | dict[str, Any] | Yes | Verified finding with id, title, target, severity, bug_class, evidence, verification_recipe |
| receipt | Any | Yes | Receipt object or dict |
| ptai_version | str | No | Version string for the capsule |
| created_at | None | No | Timestamp (caller stamps time; engine stays deterministic) |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | dict[str, Any] | Capsule with capsule_schema_version, ptai_version, created_at, finding, receipt, integrity_sha256 |
Usage Examples
Building and Verifying a Capsule
from engine.capsule import build_capsule, verify_capsule_integrity
from datetime import datetime, timezone
# 1. Build the capsule after verification
capsule = build_capsule(
finding=verified_finding,
receipt=receipt,
ptai_version="0.20.0",
created_at=datetime.now(timezone.utc).isoformat(),
)
# 2. Verify integrity (drift detection)
assert verify_capsule_integrity(capsule)
# 3. Check if replayable
if is_replayable(capsule):
print("Capsule can be re-proven against the live target")