Skip to content

fix(sqs,health): refuse a body that will not parse, and stop calling it a missing queue (#1007) - #1059

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/1007-sqs-health-body
Sep 18, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/1007-sqs-health-body

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

First of #1007's three slices: the two services whose files contained no checked guard anywhere to
copy a code from. The other thirty-five files in the inventory already contain one, which is why eighty
of the ninety-five sites need no fresh AWS archaeology — but these fifteen did.

What was wrong

Every guarded site wrote _ = json.Unmarshal(req.Body, &input) and carried on with a zero-valued
input, so a truncated or malformed body was not an error at all. That is a worse failure than the wrong
code #950 and #1003 corrected across fourteen services: a wrong code is at least a refusal, while a
discarded one produces a plausible success — or a refusal about something else entirely.

Four SQS operations were the latter, and they are the strongest observable in the slice.
GetQueueAttributes, DeleteQueue, ListQueueTags and PurgeQueue read the queue URL through one
shared helper and passed the result straight into the queue lookup, so a discarded decode yielded an
empty URL and the lookup refused it as a missing queue:

$ # malformed JSON, against an account whose queue exists
$ curl -H 'X-Amz-Target: AmazonSQS.GetQueueAttributes' -d '{"QueueUrl":' …
before: QueueDoesNotExist / 400   "The specified queue does not exist"
after:  ValidationError    / 400   "The input fails to satisfy the constraints specified by an AWS service"

That is the most expensive shape of wrong answer, because it sends the reader to look at their
infrastructure rather than at the request they just sent.

Provenance

No SQS operation page and no AWS Health operation page publishes an error for an undecodable body, so
both codes come from the service's own common-errors page — step 2 of the rule #950 established (a
per-operation code where one covers every guarded site, otherwise the service-wide page).

Service Code Status Page and gloss
SQS ValidationError 400 Common Errors: "The input fails to satisfy the constraints specified by an AWS service"
AWS Health ValidationError 400 Common Error Types: "The input doesn't meet the required format or constraints"

Nearer-looking codes on the same pages are deliberately unused, each because it would misdescribe the
fault and send the reader to the wrong place. The reasoning is recorded on each constructor rather than
only here:

  • SQS InvalidParameterValue names "the input parameter", and a body that will not parse has no
    parameter to name.
  • SQS MalformedQueryString is published at 404 and describes a query string, not a JSON body.
  • SQS MissingParameter asserts which parameter is absent, which is unknowable when nothing decoded.
  • Health MalformedHttpRequestException/400 is specifically about a body that cannot be
    decompressed under the declared content encoding — using it would send a caller to check its
    Content-Encoding header over a syntax error in its own JSON.

DescribeEventDetails also now parses its body before loadEvents, so a malformed body is refused
without consulting state.

A finding the sweep turned up: nine handlers decode the body twice

Codecov flagged nine of the twelve SQS parse guards as untested, and the reason was not a gap in the
table. Those nine read the queue URL through sqsQueueURLFromRequest first, so a body that will not
parse has been refused one call earlier and their own guard can never see one. It is still reachable,
by a body that parses cleanly but contradicts a member's type:

{"QueueUrl": "http://localhost/123456789012/typed-queue", "Attributes": "not-a-map"}

encoding/json skips a field the target struct does not declare without type-checking it, so the first
decode (which knows only QueueUrl) succeeds and the type error surfaces only on the second. An untested
guard on an input no test sends is indistinguishable from dead code, so TestSQSAMemberOfTheWrongTypeIsRefused
now sends one case per handler — against a queue that exists, since all nine look the queue up before
decoding — plus one asserting a well-typed body still answers 200, so a guard that refused everything
would not pass.

The code stays ValidationError and the offending member is not named: naming it would mean
answering InvalidParameterValue for a type mismatch and ValidationError for a syntax error on the
same operation, which is the one-plugin-two-codes split #950 removed. The common-errors gloss is true of
both.

What is deliberately not done

  • Two discards are retained, with their reachability recorded in place rather than a second refusal
    invented. sqsRequestedAttributeNames decodes the same body a second time for ReceiveMessage's
    attribute selectors and is unreachable behind ReceiveMessage's own guard. SQS's FIFO deduplication
    decode reads stored state, not a request — a corrupted state blob is not a caller error, and
    answering a caller-error code for one would be a new defect rather than a fix. This also corrects the
    plan's site count: sqs_plugin.go has thirteen request-body discards, not fourteen.
  • eventArns is published Required: Yes with Array Members 1–10 and is still unchecked —
    substrate answers an empty successfulSet for an absent list. That is a separate divergence and is
    filed rather than folded into a sweep whose whole value is being mechanical. SQS's own required-member
    checks are the same call.

