Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xSteph Pentest ai SecureCredential

From Leeroopedia
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

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

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment