Skip to content

fuzz: run the harnesses in CI, add five more, and fix the 11 crashes they found - #149

Merged
vsn411 merged 3 commits into
secfoo-com:mainfrom
karthickmk2001:fix/121-fuzz-in-ci
Nov 20, 2026
Merged

vsn411 merged 3 commits into
secfoo-com:mainfrom
karthickmk2001:fix/121-fuzz-in-ci

Conversation

@karthickmk2001

Copy link
Copy Markdown
Collaborator

Problem

Closes #121.

fuzz/fuzz_parsers.py existed, but nothing ran it, and the newer parsers of untrusted input (the SARIF/JSONL export, the skill loader, config.toml, uploaded documents, runtime ingest) had no harness at all.

What changed

Five new harnesses in fuzz/, each a check(data: bytes) that asserts the parser's contract:

Harness Input Contract
fuzz_sarif_export.py finding records as JSONL SARIF validates against the 2.1.0 schema (with and without --runtime-priority), one result per record, every ruleIndex matches its ruleId; JSONL round-trips; records never mutated
fuzz_skill_loader.py skill file bytes a Skill (custom ones: kebab-case id, name, description, body, int version, sha256 of the exact bytes) or SkillLoadError
fuzz_config.py config.toml bytes a SecfooConfig whose every field has its declared type, or ConfigError
fuzz_docext.py selector byte + PDF/DOCX/PPTX a string, within 30s per input (libFuzzer -timeout and -rss_limit_mb on CI)
fuzz_runtime_ingest.py an NDJSON batch, run the way POST /events runs it never raises; every non-blank line is stored or skipped with a reason

fuzz_parsers.py moves onto the same runner with its checks unchanged. fuzz/_common.py fuzzes with Atheris when it's installed and otherwise replays the files it's given, so python fuzz/fuzz_config.py crash-<sha1> reproduces a CI crash on Windows or macOS too.

Seed corpora in fuzz/corpus/<harness>/ (33 files, 281 KB), built from real inputs by fuzz/make_seed_corpus.py: the NodeGoat export and reports in examples/sample-output/, the example and built-in skills, the config.toml from docs/REFERENCE.md, small real PDF/DOCX/PPTX files, and sensor batches. .gitattributes marks the corpus -text so autocrlf can't change reproducer bytes.

Property tests: tests/test_property_fuzz_targets.py (73 tests) drives each harness's check with Hypothesis strategies shaped like real input, replays every corpus file, and adds readable regression tests for each crash. These run in the normal pytest tests on every platform.

CI: .github/workflows/fuzz.yml runs each harness for 60 seconds (Python 3.12, atheris==3.1.0) on PRs touching report/, skills/, settings.py, docext.py, runtime/, finding_filters.py or fuzz/, nightly, and on demand. New inputs go to a scratch work/ folder, never into the committed corpus; a crash uploads its reproducer as fuzz-crash-<harness>.

CONTRIBUTING.md documents all of this. The JSONL export moves from cli.py into report/jsonl.py so it can be fuzzed directly; its output is unchanged, and a test pins the format.

Crashes found and fixed

Each one reproduces on main. Its reproducer is in fuzz/corpus/<harness>/crash-*, and the corpus replay test keeps it fixed.

Runtime ingest: these four reach the network API. ingest_events rolls back on any exception, so one bad line from a sensor discarded the entire batch with a 500. Now only that line is skipped, and the rest of the batch is stored:

