Repository navigation
fuzz: run the harnesses in CI, add five more, and fix the 11 crashes they found - #149
Merged
Merged
Conversation
…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]>
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]>
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 The branch had fallen behind #146/#147 and review found a few behaviour changes, so I merged
Each change has a regression test. CI is green on everything, including all six fuzz jobs. Merging, and thank you again. |
Leaderboard update
karthickmk2001 now has 88 points (rank #1, Silver). 12 more to reach Gold. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #121.
fuzz/fuzz_parsers.pyexisted, 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 acheck(data: bytes)that asserts the parser's contract:fuzz_sarif_export.py--runtime-priority), one result per record, everyruleIndexmatches itsruleId; JSONL round-trips; records never mutatedfuzz_skill_loader.pySkill(custom ones: kebab-case id, name, description, body, int version, sha256 of the exact bytes) orSkillLoadErrorfuzz_config.pyconfig.tomlbytesSecfooConfigwhose every field has its declared type, orConfigErrorfuzz_docext.py-timeoutand-rss_limit_mbon CI)fuzz_runtime_ingest.pyPOST /eventsruns itfuzz_parsers.pymoves onto the same runner with its checks unchanged.fuzz/_common.pyfuzzes with Atheris when it's installed and otherwise replays the files it's given, sopython 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 byfuzz/make_seed_corpus.py: the NodeGoat export and reports inexamples/sample-output/, the example and built-in skills, theconfig.tomlfromdocs/REFERENCE.md, small real PDF/DOCX/PPTX files, and sensor batches..gitattributesmarks the corpus-textsoautocrlfcan't change reproducer bytes.Property tests:
tests/test_property_fuzz_targets.py(73 tests) drives each harness'scheckwith Hypothesis strategies shaped like real input, replays every corpus file, and adds readable regression tests for each crash. These run in the normalpytest testson every platform.CI:
.github/workflows/fuzz.ymlruns each harness for 60 seconds (Python 3.12,atheris==3.1.0) on PRs touchingreport/,skills/,settings.py,docext.py,runtime/,finding_filters.pyorfuzz/, nightly, and on demand. New inputs go to a scratchwork/folder, never into the committed corpus; a crash uploads its reproducer asfuzz-crash-<harness>.CONTRIBUTING.mddocuments all of this. The JSONL export moves fromcli.pyintoreport/jsonl.pyso 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 infuzz/corpus/<harness>/crash-*, and the corpus replay test keeps it fixed.Runtime ingest: these four reach the network API.
ingest_eventsrolls 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:RecursionErrorcrash-deep-nesting.ndjsonValueError(Python's int-string limit)crash-int-over-4300-digits.ndjson"\ud800"in a text field or stack frameUnicodeEncodeErrorfrom SQLitecrash-lone-surrogate.ndjson,crash-surrogate-entry-frame.ndjsoncountover 2^63OverflowErrorfrom SQLitecrash-count-over-int64.ndjsontest_lines_that_used_to_500_are_skipped_and_the_rest_is_storedintest_runtime_api.pyposts each line through the real endpoint, with and withoutapp=(which takes a second JSON-parsing path in_with_app_env), and expects a 200.SARIF export: a model-written
location_lineover 4,300 digits passed the[0-9]+check and crashedint(). 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_skillasUnicodeDecodeError. The user-folder loader happens to catch that, but--skill-file <url>andskills validatedon't. It is now aSkillLoadError. (crash-invalid-utf8.md)config.toml:load_config:defaults = 1,mcp_servers = 'x',[mcp_servers]written as a table,name = [1], and invalid UTF-8 (AttributeError,TypeError,UnicodeDecodeError).args = [1]orcommand = 5reaches theclaude/gemini mcp addargv and raisesTypeError: expected str ... not int(verified against_gemini_add_command). The same goes for a nestedenvtable anddefaults.timeout = "soon". These are now aConfigErrorthat names the key.[defaults] agent = "nope"reachedAgentId("nope")insecfoo runas a traceback. It is nowError in config.toml: defaults.agent must be one of ..., with exit code 1.test_the_documented_example_config_still_loads).A deeper local run, 2,000 Hypothesis examples per property, found nothing beyond these.
Testing
tests/test_property_fuzz_targets.pyand the new API test: 73 passed (also 66 property tests at 2,000 examples each)settings, skills, report, runtime, cli, mcp, docext, property parsers): 588 passedpython fuzz/fuzz_<harness>.py fuzz/corpus/<harness>ruff checkis clean on every file this PR adds or changes. The 70 findings incli.pyare untouched and pre-existing (Make lint and security scanning blocking in CI: ruff has 133 errors behind|| true, bandit findings are unreviewed, pip-audit never runs #114); bandit finds no high-severity issues.I couldn't run Atheris itself locally (Windows, no WSL), so this PR's own
Fuzzworkflow run is the first real coverage-guided pass. It triggers on this PR because it touchesfuzz/**.Follow-ups
report/sarif.pyusesPureWindowsPath.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