Repository navigation
Test: Add Atheris fuzz harnesses - #112
ModeSevenIndustrialSolutions merged 5 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The fuzz oracles miss link-containment and verdict-extraction regressions, while a lone surrogate can crash summary output and fence matching can exhibit quadratic backtracking.
7 open issues
Verify every fenced block is preserved in order · New Check code preservation in the final posted body · New Prevent quadratic backtracking in the fence-line pattern · New Reject or sanitize lone surrogates in rendered review output · New Verify extracted findings and injection attempts are preserved · New Validate the complete GitHub organization path segment · New Match raw fence delimiters before decoding escaped text · New
What changed in this PR
Adds Atheris fuzz harnesses for the bot’s handling of untrusted agent verdicts and review comments, addressing issue #111 without changing workflows or dependencies.
Changes:
- Adds verdict-validation and comment-safety harnesses with built-in seeds.
- Introduces independent Markdown oracles and seed-replay tests that run without Atheris.
- Documents manual fuzzing and input replay.
| File | Description |
|---|---|
tests/test_fuzz_harnesses.py |
Replays seeds and checks oracle rejection and harness discovery. |
README.md |
Documents harness coverage and manual invocation. |
fuzz/github_markdown.py |
Models Markdown fences, references, and URL containment for the oracles. |
fuzz/fuzz_verdict.py |
Fuzzes verdict extraction and sanitisation contracts. |
fuzz/fuzz_comment.py |
Fuzzes comment safety, code preservation, and posted-body containment. |
Review effort: Balanced
zxiiro
left a comment
There was a problem hiding this comment.
🤖 Auto-approved by agent: reviewed workflow/code change for security and CI/CD impact, found low risk. Adds Atheris fuzz harnesses under fuzz/, a replay test and a README section only; no scripts, workflows, permissions or secrets change, and nothing new runs in the review job.
b315017 to
f1f2be3
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Critical containment failures leave FTP and certain quote-suffixed or truncated URLs live, while fuzz oracles also miss code-preservation and verdict-validation regressions.
6 open issues
FTP autolinks are not contained · New Truncated organisation URLs bypass containment · New Trailing quotes leave out-of-scope autolinks live · New Uncut code blocks can be changed without detection · New Oracle does not validate the source schema · New Oracle misses erased or reordered retained text · New
Review effort: Balanced
f1f2be3 to
a3736f4
Compare
a3736f4 to
4803c36
Compare
4803c36 to
c51350b
Compare
c51350b to
760edf3
Compare
Fuzz the code that judges an untrusted review agent's text, to the
organisation's harness contract (version 1, Python).
fuzz/fuzz_verdict.py drives review_files.parse_verdict, which catches
Rejected by design, with review_policy.extract_verdict, and holds an
accepted verdict to the final json block and to its documented
bounds, the first 20 findings and injection attempts kept in order.
It renders the check as apply_review writes it, the job summary and
the approval body, and encodes both as strict UTF-8. It also holds
sanitise, defuse and contain_links to their docstrings: one safe
line, idempotent defusing, no live link outside the organisation.
fuzz/fuzz_comment.py drives comment_markdown.comment_text and the
body comment_body.fitted posts from it: within the limit, no fence
left open, no suggestion fence, nothing live in prose, fenced code
kept as written, in order, in both.
The oracles share no code with what they check: fuzz/github_markdown.py
models how GitHub reads the output from CommonMark, GFM and
docs/DESIGN.md. tests/test_fuzz_harnesses.py replays every seed in the
normal suite without Atheris and shows each oracle rejecting a wrong
result. The README says how to run a harness by hand.
Review round 1:
- Code kept: written blocks now match rendered ones in order, each
consuming its match, and the posted body is checked as well.
- last_block: possessive quantifiers, so a long fence run before a
carriage return costs one pass.
- Verdict lists: findings' areas and the injection count must match
the first 20 of the final block.
- Lone surrogates: the check is rendered and encoded strictly.
- Organisation links: the first path segment must equal the org,
after GitHub's trimming of punctuation and an unmatched ")".
- Suggestion fences: container and fence are read raw, the info
string alone decoded, so escaped backticks are text.
Review round 2:
- Code kept: fenced code counts at its own size in the no-cut bound
and only the rest grows fivefold, so a long uncut block is checked.
- Schema: the final block's schema must be 1, and so the verdict's.
- Retained text: the summary, each note and each injection attempt
must read as its own source field, the sanitiser's marks, folded
whitespace and a cut at the limit aside, so blanked or swapped
text is caught.
- Links: ftp:// is scanned too; a link counts as inside only when
it is inside with quotes trimmed and without; a cut URL is no
longer exempt.
Review round 3:
- Code kept: a body longer than the limit is skipped before the scan
for code, which read on from every unclosed opener and so took
quadratic time; a run of 20,000 unclosed openers is replayed.
- Retained text: whitespace folds to single spaces, not away, so
moved word breaks are caught; only the space sanitise puts into
"::" and "##[" is dropped.
- Cuts: a cut counts only for a source too long to fit once grown
fivefold, and what it keeps must read as a fifth of its length,
zero-width spaces the source carries aside, so an erased field is
caught.
- Pull request number: the final block's must itself be an integer,
so a true or 1.0 coerced to 1 is caught.
- Approval body: the rendered body above its footer is checked for
outside links against the checked repository's organisation.
Review round 4:
- Retained text: a field is read against its source character by
character; a sanitiser's mark counts only where it adds one (a
zero-width space after a mention, reference or tag trigger, or
before an opening fence; a space inside "::" or "##["; "amp;"
after "&"), so "x::y" for "x: :y" and "&" for "&" are caught.
- Cuts: a cut keeps the first limit characters, less a trailing
space, reads as the source's start and leaves some of it out, so
zero-width spaces standing in for text, or a cut of a source that
fits, are caught.
- Organisation and host names compare over ASCII alone, so the
Kelvin sign is no k.
- Suggestion fences: "suggestion:-0+2" opens one as well.
Review round 5:
- Code kept: the no-cut bound counts the growth each character and
line outside code can gain ("&" four, "@#<hH/]:." one, one per
line) instead of a fivefold rest, so long plain prose no longer
skips the check, and a dropped block beside it is caught.
- Code kept: the rendered blocks must equal the written ones, so a
block inserted or duplicated is caught as well as one dropped.
- Retained text: a zero-width space counts as a mark only where the
source spells out the whole trigger around it ("@", "<", "#" before
a digit, a word-initial "gh" before "-" and a digit, an issue, pull
or discussion path before a digit), so marks invented after every
"h" to fill a cut are caught.
- The text-reading oracle moves to fuzz/sanitised_text.py, which
imports nothing from scripts/, keeping fuzz_verdict.py within the
aislop file-size limit.
- Discovery test: reads tracked Python files from git ls-files, so
an ignored build or virtual environment holding Atheris is no part
of it.
Review round 6:
- Code kept: only an "&" that starts a character reference counts
four in the no-cut bound, as only that one is escaped, so a block
dropped beside plain ampersands is caught.
- Retained text: a trigger takes one zero-width space, so a run of
them filling a cut is caught; an "amp;" is required after the "&"
of a character reference, "&" aside, and accepted nowhere
else, so "&" for a plain "&" and a bare "©" are caught.
Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
contain_links documents that a bare URL stays a link only when it points under https://github.com/<org>/. It accepted the organisation name followed by any of ) ] > " ' and whatever came after, so https://github.com/<org>)other/repo and https://github.com/<org>"/x stayed live although their first path segment is not the organisation. After the name, a slash must follow, or nothing but what GitHub trims from a link's end, trailing punctuation and an unmatched ")", up to the end of the run. Anything else now becomes text, which still reads in full. Found by fuzz/fuzz_verdict.py once its link oracle compared the whole first segment (review round 1, Copilot thread on fuzz/github_markdown.py). The failing input is a seed there, and tests/test_review_policy.py carries a regression test. Review round 2 (Copilot thread on scripts/review_policy.py): GFM trims no quote from a link's end, so https://github.com/<org>'? links to /<org>' and now becomes text; a quote no longer counts as trimmed punctuation. The input is a seed in fuzz/fuzz_verdict.py. Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
sanitise documents one bounded line safe for logs and Markdown. A JSON escape such as \ud800 in a verdict decodes to a lone surrogate, and sanitise passed it through. A needs-human finding note carrying one became a check reason, and apply_review's run_check then raised UnicodeEncodeError writing the job summary as UTF-8, failing the job instead of reporting the verdict. sanitise now replaces each lone surrogate with U+FFFD before it folds control characters, so every sanitised field, in both review modes, can be written to a UTF-8 stream. Reported in review round 1 (Copilot thread on fuzz/fuzz_verdict.py) and reproduced by fuzz/fuzz_verdict.py, which now renders the check strictly. The input is a seed there, and tests/test_review_policy.py carries a regression test. Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
contain_links documents that it leaves no live link in untrusted text but those into the organisation. GFM's extended autolinks recognise ftp:// as well as http:// and https://, but the scheme pattern matched http(s) alone, so ftp://evil.example/x stayed live in an approval body and in a posted antagonistic comment. The scheme pattern now takes ftp too. No ftp URL is under https://github.com/<org>/, so every one becomes text, which still reads in full. Reported in review round 2 (Copilot thread on fuzz/github_markdown.py), whose link oracle now scans ftp:// too. Both harnesses carry the input as a seed, and tests/test_review_policy.py carries a regression test. Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
comment_body.fitted cuts a contained body back to its limit, and contained documents untrusted Markdown with no live link outside the organisation. A cut through an organisation URL left its start live: with limit 64, three short http links before https://github.com/lfreleng-actions/ posted as a body ending in https://github.com/lfr..., which GitHub links to /lfr..., outside the organisation. fitted now contains the cut body again, and cuts again while that lengthens it past the limit. Each round keeps a shorter start of the body, so the loop ends, and the result still fits. Reported in review round 2 (Copilot thread on fuzz/github_markdown.py); fuzz/fuzz_comment.py no longer exempts a cut URL, and carries the input as a seed. tests/test_comment_review.py carries a regression test. Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
760edf3 to
b8c0162
Compare
zxiiro
left a comment
There was a problem hiding this comment.
🤖 Auto-approved by agent: reviewed workflow/code change for security and CI/CD impact, found low risk. Link containment only gets stricter (the org name must end its path segment, ftp:// autolinks are disarmed, a cut comment body is re-contained) and sanitise replaces lone surrogates; the rest is fuzz harnesses, tests and docs, with no workflow changes.
7844c3f
into
lfreleng-actions:main
There was a problem hiding this comment.
🟡 Changes recommended
Fuzz checks can accept incorrect truncation or dropped content, while URL sanitisation alters valid GitHub search queries.
6 open issues
Exclude already-escaped entities from growth estimates · New Account for removable outer whitespace before skipping preservation · New Only allow spaces after the first colon in each pair · New Reject uncut matches that exceed the length limit · New Require an over-limit source before accepting a shorter prefix · New Skip FTP schemes inside already-kept organisation URLs · New
Review effort: Balanced
| # Code stays as written. A body whose code and grown rest fit the limit | ||
| # is never cut. | ||
| AMP_GROWTH = 4 | ||
| ENTITY = re.compile(r"&(?=#?[A-Za-z0-9]+;)") |
| text = folded(source) | ||
| if len(text) > limit: | ||
| return |
| if char == " " and before == ":": | ||
| return int(after.startswith(":")) |
| if not isinstance(source, str): | ||
| raise Breach(f"{what} accepted from a field that is not a string") | ||
| whole = folded(source) | ||
| if aligned(kept, whole) == (len(kept), len(whole)): |
| and limit - 1 <= len(raw) <= limit | ||
| and (read < len(whole) or zwsp_due(whole, read)) |
| # a dotless i, pass as GitHub. | ||
| WWW_RE = re.compile(r"(www)\.", re.IGNORECASE | re.ASCII) | ||
| SCHEME_RE = re.compile(r"(https?):(?=//)", re.IGNORECASE | re.ASCII) | ||
| SCHEME_RE = re.compile(r"(https?|ftp):(?=//)", re.IGNORECASE | re.ASCII) |


Closes #111
Authored by an AI agent; human review required
claude-opus-5.5via GitHub Copilot CLI5069951b513068ae575c1274531a47a076c701a6uv run python -B -m unittest tests.test_fuzz_harnesses (new tests against round-5 oracles; 6 expected failures)uv run python -B -m unittest tests.test_fuzz_harnessesuv run python -B /tmp/stress.py (400k-case differential of verify_text against sanitise)uv run python -B /tmp/stress2.py (100k-case run of fuzz_comment.check)git rebase --exec 'uv run python -B -m unittest discover -s tests' 5069951b (each of 5 commits)uv run python -B -m unittest discover -s testsprek run --files fuzz/fuzz_comment.py fuzz/sanitised_text.py tests/test_fuzz_harnesses.py (first run: ruff format rewrote my new lines)prek run --files fuzz/fuzz_comment.py fuzz/sanitised_text.py tests/test_fuzz_harnesses.pyuvx --from gitlint-core gitlint --msg-filename <msg> (each of 5 commits)python fuzz/fuzz_verdict.py -max_total_time=75python fuzz/fuzz_comment.py -max_total_time=75git log --raw --format=%h 5069951b..HEAD (no 100755/120000/160000, no mode change)The
github-code-monkey-botworkflow opened this pull request.Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds per antagonistic review round; after that a maintainer, or the next antagonistic review, takes on any finding that remains, and a maintainer reviews every round before merge.
Round 6 of revision, on its base.
Adds two Atheris fuzz harnesses for the code that judges an untrusted review agent's text. It also fixes the defects the harnesses and the review rounds found.
Commits
Test: Add Atheris fuzz harnesses:fuzz/fuzz_verdict.pycoversparse_verdict/extract_verdict, the rendered check, andsanitise/defuse/contain_links.fuzz/fuzz_comment.pycoverscomment_textandcomment_body.fitted. The oracles live infuzz/github_markdown.pyandfuzz/sanitised_text.pyand import nothing fromscripts/.tests/test_fuzz_harnesses.pyreplays every seed without Atheris and shows each oracle rejecting a wrong result. The README explains how to run a harness by hand.Fix(policy): Require org name to end its segment:contain_linksno longer keepshttps://github.com/<org>)xor<org>'?live.Fix(policy): Replace lone surrogates in sanitise: a\ud800in a verdict no longer crashes the job summary.Fix(policy): Disarm ftp autolinks:ftp://URLs become text.Fix(comment): Contain a link the cut leaves:fittedcontains the body again after a cut.This round (6): fixed all three Copilot findings in the oracles and amended them into commit 1:
fuzz_comment.py): the no-cut bound now adds four only for an&that starts a character reference, since no other&is escaped. A dropped block beside'a & b ' * 250is now caught.sanitised_text.py):alignedaccepts at most one zero-width space at each trigger, so'@' + ZWSP * 599 + '...'no longer passes for'@ critical security issue'.sanitised_text.py): anamp;is now required right after the&of a character reference (&excepted) and accepted nowhere else. This catches'&' * 120 + '...'and a bare©.Each finding has a wrong-result test, and every new test fails against the round-5 oracles.
Checks run
uv run python -B -m unittest discover -s tests: 846 tests OK at each of the 5 commits.prek run --fileson the changed files: passed, including aislop.fuzz_verdict.pyran 285k inputs andfuzz_comment.pyran 20k, both clean.sanitise(400k inputs) and the commentcheck(100k inputs) found no false breach.For the reviewer: the oracles model
review_policy.ENTITY_REandREFERENCE_RESindependently. Check thatfuzz/sanitised_text.pystill matches them if either changes.