KB-30B7

FIX7 authority-input packet — bad_input_probes.py

5 min read Revision 1
tool-kiem-thufix7authority-inputbad-probes2026-06-11

#!/usr/bin/env python3

============================================================================

FIX7 N7/N8/P7 AUTHORITY-INPUT -- BAD-INPUT PROBES (fail-closed proof)

Builds 10 adversarial mutations of the GOOD packet and asserts each is

rejected (fail-closed). exit 0 iff all 10 fail closed. No probe is allowed

to be ACCEPTED. Mirrors Workstream F of the macro.

Usage: python3 bad_input_probes.py <good_packet_dir>

============================================================================

import json, os, sys, shutil, tempfile, importlib.util

HERE = os.path.dirname(os.path.abspath(file)) sys.path.insert(0, HERE) import authority_input_validator as V import stale_prose_detector as S

GOOD = sys.argv[1] if len(sys.argv) > 1 else "."

def clone(mut_files): d = tempfile.mkdtemp(prefix="authinput-probe-") for fn in ("n7-envelope-n6-status.json", "owner-decision-template.json", "p7-id-proposal.json", "report-set-candidate.json", "authority-input-roster.json"): shutil.copy(os.path.join(GOOD, fn), os.path.join(d, fn)) for fn, mut in mut_files.items(): p = os.path.join(d, fn) j = json.load(open(p)) mut(j) json.dump(j, open(p, "w")) return d

def expect_validator_reject(label, expect, mut_files, extra_stale=False): d = clone(mut_files) try: V.validate_packet(d) # If validator passes, maybe the stale detector is the relevant gate. if extra_stale: try: S.scan_status(os.path.join(d, "n7-envelope-n6-status.json")) shutil.rmtree(d, ignore_errors=True) return (label, False, "ACCEPTED (expected reject)") except S.StaleProse as e: shutil.rmtree(d, ignore_errors=True) return (label, True, f"stale-detector {e.status}") shutil.rmtree(d, ignore_errors=True) return (label, False, "ACCEPTED (expected reject)") except V.AuthInputReject as e: ok = (e.status == expect) shutil.rmtree(d, ignore_errors=True) return (label, ok, e.status + ("" if ok else f" (expected {expect})"))

PROBES = [ ("P1 remove N6 certificate", "AUTHINPUT_N6_CERT_MISSING", {"n7-envelope-n6-status.json": lambda j: j.setitem("n6_certificate_binding_sha256", None)}), ("P2 pre-ratification SEAL_REAL_N6_NOT_AVAILABLE status", "AUTHINPUT_N6_FALSELY_OFFICIAL", {"n7-envelope-n6-status.json": lambda j: j.setitem("n6_current_status", "SEAL_REAL_N6_NOT_AVAILABLE")}), ("P3 mark N6 candidate as official seal", "AUTHINPUT_N6_FALSELY_OFFICIAL", {"n7-envelope-n6-status.json": lambda j: j.setitem("n6_is_official_seal", True)}), ("P4 fabricate owner approval", "AUTHINPUT_OWNER_APPROVAL_FABRICATED", {"owner-decision-template.json": lambda j: j.setitem("current_decision", "APPROVED")}), ("P5 fabricate N8 signer", "AUTHINPUT_N8_SIGNER_FABRICATED", {"report-set-candidate.json": lambda j: j.setitem("sealed_by", "codex-signer-x")}), ("P6 fabricate P7 official ID", "AUTHINPUT_P7_OFFICIAL_FABRICATED", {"p7-id-proposal.json": lambda j: j.setitem("is_official_p7", True)}), ("P7 omit A1..A5 but claim ready-to-author", "AUTHINPUT_READY_WITH_MISSING_INPUTS", {"authority-input-roster.json": lambda j: j.setitem("ready_to_author", True)}), ("P8 use old membership (N1) label", "AUTHINPUT_STALE_N1_MEMBERSHIP_LABEL", {"n7-envelope-n6-status.json": lambda j: j.setitem("membership_label", "N1")}), ("P9 use unratified N-number table", "AUTHINPUT_NNUMBER_NOT_RATIFIED", {"n7-envelope-n6-status.json": lambda j: j.setitem("n_number_table_status", "PROPOSED")}), ("P10 author official P7 seal artifact in this macro", "AUTHINPUT_SEAL_AUTHORED_IN_INPUT_PACKET", {"p7-id-proposal.json": lambda j: j.setitem("authority_seal_pin_sha256", "b" * 64)}), ]

def main(): results = [] for label, expect, muts in PROBES: results.append(expect_validator_reject(label, expect, muts, extra_stale=True)) nfail_closed = sum(1 for _, ok, _ in results if ok) for label, ok, note in results: print(f" [{'FAIL-CLOSED' if ok else 'FAIL-OPEN!!'}] {label} -> {note}") allok = all(ok for _, ok, _ in results) print(f"BAD-INPUT-PROBES: {nfail_closed}/{len(results)} fail-closed " f"-> {'PASS' if allok else 'FAIL (a probe was accepted / wrong code)'}") return allok

if name == "main": sys.exit(0 if main() else 1)

Back to Knowledge Hub knowledge/dev/reports/architecture/fix7-n7-n8-p7-authority-input-packet-2026-06-11/bad_input_probes.py