Input line Was Reproducer
JSON nested 20,000 deep RecursionError crash-deep-nesting.ndjson
an integer over 4,300 digits ValueError (Python's int-string limit) crash-int-over-4300-digits.ndjson
"\ud800" in a text field or stack frame UnicodeEncodeError from SQLite crash-lone-surrogate.ndjson, crash-surrogate-entry-frame.ndjson
count over 2^63 OverflowError from SQLite crash-count-over-int64.ndjson

test_lines_that_used_to_500_are_skipped_and_the_rest_is_stored in test_runtime_api.py posts each line through the real endpoint, with and without app= (which takes a second JSON-parsing path in _with_app_env), and expects a 200.

SARIF export: a model-written location_line over 4,300 digits passed the [0-9]+ check and crashed int(). Lines are now capped at 9 digits, and the file location is kept. (crash-location-line-5000-digits.jsonl)

Skill loader: invalid UTF-8 escaped _build_skill as UnicodeDecodeError. The user-folder loader happens to catch that, but --skill-file <url> and skills validate don't. It is now a SkillLoadError. (crash-invalid-utf8.md)

config.toml:

  • Crashed inside load_config: defaults = 1, mcp_servers = 'x', [mcp_servers] written as a table, name = [1], and invalid UTF-8 (AttributeError, TypeError, UnicodeDecodeError).
  • Loaded with wrong types, then crashed later: an MCP args = [1] or command = 5 reaches the claude/gemini mcp add argv and raises TypeError: expected str ... not int (verified against _gemini_add_command). The same goes for a nested env table and defaults.timeout = "soon". These are now a ConfigError that names the key.
  • [defaults] agent = "nope" reached AgentId("nope") in secfoo run as a traceback. It is now Error in config.toml: defaults.agent must be one of ..., with exit code 1.
  • The documented example config still loads (test_the_documented_example_config_still_loads).

A deeper local run, 2,000 Hypothesis examples per property, found nothing beyond these.

Testing

I couldn't run Atheris itself locally (Windows, no WSL), so this PR's own Fuzz workflow run is the first real coverage-guided pass. It triggers on this PR because it touches fuzz/**.

Follow-ups

  • report/sarif.py uses PureWindowsPath.as_uri(), which is deprecated in Python 3.14 and removed in 3.19. That's pre-existing and left as is here.

🤖 Generated with Claude Code

…they found

fuzz/fuzz_parsers.py existed but nothing ran it, and the newer parsers of
untrusted input had no harness at all.

Harnesses (fuzz/), each a `check(data: bytes)`:
- fuzz_sarif_export: records -> SARIF validates against 2.1.0, JSONL
  round-trips, records unchanged
- fuzz_skill_loader: a Skill or SkillLoadError, never anything else
- fuzz_config: a correctly typed SecfooConfig or ConfigError
- fuzz_docext: text or "" within a time limit
- fuzz_runtime_ingest: every NDJSON line stored or skipped
- fuzz_parsers moved onto the same runner

fuzz/_common.py fuzzes with Atheris when installed and otherwise replays
files, so a CI crash reproduces on any platform. Seed corpora come from
real inputs (fuzz/make_seed_corpus.py); .gitattributes keeps them
byte-exact. tests/test_property_fuzz_targets.py drives each check with
Hypothesis and replays the whole corpus on every platform.

.github/workflows/fuzz.yml: each harness for 60s on PRs touching these
parsers and nightly; uploads the reproducer on a crash.

Crashes fixed (reproducers in fuzz/corpus/*/crash-*):
- runtime ingest: deep JSON nesting (RecursionError), an int over 4300
  digits (ValueError), lone surrogates in a text field or frame
  (UnicodeEncodeError), a count over int64 (OverflowError). Each rolled
  back the whole batch, a 500 on POST /api/runtime/v1/events; now only
  that line is skipped.
- SARIF export: a location_line over 4300 digits (ValueError).
- skill loader: invalid UTF-8 escaped as UnicodeDecodeError, which
  --skill-file URLs and `skills validate` don't catch.
- config.toml: `defaults = 1`, a non-array or non-table mcp_servers, a
  non-string server name, invalid UTF-8 (AttributeError / TypeError /
  UnicodeDecodeError). Wrongly typed MCP command/args/env/headers/transport
  and defaults.agent/depth/timeout loaded and then crashed in a subprocess
  argv or `secfoo run`; they are now ConfigError naming the key, and an
  unknown defaults.agent/depth is a clean CLI error.

JSONL export moved from cli.py into report/jsonl.py so it can be fuzzed;
output unchanged.

Closes secfoo-com#121

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Satyanarayana Vuppala and others added 2 commits November 20, 2026 10:25
Conflicts with secfoo-com#146/secfoo-com#147 resolved by keeping both sides: fuzz_parsers keeps
the shared _common runner plus main's MalformedReportError handling and
coverage-table checks; settings.py keeps the new MCP type checks plus
main's `hosts` parsing and `defaults.context`.

