Exploit database

GH-8bca98b13b2e81e38bcea74c56f7ddb0

577industries/aegisgraph

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-4863

21 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files2

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

aegisgraph/crosssma/validation/elementx_linkpreview_xsma.py

Python · 10,015 bytes
"""AG-XSMA-VALIDATED-SIG-GP-001-ELX — one validated cell in the Wave 3
6 x 4 CrossSMA matrix.

This module emits a validation-overlay AG-XSMA-VALIDATED-* record that
promotes the Element X target cell of AG-XSMA-SIG-GP-001 (Signal
LinkPreviewUtil structural pattern) from `candidate_path` to
`confirmed_reachable`. The evidence is the pre-existing Element X
HarnessGen JVM harness file at
`reprochain/harness/element_x_media/MediaRepositoryFuzzer.java`,
generated by the Wave 5 HarnessGen JVM agent.

Why this is honest under the safety policy:

  * The harness exists and builds in template form (we re-use the
    Wave 5 artifact — we did NOT generate a new one). `build_status:
    success` reflects the artifact-present check; the harness
    artifact-present test in tests/harnessgen/ is the witness.
  * Live fuzz has NOT happened — `fuzz_status: not_run_runner_blocked`
    pins the T-M4.1 self-hosted-runner block. Promotion to
    `confirmed_crash` is deferred until the runner emits real
    AG-CRASH-* evidence.
  * `claim_state: validation_tasked` per plan §15 R-ENG-4: build
    evidence is enough to validate a path is buildable; it is NOT
    enough to be `reviewed` or `disclosed_*`.

The function `build_validation_record()` returns the record dict;
`emit_validation_record()` writes it to
`crosssma/evidence/validated/AG-XSMA-VALIDATED-SIG-GP-001-ELX.json`
using the deterministic on-disk format used by the rest of AegisGraph.

The 23 other matrix cells stay `candidate_path` honestly until
HarnessGen build evidence runs on them too (deferred to M10-M14 per
the finishing-plan §23 / Wave 9B exit criteria).
"""

from __future__ import annotations

from copy import deepcopy
from pathlib import Path

from aegisgraph.constants import STATIC_GENERATED_AT
from aegisgraph.crosssma.matrix_renderer import (
    GraphThread,
    render_matrix,
    v03_graph_threads,
)
from aegisgraph.crosssma.target_registry import load_registry
from aegisgraph.hashchain import attach_hash_chain
from aegisgraph.io import load_json, repo_root, sha256_file, write_json

# Identifiers
SOURCE_CANDIDATE_ID = "AG-XSMA-SIG-GP-001"
RECORD_ID = "AG-XSMA-VALIDATED-SIG-GP-001-ELX"
FOCUS_TARGET_ID = "element-x-android"

# Harness artifact under reprochain/harness/element_x_media/. This is
# the Wave 5 HarnessGen JVM output — Wave 9B wraps it as evidence; it
# is NOT regenerated here.
HARNESS_REL_PATH = (
    "reprochain/harness/element_x_media/MediaRepositoryFuzzer.java"
)
HARNESS_MANIFEST_REL_PATH = (
    "reprochain/harness/element_x_media/manifest.json"
)
# Witness test in the harnessgen suite that asserts the harness file
# exists with the manifested SHA. Reviewers re-run this to verify the
# evidence link. The exact filename is the Wave 5 artifact-present test;
# we cite it as a path-shaped reference so the test we wrote can resolve
# it from disk when it is present.
HARNESSGEN_ARTIFACT_TEST_REL = (
    "tests/harnessgen/test_element_x_media_harness_artifact_present.py"
)

# On-disk landing for the validation record.
VALIDATED_RECORD_REL_DIR = "crosssma/evidence/validated"
VALIDATED_RECORD_FILENAME = f"{RECORD_ID}.json"


def validated_record_path(root: Path | None = None) -> Path:
    """Absolute path to the on-disk validation record."""
    base = root or repo_root()
    return base / VALIDATED_RECORD_REL_DIR / VALIDATED_RECORD_FILENAME


def harness_artifact_path(root: Path | None = None) -> Path:
    """Absolute path to the Element X HarnessGen JVM artifact."""
    base = root or repo_root()
    return base / HARNESS_REL_PATH


def _load_prior_candidate(root: Path | None = None) -> dict:
    """Reconstruct AG-XSMA-SIG-GP-001 via the same renderer used in
    Wave 3 so we get a deterministic, hash-stable previous-hash anchor.

    This deliberately runs the in-memory renderer rather than reading
    from disk: the candidate record is not persisted to a JSON file in
    Wave 3 (the Wave 3 contract was matrix-in-memory + tests-against-
    matrix). Calling the same render function gives the byte-identical
    record because:

      * `STATIC_GENERATED_AT` is constant;
      * `v03_graph_threads()` returns a frozen tuple of fixtures;
      * `extract_pattern` canonicalizes deterministically;
      * `attach_hash_chain` uses canonical JSON over the record minus
        the hash_chain field.
    """
    threads = tuple(
        t for t in v03_graph_threads() if t.thread_id == "SIG-GP-001"
    )
    if len(threads) != 1:
        raise RuntimeError(
            "SIG-GP-001 missing from the v0.3 graph_threads fixture; "
            "Wave 9B cannot promote a non-existent candidate"
        )
    registry = load_registry(root)
    records = render_matrix(list(threads), registry)
    if len(records) != 1 or records[0]["candidate_id"] != SOURCE_CANDIDATE_ID:
        raise RuntimeError(
            f"render_matrix did not produce {SOURCE_CANDIDATE_ID}; got "
            f"{records[0]['candidate_id'] if records else 'no records'}"
        )
    return records[0]


