Skip to content

hypnguyen1209/offensive-claude / skills/vulnerability-analysis

vulnerability-analysis

Unverified

Use when auditing source code for vulnerabilities — drive CodeQL/Semgrep/Joern to taint untrusted data source-to-sink across injection, memory safety, deserialization/prototype-pollution, secrets/crypto/authz/race, and supply-chain risks

scripts/provenance.py

View on GitHub
#!/usr/bin/env python3
"""provenance.py - per-hop provenance for a reachability path, and the "weakest hop" rule.

A source-to-sink / reachability path is a chain of hops. graphify's rule: how each hop was
established decides how much it can be trusted:

  EXTRACTED  - a literal, resolvable call/edge in the code (e.g. `foo()` where `foo` is defined and
               the call site is a concrete `foo(` token). The strongest.
  INFERRED   - bridged by a name/resolver heuristic (dispatch table, duck-typed interface, a
               same-name method picked across classes). Plausible, not proven.
  AMBIGUOUS  - an unresolved indirect edge (function pointer, reflection, dynamic import, vtable we
               could not resolve). The weakest - could be wrong.

THE RULE: a path is only as strong as its WEAKEST hop. A CONFIRMED reachability claim requires an
all-EXTRACTED path; a single INFERRED hop caps the finding at POSSIBLE, and AMBIGUOUS is weaker
still. This is fail-CLOSED: an unknown/missing per-hop provenance is treated as AMBIGUOUS, never
silently upgraded. Post-hoc promotion of a hop's provenance is forbidden - the cap is computed from
the raw declared values and there is no code path that raises a hop's level.
"""
from __future__ import annotations

EXTRACTED = "EXTRACTED"
INFERRED = "INFERRED"
AMBIGUOUS = "AMBIGUOUS"

# higher = stronger. Anything unrecognized normalizes to the WEAKEST (AMBIGUOUS) - fail-closed.
_ORDER = {AMBIGUOUS: 0, INFERRED: 1, EXTRACTED: 2}
_LEVELS = (AMBIGUOUS, INFERRED, EXTRACTED)


def normalize(value) -> str:
    """Map any declared provenance to one of the three levels. Unknown/missing -> AMBIGUOUS."""
    if isinstance(value, str):
        v = value.strip().upper()
        if v in _ORDER:
            return v
    return AMBIGUOUS


def rank(level: str) -> int:
    return _ORDER[normalize(level)]


def _hop_provenance(hop) -> str:
    if isinstance(hop, dict):
        return normalize(hop.get("provenance"))
    if isinstance(hop, str):     # a bare hop string carries no provenance -> weakest
        return AMBIGUOUS
    return AMBIGUOUS


def weakest(hops) -> str:
    """The weakest provenance across all hops. An empty/absent path is AMBIGUOUS (a claimed
    reachability with no hops is not proof). Fail-closed throughout."""
    if not isinstance(hops, (list, tuple)) or len(hops) == 0:
        return AMBIGUOUS
    return min((_hop_provenance(h) for h in hops), key=_ORDER.__getitem__)


def all_extracted(hops) -> bool:
    """True iff the path is non-empty and every hop is EXTRACTED."""
    if not isinstance(hops, (list, tuple)) or len(hops) == 0:
        return False
    return all(_hop_provenance(h) == EXTRACTED for h in hops)


def caps_to_possible(hops) -> bool:
    """A reachability path that is NOT all-EXTRACTED caps a CONFIRMED finding down to POSSIBLE."""
    return not all_extracted(hops)
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall