Skip to content

Test: Fuzz the URL, header and body redaction - #520

Merged
ModeSevenIndustrialSolutions merged 4 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-517
Dec 5, 2026
Merged

ModeSevenIndustrialSolutions merged 4 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-517

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #517

Authored by an AI agent; human review required
Command Exit
uv run python .scratch/repro.py (3.11, 3.12, 3.13, 3.14; reproduces the finding on 3.11) 0
UV_PROJECT_ENVIRONMENT=.scratch/venv3.11 uv run --frozen --python 3.11 pytest -q --no-cov tests/test_http_api_tool.py -k 'decoder_limit or own_limit' (old oracle restored; must fail) 1
uv run --frozen pytest -q (at 1ce9467) 0
uv run --frozen pytest -q (at 01d2a93) 0
uv run --frozen pytest -q (at ebb2918) 0
uv run --frozen pytest -q (at f4f3c11) 0
UV_PROJECT_ENVIRONMENT=.scratch/venv3.11 uv run --frozen --python 3.11 pytest -q 0
UV_PROJECT_ENVIRONMENT=.scratch/venv3.12 uv run --frozen --python 3.12 pytest -q 0
uv run --frozen --python 3.14 --isolated --extra test pytest -q --no-cov tests/test_http_api_tool.py -k 'Fuzz or Regression' 0
uv run --frozen --with atheris python tests/fuzz/fuzz_header_body_redaction.py .scratch/win/* (3.13, 438 boundary inputs) 0
uv run --frozen --python 3.11 --with atheris python tests/fuzz/fuzz_header_body_redaction.py .scratch/win/* (3.11, 438 boundary inputs) 0
uv run --frozen --with atheris python tests/fuzz/fuzz_header_body_redaction.py -max_total_time=70 -rss_limit_mb=2048 .scratch/c313 0
UV_PROJECT_ENVIRONMENT=.scratch/venv3.11 uv run --frozen --python 3.11 --with atheris python tests/fuzz/fuzz_header_body_redaction.py -max_total_time=70 -rss_limit_mb=2048 .scratch/c311b 0
uv run --frozen --with atheris python tests/fuzz/fuzz_header_body_redaction.py -runs=0 0
uv run --frozen --with atheris python tests/fuzz/fuzz_header_body_redaction.py .scratch/win/raw992 0
python3 monkey-assets/scripts/message_check.py ffa820860707ab434f947177e7c0022d6d8cd00f 0
AISLOP_NO_TELEMETRY=1 uv run --frozen --with ruff npx -y [email protected] scan --changes --base ffa820860707ab434f947177e7c0022d6d8cd00f --ruff project --json 0
prek run --files README.md src/http_api_tool/sanitize.py tests/fuzz/fuzz_header_body_redaction.py tests/fuzz/fuzz_url_redaction.py tests/test_http_api_tool.py (before fixup; ruff-format rewrapped a la 1
prek run --files README.md src/http_api_tool/sanitize.py tests/fuzz/fuzz_header_body_redaction.py tests/fuzz/fuzz_url_redaction.py tests/test_http_api_tool.py 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. It answers antagonistic review round 1: #520 (review).


Adds two Atheris fuzz harnesses for the redaction helpers in src/http_api_tool/sanitize.py. It also fixes the contract breaches they found, with each fix in its own commit.

Commits

  1. Test: Fuzz the URL, header and body redaction: adds tests/fuzz/fuzz_url_redaction.py and tests/fuzz/fuzz_header_body_redaction.py (harness contract v1). It adds a seed replay with a negative control for each oracle to tests/test_http_api_tool.py, and a README section. Seeds for defects fixed later on the branch are xfail(strict=True) until their fix.
  2. Fix: Keep the host and port in redacted URLs: keeps the IPv6 brackets and port 0, and refuses a host that holds a stray bracket.
  3. Fix: Redact padded headers, contain JSON limits: matches header names with surrounding whitespace trimmed. The integer digit limit (ValueError) and deep nesting (RecursionError) now give the invalid-JSON placeholder.
  4. Fix: Show undecodable input as U+FFFD in logs: shows lone surrogates as U+FFFD, so a strict UTF-8 stdout can print every displayed value.

Antagonistic review (this round)

On Python 3.11, the JSON decoder counts nesting against the interpreter recursion limit. The header oracle decoded one call deeper than production. Reproduced: at depth 992, production decoded and redacted a nested Authorization value, but the oracle hit RecursionError and reported "no placeholder for non-object". Python 3.12 to 3.14 were not affected. Fixed in commit 1:

  • The oracle decodes, re-reads and compares with ORACLE_ROOM (50) frames more recursion room than production has.
  • OracleExhausted is a separate case: running out despite that room is not treated as invalid input. That input must get the placeholder, because production has less room.
  • The placeholder for a decoded object is accepted only if the oracle also runs out with 50 frames less room, so correct code at the limit never fails.
  • Planted nesting depth is now little-endian, so depths below 65,536, which cover the 3.11 to 3.13 limits, are reachable without a NUL byte. The two deep seeds keep their depths.
  • New tests: one checks the oracle at its own decode limit (it must still catch an unredacted secret) and past that limit. The other replays a secret Authorization header, raw and planted, through check_one_input at every depth within 50 of production's limit. It is xfail in commit 1, and commit 3 removes the marker and adds three planted seeds at depths 992, 9,996 and 116,121.
  • Against the old oracle on 3.11, both new tests fail.

Validation

  • uv run pytest: 124 passed at the head. Each commit passes on its own (92/102/117/124 passed, with the expected xfails). The suite also passes on Python 3.11 and 3.12, and the fuzz tests pass on 3.14.
  • prek run --files <changed files>: exit 0. aislop 0.24 (--ruff project): 0 diagnostics, score 100. Commit message check: exit 0.
  • Header harness under Atheris, 70 s each: 26,392 inputs on 3.13 and 52,062 on 3.11, with no failure. Replaying 438 boundary-window inputs as files gave exit 0 on both. -runs=0 and single-file replay: exit 0. The URL harness did not change this round.

For the reviewer

  • The headroom relies on sys.setrecursionlimit. On 3.12 and later the decoder's nesting has its own C budget, so the room has no effect there, and the oracle and production have the same budget.

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 harness can exceed the 2 GiB per-input memory limit, and its incomplete independent header catalogue and restricted selector leave redaction regressions undetected.

2 open issues
What changed in this PR

Adds fuzz coverage for URL, header and body redaction, addressing issue #517 and fixing defects found by the harnesses.

Changes:

  • Adds two Atheris harnesses with seed replay and oracle checks.
  • Preserves IPv6 brackets and port zero during URL redaction.
  • Redacts padded secret headers and handles JSON parsing limits.
File Description
tests/​test_http_api_tool.py Adds seed replay, oracle checks and regression tests.
tests/​fuzz/​fuzz_url_redaction.py Fuzzes URL redaction, parsing and credential extraction.
tests/​fuzz/​fuzz_header_body_redaction.py Fuzzes header and body redaction.
src/​http_api_tool/​sanitize.py Fixes URL reconstruction and header sanitization edge cases.
README.md Documents harness coverage and invocation.

Review effort: Balanced

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

Early-return exemptions in both fuzz targets bypass strict UTF-8 output checks for surrogateescaped inputs, leaving the unencodable-output logging path untested despite issue #517’s requirement.

1 open issue

Review effort: Balanced

Comment thread tests/fuzz/fuzz_url_redaction.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 raw-URL oracle leaves protocol, path, query, and fragment unchecked, allowing dropped query or fragment values to pass the tests.

1 open issue

Review effort: Balanced

Comment thread tests/fuzz/fuzz_url_redaction.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 catalogue plants only api_key, allowing weakened production redaction to expose key and api Key without an oracle failure.

1 open issue

Review effort: Balanced

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 README describes extract_url_credentials output as redacted even though it contains usernames and passwords and must not be logged.

1 open issue

Review effort: Balanced

Comment thread README.md 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.

🟢 Approval recommended

The redaction fuzzing and sanitization changes have no active review issues.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Antagonistic review by agent: 1 finding(s) for the human reviewer.

The production changes are focused, but the header fuzz oracle can report false failures at the JSON recursion boundary.

Antagonistic round 1 of 3. Revision requested from Code Monkey.


Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.

lf-releng-code-monkey-bot Bot and others added 3 commits December 4, 2026 22:37
Add two Atheris harnesses under tests/fuzz/ for the redaction
helpers in sanitize.py. Each oracle compares the whole result with
an independent expectation: the redacted URL keeps the host, port,
path and query and drops the credentials; every secret header is
redacted, every other value kept, and no exception escapes; a body
with a sensitive word is withheld and the rest truncated.

The normal suite replays every seed and proves each oracle rejects
a wrong result. Seeds that reproduce a defect fixed later on this
branch are marked xfail(strict=True). The README says how to run
the harnesses by hand.

Review round 1:
- The header catalogue lacked auth, bearer, access-token and
  x-session-token, and its selector reached eight names. It now
  holds all twelve, a four-bit selector reaches each, and the
  oracle requires redaction for any name in it or in the module's
  list, so dropping one from the module fails the harness.
- A short input could ask for 600 values a million brackets deep,
  over 2 GiB. Generated digits and brackets now share a 4,000,000
  character budget per input; that input is a seed.
- basedpyright saw "listed" as possibly unbound after pytest.skip
  in the discovery test; the check now sits in the try's else.

Review round 2:
- emit() skipped the strict UTF-8 stream for undecodable input, so
  a redacted value holding a lone surrogate was never shown. Both
  harnesses now write every shown value, parse_url's parts too, and
  expect U+FFFD for each lone surrogate. Five undecodable seeds are
  xfail until the fix later on this branch.

Review round 3:
- The raw-URL oracle for parse_url never checked protocol, path,
  query or fragment, so a parse_url that dropped a query passed.
  It now compares all four, typed, with the displayable input
  parsed independently. Negative controls cover each field, a URL
  with params, query and fragment, and undecodable input; the
  stale path in the reused fixture is gone.

Review round 4:
- The body catalogue planted api_key, where the module withholds
  any body holding key, and the raw-body oracle trusted the
  module's list. Narrowing it from key to api_key exposed bodies
  with key unseen. The catalogue now plants key, and the oracle
  withholds a body holding a word from it or the module's list.
  A test shows an empty or narrowed module list fails the oracle.

Review round 5:
- The README said extract_url_credentials drops the credentials from
  a URL, but it returns them and must not be logged. The README now
  names only sanitize_url_for_logging and parse_url as redacting, and
  says the harness checks the extracted pair and never shows it.

Antagonistic review round 1:
- On Python 3.11 the JSON decoder shares the recursion limit, and
  the header oracle decoded one call deeper than production. A
  secret header nested at production's limit was decoded and
  redacted, but the oracle ran out of room and called the input
  invalid. It now decodes and compares with 50 frames more room,
  treats running out despite that as its own case, and accepts the
  placeholder for a decoded object only if it cannot show it with
  50 frames less. Planted depths are little-endian, so depths near
  the limits of 3.11 to 3.13 are reachable. A test checks the
  oracle at its own limit; another, xfail until the fix later on
  this branch, replays a secret header around production's limit.

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>
sanitize_url_for_logging rebuilt the netloc from parsed.hostname,
which urlparse returns without the brackets of an IPv6 literal, and
kept the port only when it was truthy. A redacted IPv6 URL lost its
brackets and so its port, and port 0 vanished. parse_url had the
bracket fix already; both now share one helper.

The fuzzer also found host names that hold a bracket outside an IP
literal, such as "v1.[". No rebuilt URL with such a host parses, so
the helper refuses it: sanitize_url_for_logging shows its
placeholder and parse_url raises ValueError, as it already does for
other malformed URLs. The parse_url docstring now says so.

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>
sanitize_headers_for_logging matched a header name exactly, so
"X-Api-Key " or "\tCookie" kept its secret in the log, while curl
sends the name as written and a lenient server may trim it. It now
matches the name with surrounding whitespace removed.

It also let two decoder limits escape: ValueError for an integer
past the int digit limit and RecursionError for deep nesting. Both
now give the invalid-JSON placeholder, as other bad input does.

The header seeds in the seed replay lose their xfail markers.

The test that replays a secret header nested around the depth this
code can decode loses its xfail marker too, and three seeds plant
one near that depth on Python 3.11, 3.12 and 3.13, and 3.14.

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>
os.environ turns bytes that are not UTF-8 into lone surrogates, and
the redaction helpers passed them through. A strict UTF-8 stdout,
as under en_US.UTF-8, then refused the line: the CLI died with
UnicodeEncodeError while logging the redacted URL or request body,
so the module's promise that every value it returns is safe to
display did not hold.

sanitize_url_for_logging, sanitize_request_body_for_logging and the
display values of parse_url now replace each lone surrogate with
U+FFFD. Truncation still counts input characters, and the sensitive
word check still reads the body as given. Headers already come back
through json.dumps, which escapes them.

The undecodable seeds lose their xfail markers, and a regression
test logs the CLI configuration on a strict UTF-8 stdout.

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>

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.

🟢 Approval recommended

No active review issues are reported for the fuzz-coverage and redaction changes.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Antagonistic review by agent: no line-level findings; the summary below is the verdict.

The redaction fixes and fuzz harnesses are consistent with the inspected callers and regression tests. No actionable defects found in this diff.

Antagonistic round 2 of 3.


Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit fdde9c2 into lfreleng-actions:main Dec 5, 2026
55 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-517 branch December 5, 2026 10:22
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 URL, header and body redaction

2 participants