From 602e6aff244448dcb6d550de2fef3e2a8f13a793 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 15 Nov 2026 11:07:15 -0600 Subject: [PATCH] Fix security finding acf_08b8746bd6396181b8ed59ea69e84bd4 --- CONTRIBUTORS.md | 1 + tests/r15_receipt_test.sh | 52 ++++++++++++++ tools/r15_receipt.sh | 38 +++++++++-- tools/r15_reruns_validate.om | 128 +++++++++++++++++++++++++++++++++++ 4 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 tools/r15_reruns_validate.om diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index aa4a7bd38..118971574 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -7,6 +7,7 @@ The current development method is [Human-Directed Agentic Engineering (HDAE)](RE | Model | What it did | |---|---| +| Codex | Replaced R15 rerun substring acceptance with strict seeded-Omega JSON and exact-schema validation, including duplicate, nested, malformed, extra-key and non-string regression controls. | | Grok 4.7 (via Cursor Agent) | Merged main `fd3751b31` (#1020, carrying #1045 and #1050) into #1052. The only conflict was the generated root `.crumb` (child `last_commit` stamps, the `tests` digest, and the root digest). Recompiled with the crumb.lock tool (`d0f0b95d`); `crumb verify .` current. The #525/#962 pins were left as committed: `src/checker2/c2_check.c`, `src/compiler/osc_ir.c` and `src/compiler/osc_ir.h` still hash to the SHA-256s in `ACCEPTED`. | | Claude Opus 5.5 (via omp) | #1020 (actions/cache-4.3.0 ->6.1.0): merged main `d3d1b1bc` and recompiled the root crumb with the crumb.lock tool (`d0f0b95d`). The root crumb's source tree covers `.github/workflows/`, so the bump alone left it stale and `AIEN Checks` failed at `crumb verify .` (`1 of 188 crumbs stale`). | | Claude Opus 5.5 (via omp) | #1018 (actions/upload-artifact-4 ->7): merged main `d3d1b1bc` and recompiled the root crumb with the crumb.lock tool (`d0f0b95d`). The root crumb's source tree covers `.github/workflows/`, so the bump alone left it stale and `AIEN Checks` failed at `crumb verify .` (`1 of 188 crumbs stale`). | diff --git a/tests/r15_receipt_test.sh b/tests/r15_receipt_test.sh index bb0fa15f9..5169443ef 100755 --- a/tests/r15_receipt_test.sh +++ b/tests/r15_receipt_test.sh @@ -76,6 +76,58 @@ sed -i 's/,$/}/' "$OUT/reruns.json" check "all gates PASS but no reruns -> still FAIL" '[ $? = 1 ]' P=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json") check "all gates PASS + reruns PASS -> PASS" '[ $? = 0 ] && grep -q "\"outcome\": \"PASS\"" "$P"' + +printf '{\n' > "$OUT/reruns-formatted.json" +first=1 +for k in R15_SEQ_parity R14_silicon R14_host R13_silicon R13_host R12_silicon R12_host R11 R10 R9 R8 R7 R3; do + [ $first = 1 ] || printf ',\n' >> "$OUT/reruns-formatted.json" + first=0 + printf ' "%s" : "PASS"' "$k" >> "$OUT/reruns-formatted.json" +done +printf '\n}\n' >> "$OUT/reruns-formatted.json" +F=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns-formatted.json") +check "reordered whitespace-formatted reruns -> PASS" '[ $? = 0 ] && grep -q "\"outcome\": \"PASS\"" "$F"' + +# The rerun input is a security boundary: only the exact root object is +# accepted. The structural fixtures retain enough PASS substrings for the old +# grep loop to accept them; the value fixtures exercise the exact schema. +bad_reruns() { # label file + label=$1; file=$2 + Q=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$file") + qrc=$? + check "$label -> FAIL" '[ $qrc = 1 ] && grep -q "correctness reruns must be one exact root object" "$Q"' + check "$label -> untrusted JSON not embedded" 'grep -Fq "\"correctness_reruns\": {\"status\":\"invalid\"}" "$Q"' +} + +printf '{"reported":' > "$OUT/reruns-nested.json" +cat "$OUT/reruns.json" >> "$OUT/reruns-nested.json" +printf '}' >> "$OUT/reruns-nested.json" +bad_reruns "nested decoy PASS keys" "$OUT/reruns-nested.json" + +sed 's/}$/,"R3":"FAIL"}/' "$OUT/reruns.json" > "$OUT/reruns-duplicate.json" +bad_reruns "duplicate conflicting key" "$OUT/reruns-duplicate.json" + +sed 's/}$/,"R\\u0033":"FAIL"}/' "$OUT/reruns.json" > "$OUT/reruns-escaped-duplicate.json" +bad_reruns "escaped duplicate key" "$OUT/reruns-escaped-duplicate.json" + +sed 's/"R7":"PASS"/"R\\u0033":"FAIL"/' "$OUT/reruns.json" > "$OUT/reruns-escaped-duplicate-13.json" +bad_reruns "decoded duplicate among thirteen keys" "$OUT/reruns-escaped-duplicate-13.json" + +sed 's/}$/,"extra":"PASS"}/' "$OUT/reruns.json" > "$OUT/reruns-extra.json" +bad_reruns "extra root key" "$OUT/reruns-extra.json" + +sed 's/"R3":"PASS"/"R3":true/' "$OUT/reruns.json" > "$OUT/reruns-nonstring.json" +bad_reruns "non-string PASS value" "$OUT/reruns-nonstring.json" + +sed 's/"R3":"PASS"/"R3":"FAIL"/' "$OUT/reruns.json" > "$OUT/reruns-fail.json" +bad_reruns "non-PASS string value" "$OUT/reruns-fail.json" + +sed 's/"R3":"PASS",//' "$OUT/reruns.json" > "$OUT/reruns-missing.json" +bad_reruns "missing required key" "$OUT/reruns-missing.json" + +sed 's/}$//' "$OUT/reruns.json" > "$OUT/reruns-malformed.json" +bad_reruns "malformed JSON" "$OUT/reruns-malformed.json" + "$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" 0000000000000000000000000000000000000000 "$OUT/reruns.json" >/dev/null check "wrong candidate -> FAIL" '[ $? = 1 ]' check "nodigest flag checked from raw" 'grep -q "\"checked_from_raw\": true, \"nodigest_processes_digest_off\": 12, \"production_processes_digest_on\": 46" "$R"' diff --git a/tools/r15_receipt.sh b/tools/r15_receipt.sh index 13b06dc08..aa385fb9e 100755 --- a/tools/r15_receipt.sh +++ b/tools/r15_receipt.sh @@ -49,7 +49,8 @@ # observed, aienos and physics commits are recorded and equal the pins in # aienos.lock/physics.lock at the run commit, and every required correctness # rerun is PASS. Anything else is FAIL, with the reasons listed. -# Shell and coreutils only (sha256sum, grep, sed, git). No jq, no Python. +# Shell, coreutils, git and the seeded Omega compiler. No jq, Python or C is +# introduced on this path; reruns.json is parsed by seed/json/json.om. set -u RAW=${1:?raw run directory} @@ -138,11 +139,40 @@ if [ -z "$PHYSICS" ]; then fail "physics_commit not recorded in machine.json" elif [ "$PHYSICS" != "$PHYSICS_LOCK" ]; then fail "physics_commit $PHYSICS != physics.lock $PHYSICS_LOCK"; fi # ---- correctness reruns (§14, §16 item 9) +# Parse before embedding. The schema-specific Omega validator composes the +# repository's strict RFC 8259 reader and rejects non-root, missing, extra, +# duplicate or non-PASS members (including escaped spellings of a duplicate). if [ -n "$RERUNS" ] && [ -s "$RERUNS" ]; then - RERUN_JSON=$(tr -d '\n' < "$RERUNS") - for k in $REQUIRED_RERUNS; do - printf '%s' "$RERUN_JSON" | grep -q "\"$k\":\"PASS\"" || fail "correctness rerun $k not PASS" + OMC=$HERE/seed/out/omc + JSON_UNIT=$HERE/seed/json/json.om + RERUN_UNIT=$HERE/tools/r15_reruns_validate.om + for f in "$OMC" "$HERE/seed/out/omc.sha256" "$JSON_UNIT" "$RERUN_UNIT"; do + [ -s "$f" ] || { echo "r15_receipt: missing $f" >&2; exit 2; } done + [ -x "$OMC" ] || { echo "r15_receipt: seeded compiler $OMC is not executable" >&2; exit 2; } + (cd "$HERE" && sha256sum --quiet -c seed/out/omc.sha256) || { + echo "r15_receipt: seeded compiler does not match seed/out/omc.sha256" >&2 + exit 2 + } + RERUN_CHECK=$(mktemp "$OUTDIR/.r15-reruns-check.XXXXXX") || exit 2 + if ! { printf 'om2\n'; cat "$JSON_UNIT" "$RERUN_UNIT"; } | "$OMC" > "$RERUN_CHECK"; then + rm -f "$RERUN_CHECK" + echo "r15_receipt: cannot build strict rerun validator" >&2 + exit 2 + fi + chmod 700 "$RERUN_CHECK" || { rm -f "$RERUN_CHECK"; exit 2; } + "$RERUN_CHECK" < "$RERUNS" + RERUN_RC=$? + rm -f "$RERUN_CHECK" + if [ "$RERUN_RC" = 0 ]; then + RERUN_JSON=$(tr -d '\r\n' < "$RERUNS") + elif [ "$RERUN_RC" = 1 ]; then + RERUN_JSON='{"status":"invalid"}' + fail "correctness reruns must be one exact root object with every required key once and string value PASS" + else + echo "r15_receipt: rerun validator failed with exit $RERUN_RC" >&2 + exit 2 + fi else RERUN_JSON='{"status":"not done"}' fail "correctness reruns (§14) not recorded" diff --git a/tools/r15_reruns_validate.om b/tools/r15_reruns_validate.om new file mode 100644 index 000000000..3fbf3dd6a --- /dev/null +++ b/tools/r15_reruns_validate.om @@ -0,0 +1,128 @@ +note SPDX-License-Identifier: Apache-2.0 +note Copyright 2026 Drake Stapleton (AIEN / aien-dev) +note +note r15_reruns_validate.om: strict schema check for the R15 correctness-rerun object. +note Compose after seed/json/json.om under one om2 line. Reads one JSON document from stdin. +note Exit 0 only for exactly the thirteen required keys, each once, with the string value PASS. +note Exit 1 for invalid JSON or schema and 2 for an input read error. No output is written. + +text rrpass "PASS" +text rr3 "R3" +text rr7 "R7" +text rr8 "R8" +text rr9 "R9" +text rr10 "R10" +text rr11 "R11" +text rr12h "R12_host" +text rr12s "R12_silicon" +text rr13h "R13_host" +text rr13s "R13_silicon" +text rr14h "R14_host" +text rr14s "R14_silicon" +text rr15p "R15_SEQ_parity" + +note rrkey returns 0..12 for a required decoded key and 13 for every other key. +fn rrkey src view uchar * tape view uint * k ulong to ulong +o = js_off tape k +if js_streq src o rr3 +ret 0 +end +if js_streq src o rr7 +ret 1 +end +if js_streq src o rr8 +ret 2 +end +if js_streq src o rr9 +ret 3 +end +if js_streq src o rr10 +ret 4 +end +if js_streq src o rr11 +ret 5 +end +if js_streq src o rr12h +ret 6 +end +if js_streq src o rr12s +ret 7 +end +if js_streq src o rr13h +ret 8 +end +if js_streq src o rr13s +ret 9 +end +if js_streq src o rr14h +ret 10 +end +if js_streq src o rr14s +ret 11 +end +if js_streq src o rr15p +ret 12 +end +ret 13 +end + +fn rrread src edit uchar * to ulong +p = ulong 0 +while lt p len src bound 983041 +r = read 0 src p sub len src p +if lt r 0 +exit 2 +end +if eq r 0 +ret p +end +p = add p ulong r +end +extra = new uchar 1 0 +r = read 0 extra 0 1 +if ne r 0 +exit 1 +end +ret p +end + +fn main to int +src = new uchar 983040 0 +tape = new uint 256 0 +n = rrread src +if ne js_init tape 983040 16 0 +ret 2 +end +if lt js_parse src tape n 0 +ret 1 +end +if or ne js_type tape 0 jsobj ne js_nkids tape 0 13 +ret 1 +end + +seen = ulong 0 +k = js_first tape 0 +for i ulong 13 +if eq k jsnone +ret 1 +end +id = rrkey src tape k +if eq id 13 +ret 1 +end +bit = shl ulong 1 id +if ne and seen bit 0 +ret 1 +end +v = add k 1 +if or ne js_type tape v jsstr not js_streq src js_off tape v rrpass +ret 1 +end +seen = or seen bit +k = js_mnext tape k +end +if or ne k jsnone ne seen 8191 +ret 1 +end +ret 0 +end