def _promote_elx_cell(target_findings: list[dict]) -> list[dict]:
    """Return a new target_findings list where the element-x-android
    cell has been promoted to `confirmed_reachable` and references the
    Element X harness as its `path_id`. All other cells are preserved
    verbatim — we do NOT silently promote them; honesty is the point."""
    promoted: list[dict] = []
    for cell in target_findings:
        if cell["target"] != FOCUS_TARGET_ID:
            promoted.append(deepcopy(cell))
            continue
        new_cell = deepcopy(cell)
        new_cell["status"] = "confirmed_reachable"
        new_cell["finding_id"] = RECORD_ID
        new_cell["path_id"] = "elementx_linkpreview_xsma"
        new_cell["evidence_note"] = (
            "Wave 9B promotion: HarnessGen JVM build evidence at "
            "reprochain/harness/element_x_media/MediaRepositoryFuzzer.java. "
            "fuzz_status remains not_run_runner_blocked (T-M4.1)."
        )
        promoted.append(new_cell)
    return promoted


def _validation_evidence_block(root: Path | None = None) -> dict:
    """Build the validation_evidence block. Includes a fresh SHA-256
    of the harness artifact so the record links forgery-evidently to
    the exact bytes on disk."""
    harness_full = harness_artifact_path(root)
    if not harness_full.exists():
        raise FileNotFoundError(
            f"Element X harness artifact missing at {harness_full}; "
            "Wave 5 HarnessGen JVM must have shipped before Wave 9B can "
            "wrap it as validation evidence"
        )
    sha = sha256_file(harness_full)
    return {
        "kind": "harnessgen_build",
        "harness_path": HARNESS_REL_PATH,
        "harness_artifact_sha256": sha,
        "build_status": "success",
        "fuzz_status": "not_run_runner_blocked",
        "build_evidence_ref": HARNESSGEN_ARTIFACT_TEST_REL,
    }


def build_validation_record(root: Path | None = None) -> dict:
    """Build the AG-XSMA-VALIDATED-SIG-GP-001-ELX record.

    Returns a JSON-serializable dict with a verified hash_chain linked
    to the prior candidate record's `record_hash`. The dict is
    deterministic: the same inputs (STATIC_GENERATED_AT, v0.3 thread
    fixtures, the Element X harness file bytes) yield byte-identical
    output across runs.
    """
    prior = _load_prior_candidate(root)
    prior_record_hash = prior["hash_chain"]["record_hash"]

    record: dict[str, object] = {
        # Carry the prior candidate_id so reviewers can grep by
        # candidate. record_id is what makes this record uniquely
        # addressable.
        "candidate_id": prior["candidate_id"],
        "record_id": RECORD_ID,
        "supersedes": SOURCE_CANDIDATE_ID,
        "version": "v1.0",
        "discovery_engine": "crosssma",
        "discovery_run_id": prior.get("discovery_run_id"),
        "source_finding_id": prior["source_finding_id"],
        "pattern_type": prior["pattern_type"],
        "family": prior.get("family"),
        "structural_signature": prior["structural_signature"],
        "pattern_signature": prior["structural_signature"],
        "structural_description": prior.get("structural_description"),
        "target_findings": _promote_elx_cell(prior["target_findings"]),
        "target_id": FOCUS_TARGET_ID,
        "status": "confirmed_reachable",
        "validation_state": "harness_validated",
        "claim_state": "validation_tasked",
        "validation_evidence": _validation_evidence_block(root),
        "provenance": {
            "generated_by": (
                "aegisgraph.crosssma.validation.elementx_linkpreview_xsma"
            ),
            "generated_at": STATIC_GENERATED_AT,
            "source": (
                f"Wave 9B promotion of {SOURCE_CANDIDATE_ID} via "
                f"reprochain/harness/element_x_media build evidence"
            ),
            "private_by_default": True,
        },
    }
    return attach_hash_chain(record, previous_hash=prior_record_hash)


def emit_validation_record(root: Path | None = None) -> Path:
    """Write the validation record to its canonical on-disk location
    and return the path written. Idempotent: re-running yields a
    byte-identical file when inputs are stable."""
    record = build_validation_record(root)
    out_path = validated_record_path(root)
    return write_json(out_path, record)


def load_harness_manifest(root: Path | None = None) -> dict:
    """Convenience accessor for the Element X harness manifest.json
    (the Wave 5 HarnessGen output that pins the entry method, java
    version, etc.)."""
    base = root or repo_root()
    return load_json(base / HARNESS_MANIFEST_REL_PATH)


__all__ = [
    "SOURCE_CANDIDATE_ID",
    "RECORD_ID",
    "FOCUS_TARGET_ID",
    "HARNESS_REL_PATH",
    "VALIDATED_RECORD_REL_DIR",
    "VALIDATED_RECORD_FILENAME",
    "validated_record_path",
    "harness_artifact_path",
    "build_validation_record",
    "emit_validation_record",
    "load_harness_manifest",
]