Skip to content

Bound consumer API JSON requests before state changes - #36

Open
nirmalhk7 wants to merge 2 commits into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/cloudy-consumer-request-limits
Open

nirmalhk7 wants to merge 2 commits into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/cloudy-consumer-request-limits

Conversation

@nirmalhk7

Copy link
Copy Markdown
Contributor

Consumer JSON handlers currently decode unbounded request bodies. A valid signed object can also be accepted before its oversized trailing bytes are noticed, allowing registration or narrative storage to mutate despite an excessive request.

This change puts a shared complete-body guard before all ten consumer JSON write handlers. It rejects declared and streamed overflow with a JSON HTTP 413 response before decoding or mutation, reads at most the configured limit plus one byte for unknown lengths, and closes the original body before dispatch. Accepted bytes reach the existing decoder unchanged. Read or close failures return HTTP 400 without admitting the write.

Defaults are 64 KiB for structural requests and 1 MiB for claims carrying member-local narrative. cloudyd exposes positive -request-bytes and -claim-request-bytes overrides; embedded callers can use NewServerWithLimits. The existing NewServer signature remains compatible and uses the defaults. The deployment guide and conformance notes explain the budgets and their scope.

Validation:

  • Regressions observed oversized signed registration and claim requests succeeding and changing stores before the fix. Missing daemon flags and a rejected-body cleanup defect were also observed before their fixes.
  • Acceptance checks cover every mounted JSON write route, declared and unknown lengths, real chunked HTTP, limit-minus-one/exact/limit-plus-one boundaries, signed registration and narrative preservation, no mutation on overflow, bounded reads, body cleanup, and read/close failures.
  • The full go test -race ./... -count=1 suite, go build ./..., go vet ./..., repository formatting, and whitespace checks pass.
  • Full-repository Qlty smells and checks add no findings: 146 existing smells and 233 existing check findings remain unchanged. Temporary analysis configuration was removed after verification. The completion gate was run manually because automatic hook enforcement was unavailable.
  • Commit 12cf534 is SSH-signed and DCO-signed-off; its signature was verified locally.

These are per-request deployment controls, not consensus or financial rules. Public reads, signed artifact formats, covenant semantics, escrow policy and /v0/ node relay traffic retain their existing contracts. Aggregate concurrency and HTTP timeouts remain separate concerns. Existing in-memory storage and ephemeral-key limitations remain; no production deployment verification is claimed.

The route-registration changes share server.go with #31; preserve both its reference-read additions and these write guards during integration. #34 changes marketplace browsing and is not a prerequisite for this fix. This draft is ready for independent review; hosted CI and maintainer approval remain pending.

Read complete request bodies within configurable byte budgets before any
write handler decodes or mutates state. Reject declared and streamed
overflow with HTTP 413, including excess bytes after a valid signed object.
Preserve accepted bytes and close the original body before dispatch.

Default structural requests to 64 KiB and narrative claims to 1 MiB. Expose
positive deployment overrides through cloudyd flags and an explicit server
constructor. Document the deployment boundary and conformance scope.

Cover all ten write routes, exact boundaries, real chunked HTTP, signed
registration and claims, read limits, and read/close failures. Race-enabled
Go tests, build, vet, formatting and Qlty baseline comparison pass.

Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
@nirmalhk7
nirmalhk7 marked this pull request as ready for review November 11, 2026 23:11
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.

1 participant