Implementation:0xSteph Pentest ai ensure consent
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Authorization |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Concrete consent gate function that checks, prompts for, or skips the Acceptable Use Policy acceptance required before any network operations.
Description
ensure_consent is the entry point for the AUP consent gate. It returns True if the user has accepted the AUP, False otherwise. The logic:
- Environment override: `PENTEST_AI_AUP_ACCEPTED=1` returns True without prompt or persisting (for non-interactive CI the operator controls)
- File exists: If `~/.pentest-ai/aup-consent.txt` exists and is non-empty, returns True silently
- Interactive prompt: Displays the AUP text; user must type 'yes' to accept and persist
- Non-interactive + no file: Returns False
The consent file is the legal artifact — a clickwrap-equivalent contract with ISO timestamp, AUP version, and URL. It is chmod 0600 (user-only read) on POSIX.
Supporting functions:
- has_consent: Checks if the consent file exists and is non-empty
- grant_consent: Writes the consent file with timestamp + version + URL
- revoke_consent: Deletes the consent file (re-prompts on next run)
- banner_text: One-line authorized-use banner for engagement headers
Usage
Import this when you need to:
- Gate engagement start behind AUP consent (CLI `ptai start`, MCP `start_engagement`)
- Check consent status in CI/CD pipelines
- Display the authorization banner
Code Reference
Source Location
- Repository: pentest-ai
- File: engine/aup_consent.py
Signature
CONFIG_DIR = Path(os.environ.get("PENTEST_AI_CONFIG_DIR", str(Path.home() / ".pentest-ai")))
CONSENT_PATH = CONFIG_DIR / "aup-consent.txt"
AUP_VERSION = "1.0"
def has_consent() -> bool:
def grant_consent() -> None:
def revoke_consent() -> None:
def ensure_consent(interactive: bool = True) -> bool:
"""Return True if the user has accepted the AUP, False otherwise."""
def banner_text() -> str:
Import
from engine.aup_consent import ensure_consent, has_consent, grant_consent, revoke_consent, banner_text
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| interactive | bool | No | True for terminal prompt, False for CI (default: True) |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | bool | True if consent exists/accepted, False otherwise |
Usage Examples
Interactive Consent (CLI)
from engine.aup_consent import ensure_consent, banner_text
print(banner_text())
if not ensure_consent(interactive=True):
print("AUP not accepted; exiting.")
sys.exit(1)
# Proceed with engagement
Non-Interactive CI
from engine.aup_consent import ensure_consent
# In CI, set PENTEST_AI_AUP_ACCEPTED=1 in the environment
# ensure_consent reads the env var and returns True without prompting
if not ensure_consent(interactive=False):
print("AUP not accepted. Set PENTEST_AI_AUP_ACCEPTED=1 for CI.")
sys.exit(1)