Repository navigation
fix(sqs,health): refuse a body that will not parse, and stop calling it a missing queue (#1007) - #1059
Merged
Conversation
…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 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.
This was referenced Sep 18, 2026
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.
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-valuedinput, 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,ListQueueTagsandPurgeQueueread the queue URL through oneshared 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:
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).
ValidationErrorValidationErrorNearer-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:
InvalidParameterValuenames "the input parameter", and a body that will not parse has noparameter to name.
MalformedQueryStringis published at 404 and describes a query string, not a JSON body.MissingParameterasserts which parameter is absent, which is unknowable when nothing decoded.MalformedHttpRequestException/400 is specifically about a body that cannot bedecompressed under the declared content encoding — using it would send a caller to check its
Content-Encodingheader over a syntax error in its own JSON.DescribeEventDetailsalso now parses its body beforeloadEvents, so a malformed body is refusedwithout 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
sqsQueueURLFromRequestfirst, so a body that will notparse 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:
encoding/jsonskips a field the target struct does not declare without type-checking it, so the firstdecode (which knows only
QueueUrl) succeeds and the type error surfaces only on the second. An untestedguard on an input no test sends is indistinguishable from dead code, so
TestSQSAMemberOfTheWrongTypeIsRefusednow 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
ValidationErrorand the offending member is not named: naming it would meananswering
InvalidParameterValuefor a type mismatch andValidationErrorfor a syntax error on thesame operation, which is the one-plugin-two-codes split #950 removed. The common-errors gloss is true of
both.
What is deliberately not done
invented.
sqsRequestedAttributeNamesdecodes the same body a second time forReceiveMessage'sattribute selectors and is unreachable behind
ReceiveMessage's own guard. SQS's FIFO deduplicationdecode 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.gohas thirteen request-body discards, not fourteen.eventArnsis publishedRequired: Yeswith Array Members 1–10 and is still unchecked —substrate answers an empty
successfulSetfor an absent list. That is a separate divergence and isfiled rather than folded into a sweep whose whole value is being mechanical. SQS's own required-member
checks are the same call.
Verification
invalid_body_inventory_test.gogains seventeen cases — sixteen SQS operationsand
DescribeEventDetails— each asserting the code, the status and that the message is thepublished one.
TestSQSInvalidBodyIsRefusedBeforeTheQueueLookupcreates the queue first, so a passing assertionon 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
GetQueueAttributesfor anabsent queue still answers
QueueDoesNotExist, so the lookup moved rather than went away.main's plugins.gofmt/go build/go vetclean,golangci-lint run ./...→0 issues.,go test -racegreen 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.