Review follow-ups for secfoo-com#149 (secfoo-com#121), pushed by the maintainers:

- fuzz.yml: replays every seed corpus and reproducer (blocking), then
  fuzzes 30 s non-blocking on PRs and 60 s blocking nightly; concurrency
  group; checkout without persisted credentials. parser-fuzz.yml (atheris
  2.3.0, weekly) is removed: the matrix replaces it.
- `secfoo run`: an unknown defaults.agent / defaults.depth is an error only
  when no --agent / --depth flag overrides it.
- Config: shapes that always worked keep working -- `timeout = 1800.0`,
  scalar env/header values (coerced to strings), a blank command/url next
  to the other, any transport name. Values that used to crash still raise
  a ConfigError naming the key.
- SARIF: a zero-padded line ("0000000042") keeps its region.
- Runtime evidence: only json.loads is covered by the broad decode-error
  catch, so a validation bug surfaces instead of becoming "not valid JSON".
- Heartbeat API: the same crash classes as /events (deep nesting, 4300+
  digit ints, values over 64 bits, lone surrogates) now get 400/422, not 500.
- Ingest harness clears the runtime tables per input, so a crash reproduces
  from its own file; corpus replay runs files without an extension too.
- CONTRIBUTING.md: fuzz_parsers' contract and the workflow schedule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411

vsn411 commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Thank you, @karthickmk2001. This is a big, well-built piece of work: five new harnesses sharing one runner that fuzzes, replays and runs under Hypothesis, a real seed corpus, and 11 genuine crashes fixed, each with its reproducer kept. Action SHAs matched main, no secrets, and no pull_request_target.

The branch had fallen behind #146/#147 and review found a few behaviour changes, so I merged main in and pushed the follow-ups onto your branch (4adece7, 3d743ac) rather than send it back:

  • Conflicts: kept both sides. fuzz_parsers keeps your _common runner plus Fail malformed reports safely and resolve adversarial evaluation review #147's MalformedReportError rule and Add --context sources: host classification, MCP reader hints, local document inlining and per-source coverage (#125) #146's coverage-table checks; settings.py keeps your MCP type checks plus hosts and defaults.context.
  • One fuzz workflow: parser-fuzz.yml (atheris 2.3.0, weekly) is removed, since your matrix replaces it. Every run now first replays the seed corpus and reproducers (blocking, deterministic), then fuzzes 30 s non-blocking on PRs and 60 s blocking nightly, so a long-standing crash found by chance can't fail an unrelated PR (its reproducer is still uploaded). Also added a concurrency group and persist-credentials: false, since the job installs and runs PR code.
  • secfoo run: an unknown defaults.agent / defaults.depth is now an error only when no --agent / --depth flag overrides it. Flags always win, as documented.
  • Config compatibility: timeout = 1800.0, scalar env/headers values (PORT = 8080, coerced to strings), a blank command/url next to the other, and other transport names keep working as before. Values that used to crash still get a ConfigError naming the key.
  • SARIF: a zero-padded line such as 0000000042 keeps its region (the cap is now on the value, not the character count).
  • Runtime evidence: the broad decode-error catch now covers only json.loads, so a future validation bug surfaces instead of being reported as "not valid JSON".
  • Heartbeat API: it had the same crash classes you fixed for /events (deep nesting, 4300+ digit ints, values over 64 bits, lone surrogates); those now get 400/422 instead of 500.
  • Harness details: the ingest harness clears the runtime tables per input, so a crash reproduces from its own file, and the corpus replay test also runs files without an extension (libFuzzer's crash-<sha1>).

Each change has a regression test. CI is green on everything, including all six fuzz jobs. Merging, and thank you again.

@vsn411
vsn411 merged commit 2208de0 into secfoo-com:main Nov 20, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown

Leaderboard update

karthickmk2001 now has 88 points (rank #1, Silver). 12 more to reach Gold.

Full leaderboard

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.

Run the fuzz harness in CI and extend it to the SARIF/JSONL exporters, the skill loader and the config parser

2 participants