Verification

  • The shared table in invalid_body_inventory_test.go gains seventeen cases — sixteen SQS operations
    and DescribeEventDetails — each asserting the code, the status and that the message is the
    published one.
  • TestSQSInvalidBodyIsRefusedBeforeTheQueueLookup creates the queue first, so a passing assertion
    on the four lookup-carrying operations is known to come from the new guard rather than from a lookup
    that happened to fail anyway; a fifth subtest asserts a well-formed GetQueueAttributes for an
    absent queue still answers QueueDoesNotExist, so the lookup moved rather than went away.
  • Nineteen of the new assertions were mutation-checked: they fail against main's plugins.
  • Gate: gofmt/go build/go vet clean, golangci-lint run ./... → 0 issues., go test -race
    green on both toolchains, docs/authz reference checks clean, docs site builds, e2e green. Coverage
    85.3% emulator / 84.8% total, above the 85.1%/84.6% floor.

Part of #1007 — two slices remain (the twelve services with an existing *InvalidBody()
constructor, then the twenty-three-file inline-literal tail), so the issue stays open.

…it a missing queue (#1007)

Fifteen sites in SQS and AWS Health wrote `_ = json.Unmarshal(req.Body, &input)` and carried on with a
zero-valued input, so a malformed request body was not an error at all. That is worse than the wrong
code #950 and #1003 corrected, because a wrong code is at least a refusal; a discarded one produces a
plausible success, or a refusal about something else.

Four SQS operations were doing the latter. GetQueueAttributes, DeleteQueue, ListQueueTags and PurgeQueue
read the queue URL through one shared helper and passed the result straight into the queue lookup, so a
discarded decode yielded an empty URL and the lookup answered QueueDoesNotExist -- the emulator telling a
caller its queue was missing when the queue was fine and the request was not. The helper now returns the
refusal to its thirteen callers, and the new test creates the queue first so a passing assertion is known
to come from the guard rather than from a lookup that failed for its own reasons. A well-formed request
for an absent queue still answers QueueDoesNotExist: the lookup moved, it did not go away.

Both codes come from the service's own common-errors page, under step 2 of #950's rule -- no SQS or
Health operation page publishes an error for an undecodable body. SQS answers ValidationError/400 "The
input fails to satisfy the constraints specified by an AWS service"; Health answers ValidationError/400
"The input doesn't meet the required format or constraints". Nearer-looking codes are unused with the
reasoning recorded on each constructor: SQS's InvalidParameterValue names a parameter a failed decode
does not have, MalformedQueryString is published at 404 and describes a query string, MissingParameter
asserts which parameter is absent, and Health's MalformedHttpRequestException is about a body that
cannot be decompressed.

DescribeEventDetails now parses before loading event state. Two discards are retained with their
reasoning in place rather than refused twice: sqsRequestedAttributeNames is unreachable behind
ReceiveMessage's own guard, and the FIFO deduplication decode reads stored state, where a caller-error
code would be a new defect. `eventArns`' published Required: Yes / 1-10 bounds and SQS's own
required-member checks are separate classes and are filed rather than folded in.

This is the first of #1007's three slices; the other two cover the twelve services with an existing
*InvalidBody() constructor and the twenty-three-file inline-literal tail.
@codecov

codecov Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

… wrong type (#1007)

Codecov showed nine of the twelve SQS parse guards untested, and the reason was not a gap in the table:
those nine handlers read the queue URL through sqsQueueURLFromRequest first, so a body that will not
parse has already been refused one call earlier and their own guard can never see one. It is still
reachable, by a body that parses cleanly but contradicts a member's type -- the first decode skips a
field its target does not declare without type-checking it, so the type error surfaces only on the
second. An untested guard on an input no test sends is indistinguishable from dead code, so each of the
nine now has a case, plus one asserting a well-typed body still succeeds.

The code stays ValidationError and the member is not named: naming it would mean InvalidParameterValue
for a type mismatch and ValidationError for a syntax error on the same operation, which is the
one-plugin-two-codes split #950 removed.
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