Skip to content

Test: Add Atheris fuzz harnesses - #112

Merged
ModeSevenIndustrialSolutions merged 5 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-111
Nov 19, 2026
Merged

ModeSevenIndustrialSolutions merged 5 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-111

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #111

Authored by an AI agent; human review required
Command Exit
uv run python -B -m unittest tests.test_fuzz_harnesses (new tests against round-5 oracles; 6 expected failures) 1
uv run python -B -m unittest tests.test_fuzz_harnesses 0
uv run python -B /tmp/stress.py (400k-case differential of verify_text against sanitise) 0
uv run python -B /tmp/stress2.py (100k-case run of fuzz_comment.check) 0
git rebase --exec 'uv run python -B -m unittest discover -s tests' 5069951b (each of 5 commits) 0
uv run python -B -m unittest discover -s tests 0
prek run --files fuzz/fuzz_comment.py fuzz/sanitised_text.py tests/test_fuzz_harnesses.py (first run: ruff format rewrote my new lines) 1
prek run --files fuzz/fuzz_comment.py fuzz/sanitised_text.py tests/test_fuzz_harnesses.py 0
uvx --from gitlint-core gitlint --msg-filename <msg> (each of 5 commits) 0
python fuzz/fuzz_verdict.py -max_total_time=75 0
python fuzz/fuzz_comment.py -max_total_time=75 0
git log --raw --format=%h 5069951b..HEAD (no 100755/120000/160000, no mode change) 0

The github-code-monkey-bot workflow 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

  1. Test: Add Atheris fuzz harnesses: fuzz/fuzz_verdict.py covers parse_verdict/extract_verdict, the rendered check, and sanitise/defuse/contain_links. fuzz/fuzz_comment.py covers comment_text and comment_body.fitted. The oracles live in fuzz/github_markdown.py and fuzz/sanitised_text.py and import nothing from scripts/. tests/test_fuzz_harnesses.py replays every seed without Atheris and shows each oracle rejecting a wrong result. The README explains how to run a harness by hand.
  2. Fix(policy): Require org name to end its segment: contain_links no longer keeps https://github.com/<org>)x or <org>'? live.
  3. Fix(policy): Replace lone surrogates in sanitise: a \ud800 in a verdict no longer crashes the job summary.
  4. Fix(policy): Disarm ftp autolinks: ftp:// URLs become text.
  5. Fix(comment): Contain a link the cut leaves: fitted contains the body again after a cut.

This round (6): fixed all three Copilot findings in the oracles and amended them into commit 1:

  • Plain ampersands (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 ' * 250 is now caught.
  • One mark per trigger (sanitised_text.py): aligned accepts at most one zero-width space at each trigger, so '@' + ZWSP * 599 + '...' no longer passes for '@ critical security issue'.
  • Complete entities (sanitised_text.py): an amp; is now required right after the & of a character reference (&amp; excepted) and accepted nowhere else. This catches '&amp;' * 120 + '...' and a bare &copy;.

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 --files on the changed files: passed, including aislop.
  • gitlint: clean on all 5 commits.
  • Atheris for 75 s each: fuzz_verdict.py ran 285k inputs and fuzz_comment.py ran 20k, both clean.
  • Differential stress tests against the real sanitise (400k inputs) and the comment check (100k inputs) found no false breach.
  • No file changes mode.

For the reviewer: the oracles model review_policy.ENTITY_RE and REFERENCE_RES independently. Check that fuzz/sanitised_text.py still matches them if either changes.

Copilot AI 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.

🟡 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
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

Comment thread fuzz/fuzz_comment.py Resolved
Comment thread fuzz/fuzz_comment.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/github_markdown.py Resolved
Comment thread fuzz/github_markdown.py Resolved
zxiiro
zxiiro previously approved these changes Nov 19, 2026

@zxiiro zxiiro 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.

🤖 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.

Copilot AI 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.

🟡 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

Review effort: Balanced

Comment thread fuzz/github_markdown.py Resolved
Comment thread fuzz/github_markdown.py Resolved
Comment thread scripts/review_policy.py Resolved
Comment thread fuzz/fuzz_comment.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved

Copilot AI 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.

🟡 Changes recommended

Fuzz checks can miss altered or erased verdict text, unsafe rendered links, and invalid pull-request numbers, while repeated unclosed fences can cause quadratic work and timeouts.

5 open issues

Review effort: Balanced

Comment thread fuzz/fuzz_comment.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved

Copilot AI 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.

🟡 Changes recommended

The fuzz oracles still accept out-of-organisation links, live suggestion fences, incorrect truncation, and altered marker spacing.

4 open issues

Review effort: Balanced

Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread fuzz/github_markdown.py Resolved
Comment thread fuzz/github_markdown.py Resolved

Copilot AI 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.

🟡 Changes recommended

The test scan includes untracked environment files, while fuzz oracles can miss fabricated sanitization marks and dropped, inserted, or duplicated code blocks.

4 open issues

Review effort: Balanced

Comment thread fuzz/fuzz_comment.py Resolved
Comment thread fuzz/fuzz_comment.py Resolved
Comment thread fuzz/fuzz_verdict.py Resolved
Comment thread tests/test_fuzz_harnesses.py Resolved

Copilot AI 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.

🟡 Changes recommended

The fuzz oracles mishandle zero-width marks and ampersand escaping, allowing incorrect output that hides warnings or changes rendered text.

3 open issues

Review effort: Balanced

Comment thread fuzz/fuzz_comment.py Resolved
Comment thread fuzz/sanitised_text.py Resolved
Comment thread fuzz/sanitised_text.py Resolved
lf-releng-code-monkey-bot Bot and others added 2 commits November 19, 2026 20:22
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 "&amp;" 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, "&amp;" aside, and accepted nowhere
  else, so "&amp;" for a plain "&" and a bare "&copy;" 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>
lf-releng-code-monkey-bot Bot and others added 3 commits November 19, 2026 20:22
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>

@zxiiro zxiiro 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.

🤖 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.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 7844c3f into lfreleng-actions:main Nov 19, 2026
28 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-111 branch November 19, 2026 20:30

Copilot AI 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.

🟡 Changes recommended

Fuzz checks can accept incorrect truncation or dropped content, while URL sanitisation alters valid GitHub search queries.

6 open issues

Review effort: Balanced

Comment thread fuzz/fuzz_comment.py
# 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]+;)")
Comment thread fuzz/fuzz_comment.py
Comment on lines +176 to +178
text = folded(source)
if len(text) > limit:
return
Comment thread fuzz/sanitised_text.py
Comment on lines +86 to +87
if char == " " and before == ":":
return int(after.startswith(":"))
Comment thread fuzz/sanitised_text.py
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)):
Comment thread fuzz/sanitised_text.py
Comment on lines +163 to +164
and limit - 1 <= len(raw) <= limit
and (read < len(whole) or zwsp_due(whole, read))
Comment thread scripts/review_policy.py
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality Updates to code-quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: Fuzz the verdict and comment handling

3 participants