Summary

Mareforma: Unsigned Claims Can Be Promoted to REPLICATED via Missing Signature Enforcement in Convergence Path

Advisory details

Summary

mareforma 0.3.3 contains a critical integrity flaw in the REPLICATED convergence logic (_maybe_update_replicated_unlocked() in mareforma/db/core.py:1300-1319). The peer-selection SQL query that determines whether two independent claims "agree" on the same anchor does not verify that either claim carries a valid cryptographic signature from an enrolled validator key. Because rekor_enabled=False is the default and automatically sets transparency_logged=1 at insert time, every claim — signed or not — immediately satisfies the convergence precondition. An attacker with no Mareforma key can write an unsigned claim to a shared graph, cause it to converge with a legitimate signed peer claim, and have it promoted to REPLICATED status. The forged REPLICATED row is then returned by the default trust query (graph.query(min_support="REPLICATED")), allowing the attacker to inject false trust signals into any downstream consumer relying on REPLICATED as a multi-party endorsement guarantee.

Details

Root cause — mareforma/db/core.py:1300-1319

The convergence function _maybe_update_replicated_unlocked() selects peer claims using a SQL query that filters on status, unresolved, transparency_logged, and artifact_hash, but contains no predicate on signature_bundle or enrolled-key identity:

# mareforma/db/core.py:1300-1319
rows = conn.execute(
    f"""
    SELECT DISTINCT c.claim_id, c.generated_by
    FROM claims c, json_each(c.supports_json) j
    WHERE j.value IN ({placeholders})
      AND c.claim_id != ?
      AND c.generated_by != ?
      AND c.support_level != 'ESTABLISHED'
      AND c.status = 'open'
      AND c.unresolved = 0
      AND c.transparency_logged = 1
      AND (
          c.artifact_hash IS NULL
          OR ? IS NULL
          OR c.artifact_hash = ?
      )
    """,

Once peer rows are collected, the sink at core.py:1324-1334 promotes all matching claim IDs — including the attacker's — to REPLICATED without any additional validation.

Why the preconditions are trivially satisfied

  1. transparency_logged = 1 is set automatically. When rekor_enabled=False (the library default), core.py:1061 sets transparency_logged = 1 immediately after insert. There is no Rekor step, so every claim becomes convergence-eligible the moment it is written.
  2. require_signed=False is the default. mareforma/__init__.py:41 defaults require_signed to False. When the attacker opens the graph with a non-existent key path, __init__.py:132-138 silently sets signer = None, enabling unsigned claim insertion.
  3. assert_claim() performs no signature gate. _graph.py:284-291 only validates DOI resolution on the supports list before forwarding attacker-controlled fields to _db.add_claim() (_graph.py:373-380).

Why the forged claim surfaces in trust queries

The default query path at core.py:3647-3650 filters out only PRELIMINARY claims whose generator is not enrolled. Claims at REPLICATED status are returned unconditionally, so the unsigned forged row is indistinguishable from a legitimately converged row in any downstream consumer.

The helper that should have been called

core.py:3661-3669 contains _extract_signature_bundle_keyid(), which can extract the key ID from a signature_bundle. This helper exists but is never invoked on the convergence path, indicating the validation was inadvertently omitted rather than a design decision.

Complete data flow (source → sink)

Step Location Description
1 cli.py:700-739 CLI accepts arbitrary TEXT, --supports, --generated-by; lines 720-723 explicitly permit unsigned graph mode
2 __init__.py:128-138 Missing key file → signer = None (no error raised)
3 _graph.py:284-291 assert_claim() forwards user-controlled supports after DOI check only
4 _graph.py:373-380 Calls _db.add_claim() with attacker-controlled claim fields
5 db/core.py:1208-1214 Post-insert convergence triggered when unresolved == False and transparency_logged == 1
6 db/core.py:1300-1319 Peer-selection SQL — no signature_bundle or enrolled-key check (vulnerable sink)
7 db/core.py:1324-1334 Updates peer and attacker claims to REPLICATED
8 db/core.py:3647-3650 Default query returns REPLICATED rows without signature validation

PoC

Prerequisites

python3 -m venv /tmp/mareforma-poc
/tmp/mareforma-poc/bin/pip install mareforma==0.3.3

Or run the fully self-contained Docker image:

# Build (from the repository root, with the local repo mounted under ./repo)
docker build -f vuln-001/Dockerfile -t mareforma-vuln001 .

# Run (no network required)
docker run --rm --network none mareforma-vuln001

Step-by-step attack

#!/usr/bin/env python3
from pathlib import Path
from tempfile import TemporaryDirectory

import mareforma
from mareforma import signing

with TemporaryDirectory() as td:
    root = Path(td)
    key_path = root / "root-key.pem"

    # Step 1: Legitimate root agent bootstraps a key and creates an ESTABLISHED anchor.
    signing.bootstrap_key(key_path)
    with mareforma.open(root, key_path=key_path) as g:
        anchor = g.assert_claim(
            "established anchor",
            classification="DERIVED",
            generated_by="seed/root",
            seed=True,
        )
        # Step 2: Honest peer asserts a signed PRELIMINARY claim supporting the anchor.
        honest = g.assert_claim(
            "same result",
            supports=[anchor],
            generated_by="honest-agent",
        )

    # Step 3: Attacker opens the same graph with a non-existent key path.
    #         __init__.py:132-138 silently sets signer=None — unsigned mode.
    attacker_key = root / "missing-attacker-key.pem"  # does not exist
    with mareforma.open(root, key_path=attacker_key) as g:
        # Step 4: Attacker inserts an unsigned claim supporting the same anchor.
        #         Convergence fires in _maybe_update_replicated_unlocked():
        #           - Two claims share the same ESTABLISHED anchor
        #           - Different generated_by values
        #           - Both have transparency_logged=1 (Rekor disabled by default)
        #           - No signature or enrollment check performed
        attack = g.assert_claim(
            "forged convergence",
            supports=[anchor],
            generated_by="attacker-agent",
        )

        attack_info = g.get_claim(attack)
        print(attack_info["support_level"])          # → REPLICATED
        print(attack_info["signature_bundle"] is None)  # → True (unsigned)

        # Step 5: The unsigned REPLICATED claim appears in the default trust query.
        results = g.query(min_support="REPLICATED")
        for r in results:
            print((r["text"], r["support_level"],
                   r["signature_bundle"] is None, r["generator_enrolled"]))

Expected output

REPLICATED
True
('established anchor', 'ESTABLISHED', False, True)
('forged convergence', 'REPLICATED', True, False)   # ← unsigned, unenrolled
('same result', 'REPLICATED', False, True)

The forged claim (signature_bundle=None, generator_enrolled=False) is promoted to REPLICATED and returned alongside legitimately signed claims.

Remediation

The convergence path must require both the incoming claim and every selected peer claim to carry a valid signature_bundle signed by a distinct enrolled validator key:

--- a/mareforma/db/core.py
+++ b/mareforma/db/core.py
@@
-    new_status_row = conn.execute(
-        "SELECT status FROM claims WHERE claim_id = ?", (new_claim_id,),
+    new_status_row = conn.execute(
+        "SELECT status, signature_bundle FROM claims WHERE claim_id = ?",
+        (new_claim_id,),
     ).fetchone()
     if new_status_row is None or new_status_row["status"] != "open":

References