Implementation:0xSteph Pentest ai SecureCredential
| Knowledge Sources | |
|---|---|
| Domains | Security, Credential_Management, CLI |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Concrete tool for in-memory credential holding that refuses to leak via repr, str, JSON serialization, or pickling, provided by the pentest-ai CLI module.
Description
The SecureCredential class wraps a resolved credential value (password, token, etc.) and never exposes it via repr/str/JSON serialization. The only way to read the value is via .reveal(), which is a deliberate explicit call that's easy to grep for in review. Security invariants: repr/str return "[REDACTED]", json.dumps refuses to serialize (TypeError), logging yields "[REDACTED]", pickling is refused (TypeError), and the wrapped value is stored in a private slot attribute.
Usage
Import this class when you need to hold resolved credentials in memory safely. Used by cli.auth_profiles.resolve() and credential resolvers to wrap secret values.
Code Reference
Source Location
- Repository: 0xSteph_Pentest_ai
- File: cli/secure_credential.py
- Lines: 1-70
Signature
class SecureCredential:
__slots__ = ("_value", "_source", "_ref")
def __init__(self, value: str, source: str = "", ref: str = "") -> None: ...
def reveal(self) -> str: ...
@property
def source(self) -> str: ...
@property
def ref(self) -> str: ...
def __repr__(self) -> str: ...
def __str__(self) -> str: ...
def __bool__(self) -> bool: ...
def __eq__(self, other: Any) -> bool: ...
def __hash__(self) -> int: ...
def __reduce__(self) -> Any: ... # raises TypeError
def __getstate__(self) -> Any: ... # raises TypeError
Import
from cli.secure_credential import SecureCredential
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| value | str | Yes | The credential value to wrap |
| source | str | No | Resolver source (env, op, vault, aws-sm) |
| ref | str | No | Reference used to fetch the credential |
Outputs
| Name | Type | Description |
|---|---|---|
| reveal() | str | The underlying credential value (use sparingly) |
| source | str | The resolver source |
| ref | str | The reference used to fetch |
Usage Examples
Wrap and Use a Credential
from cli.secure_credential import SecureCredential
import json
cred = SecureCredential("my-secret-password", source="env", ref="DB_PASSWORD")
# Safe operations:
print(repr(cred)) # SecureCredential(source='env', ref='DB_PASSWORD', value=[REDACTED])
print(str(cred)) # [REDACTED]
print(bool(cred)) # True
print(cred.source) # env
print(cred.ref) # DB_PASSWORD
# The only way to get the value:
password = cred.reveal() # "my-secret-password"
# Serialization refused:
# json.dumps(cred) # TypeError
# pickle.dumps(cred) # TypeError