Skip to content

Reject invalid signed timestamps and fuzz untrusted inputs - #13

Merged
NetworkTheoryAppliedResearchInstitute merged 2 commits into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/protocol-input-fuzzing
Nov 9, 2026
Merged

NetworkTheoryAppliedResearchInstitute merged 2 commits into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/protocol-input-fuzzing

Conversation

@nirmalhk7

Copy link
Copy Markdown
Contributor

SPEC §3 requires rejecting timestamps outside the range of int64 Unix nanoseconds, but the twelve timestamp-bearing message types did not enforce that during signature verification. The encoder skips an invalid timestamp; a sender could sign those incomplete bytes and still get a successful verification result.

Each affected verifier now checks its timestamps before checking the signature. Regression tests cover every timestamp field, including zero time, values just outside the supported range, and both valid endpoints. They fail before the fix and pass afterward. Valid message formats, canonical bytes, domain tags, and public APIs stay the same.

This also adds malformed-response tests and five fuzz targets covering request/response JSON decoding, signature verification, the timestamp-bearing messages, and operator messages. These exercise untrusted inputs beyond the cases covered by the existing examples.

Validation: local build, vet, race-enabled tests, and all 55 independent Python conformance checks passed. Five 10-second fuzz campaigns completed over one million executions combined without another failure. Golden vectors and module dependencies are unchanged.

This is the second change in a three-PR stack. Its branch includes the transport-test commit; review the timestamp/fuzzing commit separately until the first PR is merged. The CI change follows this one.

Depends on #12. The fix and additional tests are in commit f3e09c5.

Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, @nirmalhk7. This closes a real gap: before this change, a signature over the encoder's skipped-field bytes verified for any out-of-range timestamp. The fix is small and easy to follow.

What I checked: commit f3e09c5 compared with f7c802e (#12), by reading the code. I didn't run anything locally. CI passed on this commit: Go build, vet and test, foreign-implementation conformance, and the zero-dependency check.

What looks right:

  • All twelve timestamp-bearing Verify methods check canon.ValidTime before the signature, covering all 14 time fields.
  • The check matches SPEC §3's verifier rule exactly (the full int64-nanosecond range, both ends included).
  • Canonical bytes, vectors, SPEC.md and go.mod are unchanged, so there's no wire change and no new dependency.
  • No clock-skew window is added and Seq/replay handling is untouched, so peers that follow SPEC aren't affected.
  • The regression tests try each time field on its own and check both ends of the range.
  • The CONFORMANCE row claims only what was built.

Non-blocking, fine as follow-ups:

  1. Zero-time messages (an unset time.Time) used to verify and now don't, e.g. identity/keylife.go:106 and employment/employment.go:161. The description says the public APIs stay the same, which is true of the signatures but not of the behaviour. Please note this in the next release notes.
  2. verification_fuzz_test.go:24-39, 56-61: assert 12 message types and 14 time.Time fields visited, so a new or wrapped field can't be skipped silently.
  3. operator/verify_fuzz_test.go:24-26: no seed reaches the key-length checks with a malformed key. The malformed seed has no Nonce, so it stops at ErrNonceTooShort. Add seeds that pair a valid payload with an empty key and a 31-byte key, and give the malformed seed a 16-byte Nonce. In canon/verify_fuzz_test.go:51-53, the oracle is the function VerifySig wraps; assert that the vector seeds verify, or reword the comment.
  4. 🐛 (preexisting) SPEC.md:114 says producers MUST check ValidTime before signing, but no Sign() does (e.g. fees/fees.go:51-52). After this PR such messages fail Verify with no local error. Worth a producer-side guard or an error-returning signer at the next version bump.
  5. 🐛 (preexisting) SPEC.md:115 and canon/canon.go:47,133 say a "decoder" MUST reject bad timestamps, while SPEC §7 and the reference handler leave that to Verify (decode_fuzz_test.go:48-49). A SPEC-first wording fix would make these agree.
  6. 🐛 (preexisting) transport/httpjson/server.go:85 and client.go:82 decode bodies with no size cap. Suggest a separate hardening PR using http.MaxBytesReader and io.LimitReader.

Merge note: this branch carries #12's commit. Merge #12 first, then squash-merge this one. If the branch is restacked, the new head needs a fresh approval.

Approved at the tested commit f3e09c5 on Jodson Graves's instruction.

@NetworkTheoryAppliedResearchInstitute
NetworkTheoryAppliedResearchInstitute merged commit c3fac19 into NTARI-RAND:main Nov 9, 2026
4 checks passed
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.

2 participants