Skip to content

feat(fuzz): a cargo-fuzz target per untrusted-input parser - #1289

Merged
chappie-daemon merged 9 commits into
rewrite/mainfrom
factory/043-fuzz-targets
Nov 30, 2026
Merged

chappie-daemon merged 9 commits into
rewrite/mainfrom
factory/043-fuzz-targets

Conversation

@chappie-daemon

Copy link
Copy Markdown
Collaborator

What

fuzz/ is a cargo-fuzz crate of its own (an empty [workspace], so the root workspace stays at ten members) with one target per hand-written parser that takes bytes from a socket or an operator's file:

target parser
client_frame nostream_core::messages::decode
filter nostream_core::filter::validate_filter
settings nostream_config::load
nip11 nostream_relay::nip11::parse_relay_pubkey + document

Each target path-depends on the crate that owns its parser (nothing is copied), calls it on every input, and asserts the invariant its doc comment states. Seeds under fuzz/seeds/<target>/ are the cases the crates' own tests already use.

The crate carries its own nightly-2026-08-21 pin: cargo-fuzz always emits -Zsanitizer=address and the repository pin is a stable that rejects it. Nothing outside fuzz/ selects that toolchain; the root pin is unedited and the root build still reports 1.99.1.

Work is bounded by the runtime, not by a timer in the harness: every campaign passes -max_len=131072 (the socket's own payload bound), -timeout=10 and -rss_limit_mb=2048.

The 60 s campaigns

cargo-fuzz 0.13.2, nightly-2026-08-21, -max_total_time=60 -max_len=131072 -timeout=10 -rss_limit_mb=2048:

target first INITED result
client_frame cov: 641 ft: 1005 Done 2008021 runs in 61 second(s)
filter cov: 501 ft: 668 Done 2195083 runs in 61 second(s)
settings cov: 4847 ft: 7804 Done 7202 runs in 61 second(s)
nip11 cov: 5250 ft: 6275 Done 25673 runs in 61 second(s)

All four exit 0; find fuzz/artifacts -type f prints 0. The stub-target baseline is INITED cov: 14, and the target bodies are the greps the job records, so the figures are trend, not proof.

One campaign did stop: the settings target's first run crashed on a five-byte input, !lsd\n (sha256 06be3a69fd05e8374906612833afaff0d52bc994e58551ccaebf7991d77506f0). The cause was the harness, not the loader: its liveness check counted a YAML tagged null as a document load must reject, but serde_yaml::Value::is_null() untags, so load_user_settings treats !tag on an empty node the same as an empty file — no overrides, no issue, used_defaults = false. The expectation now uses Value::is_null(); no file under crates/ changed, and the clean rerun above is the record. The input is not committed as a seed because the job's seed set is fixed.

A 60 s run is a smoke test, not a campaign: libFuzzer grows its input length from the seeds and reaches a few KiB here (87–4190), nowhere near the 128 KiB -max_len bound. A finding above that bound would not be production-reachable.

CI and the runbook

fuzz/** joins the rust path filter and rust-checks gains one cd fuzz && cargo check after its existing checks — compile only, no campaign — so a parser change that breaks the crate fails its own PR. docs/rewrite/fuzz.md is the runbook: install, the exact environment, the seed flow, the four build and four run commands, what a finding means, and the longer campaign that is written down and not run: it waits on #871's tauceti runbook and the operator's word because this sandbox has no spare cores.

Validation

  • cargo fmt --all --check — exit 0, no output
  • cargo clippy --workspace --all-targets --all-features -- -D warnings — exit 0
  • the strict --lib --bins clippy pass — exit 0
  • cargo test -p nostream-core -p nostream-config -p nostream-relay -p nostream-scan --all-features — exit 0, 17 s, the same counts as the base (core 145 / 105 / 58 / 31 / 27, config 62 / 25 / 6, relay 8 / 29 / 66 / 115 and the rest)
  • cargo test -p nostream-core -p nostream-config -p nostream-relay -p nostream-storage --all-features — exit 0
  • cargo fuzz list prints exactly the four names; the four cargo fuzz build runs exit 0

cargo test --workspace --all-features is not the oracle here: it fails at the base commit on two nostream-admin network-health cases for want of egress.

Addresses #1286. (Closes would not close it: this PR targets rewrite/main, not the default branch.)

The crate is its own workspace and carries its own nightly pin because cargo-fuzz emits
-Zsanitizer and the repository pin is a stable. Each target path-depends on the crate that
owns its parser and calls it on every input; seeds come from the crates' own tests.
fuzz/** joins the rust path filter, and rust-checks runs one `cd fuzz && cargo check`
after its existing checks: a parser change that breaks the crate fails its PR instead of
surfacing at the next campaign. No campaign runs in CI.
Install, environment, seeds, the four build and run commands, what a 60 s smoke test
does and does not reach, what a finding means, and the longer campaign gated on #871 and
tauceti.
@changeset-bot

changeset-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f44c599

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2204bcd5-8ac7-4580-9e81-2f7fd9767290

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@socket-security

socket-security Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​libfuzzer-sys@​0.4.134710093100100

View full report

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge, with one non-blocking correction still needed in the runbook.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with one non-blocking correction still needed in the runbook.

Findings

  1. P2 Production accepts larger inputs ▶

Summary

Adds a separate cargo-fuzz crate with four targets, committed seeds, and a runbook.

  • Fuzzed client frames are checked against their accepted REQ and COUNT limits.
  • Fuzzed filter inputs are checked against accepted filter rules.
  • Fuzzed settings files are checked through the real settings loader.
  • NIP-11 key parsing and document generation now have a fuzz target.
  • The standalone fuzz crate has its own toolchain, CI checks, and runbook.

Reviews (4) · Last reviewed commit: "fix(fuzz): remove the settings scratch d..." · Reviewed by Greptile

Comment thread fuzz/fuzz_targets/settings.rs Resolved
Comment thread docs/rewrite/fuzz.md Outdated
Comment on lines +144 to +146
A finding above the 128 KiB payload bound is not production-reachable: the transport refuses a
larger frame before any parser sees it. It is still a bug worth fixing, but it cannot be a
denial of service against the relay.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Production accepts larger inputs

The runbook incorrectly rules out production failures above 128 KiB. DEFAULT_MAX_PAYLOAD is only a fallback: the shipped network.maxPayloadSize is 524288, and load_document reads settings files without that socket limit.

The documented -max_len=131072 commands skip part of the shipped socket range. This advice could also cause a real finding to be dismissed. Describe 128 KiB as the chosen campaign limit, cover the shipped 512 KiB socket limit, and judge settings findings separately.

Comment thread fuzz/fuzz_targets/filter.rs Resolved
@coveralls

coveralls commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 46304498508

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.01%) to 77.617%

Details

  • Coverage decreased (-0.01%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 1 coverage regression across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/utils/relay-probe/dns-probe.ts 1 81.82%

Coverage Stats

Coverage Status
Relevant Lines: 12114
Covered Lines: 9823
Line Coverage: 81.09%
Relevant Branches: 6355
Covered Branches: 4512
Branch Coverage: 71.0%
Branches in Coverage %: Yes
Coverage Strength: 760.58 hits per line

💛 - Coveralls

The settings harness created its document directory with create_dir_all, which adopts a
directory someone else made first and lets fs::write follow a settings.yaml symlink planted
inside it; it now creates a unique 0700 directory with create_dir and treats an existing path
as a harness failure. The filter target's note named {"ids": null} as the non-object example,
which reaches validate_prefixes; it now names null. The three test files are rustfmt-clean, and
fuzz/seeds/nip11/pow-enabled.yaml enables adaptive PoW so the target's min_pow_difficulty clause
is reachable from the committed seeds.
…ach target is fed

resources/default-settings.yaml:212 ships network.maxPayloadSize: 524288 and transport
returns it, so every campaign command passes -max_len=524288 and the runbook cites the setting
rather than the 131072 fallback constant. The CI section names the crate's format gate, which
checks fuzz/ with cargo fmt --manifest-path fuzz/Cargo.toml --check. The target table now says
what each target is actually fed, and the fuzz/** cost names kani-proofs and windows-cli-check.
greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 29, 2026
The default runs' length controller kept lim under 4 KiB, so -max_len=524288 bound a range
nothing reached. A second form passes -len_control=0 so the mutator goes for bound-sized inputs;
all four targets reached lim: 524288 in a 60 s pass and found nothing. The runbook says why the
default lim stays small, what len_control buys, and that settings and nip11 pay for it in runs
per second.
@greptile-apps
greptile-apps Bot dismissed their stale review November 29, 2026 19:37

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 29, 2026
The harness's directory survived the run with the planted document in it. Each execution now
creates a 0700 directory with create_dir and removes it in Drop, so a clean campaign leaves
nothing behind and a killed one leaves at most its current input. The runbook narrows its
opening claim (two peer-reachable parsers are untargeted; #1293 tracks them), says to refresh
fuzz/Cargo.lock with the root lock (different graph, 228 packages against 335, 58 shared crates
at other versions), notes that settings and nip11 parse through unsafe-libyaml
(RUSTSEC-2024-0449) so a finding there may need a bound in our caller, and couples
-rss_limit_mb and -timeout to the configured payload bound with the measured peaks.
@greptile-apps
greptile-apps Bot dismissed their stale review November 29, 2026 20:05

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@chappie-daemon
chappie-daemon merged commit 8488bf1 into rewrite/main Nov 30, 2026
22 checks passed
@chappie-daemon
chappie-daemon deleted the factory/043-fuzz-targets branch November 30, 2026 00:02
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.

3 participants