Skip to content

fix(trust): make Idris2 escape gate genuinely fail closed (#212) - #242

Open
hyperpolymath wants to merge 4 commits into
mainfrom
fix/212-idris-escape-gate-20261123
Open

hyperpolymath wants to merge 4 commits into
mainfrom
fix/212-idris-escape-gate-20261123

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Purpose

Fixes the pre-existing fail-open believe_me audit in #212 as an independent P0 Trustfile repair, before new proof-discharge work.

The old step counted strings/comments and printed only a warning over 300 matches; it could not fail even if active trust escapes were introduced. The new gate scans tracked Idris2 sources under src/, ignores documentation/comments/string literals, and fails on active believe_me, really_believe_me or idris_crash. It is deliberately a lexical safety gate, not a proof checker or a statement that all assumptions have been discharged.

Changes

  • scripts/check-idris-escape-hatches.sh: fail-closed source scan, nested Idris block comments, missing-source refusal.
  • scripts/test-idris-escape-gate.sh: planted negatives for all three escapes, positives for comments, strings and inline comments, and missing-source negative control.
  • trustfile.yml: execute control tests and actual scan before the SPDX/other policy steps; rerun on updates to either script. No threshold, no warning-only path.

Verification

Scope and precedence

The change deliberately does not alter assert_total rules, compiler-proof verification, the authoritative proof policy, or legacy A2ML governance semantics. Other Trustfile jobs and their pre-existing failures remain separately tracked. The mathematical-completion UltraPlan is in draft #241.

@gitnotebooks

gitnotebooks Bot commented Nov 23, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T09:12:56.039807Z 1a392f1 New commits
🔒 Security Review ✅ Completed 2026-11-25T09:15:14.622953Z 1a392f1 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c2f18eb30

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
if (pair == "--") break
if (pair == "{-") { depth++; i++; continue }
if (ch == "\"") { quoted = 1; continue }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Parse character literals before opening strings

When an active escape follows a double-quote character pattern, such as f '"' = believe_me 42, this condition treats the " inside the character literal as the start of a string and discards the remainder of the line. The scanner consequently exits successfully despite executable believe_me, defeating the fail-closed gate; track single-quoted character literals and their escapes before interpreting double quotes.

Useful? React with 👍 / 👎.

# remains forbidden, with no permissive threshold or implicit waiver.
awk '
function code_of(line, i, pair, ch, out, quoted, escaped) {
out = ""; quoted = 0; escaped = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve state across multiline string literals

When a triple-quoted Idris string contains one of the forbidden names on an interior line, quoted is reset on every call, so that harmless text is scanned as executable code and fails the required workflow. The repository already uses multiline strings extensively (for example, safetyGuarantees in src/Proven/SafeSQL/Proofs.idr), so descriptive text mentioning an escape hatch can spuriously block a legitimate change; maintain multiline-string state across lines and add it to the positive controls.

Useful? React with 👍 / 👎.

exit 2
fi

mapfile -d '' -t sources < <(find "$source_root" -type f -name '*.idr' -print0 | LC_ALL=C sort -z)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include literate Idris source files in the census

When a trust escape is added in a literate Idris module under src, this census silently ignores it because it only selects *.idr; the hundreds of ordinary sources keep the nonempty check satisfied, so the gate reports success. Idris 2 officially treats .lidr files as compilable literate source files (Idris2 literate programming reference), so such a module can contain executable believe_me while this supposedly fail-closed workflow remains green; include every supported source extension or derive the scanned files from the package/compiler inputs.

Useful? React with 👍 / 👎.

}
{
executable = code_of($0)
if (executable ~ /(^|[^[:alnum:]_])(really_believe_me|believe_me|idris_crash)([^[:alnum:]_]|$)/) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject direct unsafe primitives as well

When code invokes prim__believe_me _ _ value or prim__crash _ message directly, this pattern accepts it: the underscore before believe_me defeats the left token boundary, while prim__crash is absent entirely. Idris2's official Builtin source implements believe_me and idris_crash using exactly these primitives (Builtin source), so the same unsafe cast or crash bypasses the gate without any lexical trick; add the primitive names to the forbidden set and planted controls.

Useful? React with 👍 / 👎.

Repository owner deleted a comment from coderabbitai Bot Nov 25, 2026
Repository owner deleted a comment from coderabbitai Bot Nov 25, 2026
@sonarqubecloud

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a392f10ef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

exit 2
fi

mapfile -d '' -t sources < <(find "$source_root" -type f -name '*.idr' -print0 | LC_ALL=C sort -z)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Follow symlinked Idris sources in the census

When a package-listed source such as src/Evil.idr is a symlink to a tracked .idr file outside src, find -type f omits the symlink even though Idris opens and compiles it; the existing regular sources keep the nonempty check satisfied, so an active believe_me in that target still produces PASS. The repository already uses a source-tree symlink at src/abi, so the census should either follow symlinks safely or reject symlinked source entries explicitly.

Useful? React with 👍 / 👎.

Comment on lines +35 to +37
if (quoted) {
if (escaped) { escaped = 0; continue }
if (ch == "\\") { escaped = 1; continue }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scan expressions inside interpolated strings

When a trust escape occurs in an interpolation such as x = "forged: \{believe_me value}", this branch treats \{ as an ordinary string escape and ignores everything through the closing quote, so the gate reports PASS. Idris explicitly permits arbitrary expressions inside interpolation slices and desugars them into executable calls, as documented in the Idris2 string-literal reference; the scanner therefore needs to resume token scanning inside interpolation braces rather than discarding the whole literal.

Useful? React with 👍 / 👎.

if (quoted) {
if (escaped) { escaped = 0; continue }
if (ch == "\\") { escaped = 1; continue }
if (ch == "\"") { quoted = 0; continue }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor raw-string closing delimiters

When a valid raw string contains an ordinary quote before harmless forbidden-name text, for example #"quote: " and believe_me text"#, this condition treats that quote as the end of the literal and scans the remaining text as executable code, causing the required workflow to fail. Idris raw strings close with a quote followed by the matching number of # characters, and embedded bare quotes remain literal according to the Idris2 string-literal reference, so the lexer must track the raw delimiter rather than closing every string on ".

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants