Repository navigation
Description
#950 corrected the error code at every site that guards json.Unmarshal on a request body. This is
the complement: 95 sites across 38 files discard the unmarshal error entirely, so a malformed body
is not refused at all.
$ grep -rn "_ = json.Unmarshal(req.Body" --include=*.go emulator/ | grep -v _test.go | wc -l
95
Heaviest: sqs_plugin.go 13, sso_plugin.go 9, apigateway_plugin.go 7, ram_plugin.go 5, then
lambda_plugin.go, ecs_plugin.go, cloudwatchlogs_plugin.go and apigatewayv2_plugin.go at 4 each.
Thirty more files carry one to three.
This is a different defect from #950's, not more of it. There the code was wrong; here there is no
refusal, and the request proceeds against a zero-valued input struct. Two consequence classes are
verified, and they need different fixes:
1. A dropped filter answers 200 with the wrong result set
ServiceQuotasPlugin.listRequestedServiceQuotaChangeHistory
(emulator/servicequotas_plugin.go:257-264):
var input struct {
ServiceCode string `json:"ServiceCode"`
Status string `json:"Status"`
}
if len(req.Body) > 0 {
_ = json.Unmarshal(req.Body, &input)
}A body that will not parse leaves both members empty, so both filters are silently dropped and the
caller receives the unfiltered history at HTTP 200. This is the worst shape of the two: nothing in the
response tells the caller their filter was ignored, and a consumer asserting on a filtered set gets a
superset that happens to contain what it expected. A test looking for the presence of a record passes;
one asserting the count fails for a reason that points nowhere near the body.
2. A dropped identifier answers the wrong code
sqsQueueURLFromRequest (emulator/sqs_plugin.go:129-137) returns input.QueueURL after discarding
the error, so a malformed body yields an empty queue URL, which then fails loadQueue. The caller
is told the queue does not exist rather than that their body is unparseable — the same
wrong-code outcome #950 fixed, arrived at by a different route, and it feeds all thirteen SQS sites
through one helper.
Why a green suite holds these too
The same structural reason #950 recorded: a test that builds its request from a Go value cannot reach
this path, because json.Marshal produces valid JSON by construction. emulator/invalid_body_code_test.go
and emulator/invalid_body_inventory_test.go now send raw bytes, but only at the 66+ operations that
have a guard — by construction they cannot cover the 95 that do not.
Scope
The 95 are not one fix. Classifying them is most of the work, and the classes plausibly are:
- A required member is read → refuse the body, following Twenty-seven plugins answer twenty-one different codes for an unparseable body, and at least three are codes the service does not publish #950's per-service constructor (the
*_errors.gofiles) so the code matches what the service publishes. - Only optional members are read, and an absent body is legitimate — several sites already wrap the
call inif len(req.Body) > 0for exactly that reason. A body that is present and malformed is still
not the same as an absent one, and should be refused;if len(req.Body) > 0is the wrong guard for
the wrong condition. - The body is genuinely irrelevant to the operation, in which case
//nolint:errcheckwith a stated
reason is the honest outcome —kms_plugin.go:424and:1218already do this ("optional body"), which
is the pattern to follow rather than a bare_ =.
A separate, larger set of _ = json.Unmarshal calls decode state read back from the store rather
than a caller's body (dynamodb_plugin.go:1736, elasticache_plugin.go:921, ecr_plugin.go:989, and
others — 122 total including the 95). Those are out of scope here: a failure there means substrate wrote
corrupt state, which is a different bug with a different answer, and conflating the two would make this
issue unshippable.
Acceptance criteria
- All 95 caller-body sites are classified into the three classes above, with the classification
recorded rather than implied by the diff. - Every site reading a required member refuses a malformed body with the code its service publishes,
reusing the existing per-service constructor where one exists. - Every site left discarding the error carries
//nolint:errcheckand a stated reason, so a
later reader can tell a decision from an oversight — no bare_ =remains on a caller body. -
listRequestedServiceQuotaChangeHistoryno longer answers 200 with an unfiltered result set for a
malformed body, asserted over the wire on raw bytes. -
sqsQueueURLFromRequestdistinguishes a malformed body from an absentQueueUrl, so the thirteen
SQS sites stop reporting a missing queue for a parse failure. - A wire test per corrected site, asserting status alongside code per fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923, in the pattern
invalid_body_inventory_test.goestablished. -
docs/services.mdrecords the classification under the existing "A request body that will not
parse" section, so the 95 are not re-derived. -
CHANGELOG.mdupdated.
Activity
scttfrdmn commentedon Sep 18, 2026
Premise check before the PRs open
Re-counted against the tree at
5bd5177. The headline numbers all hold exactly: 95 sites in 38files; SQS 13, SSO 9, API Gateway 7, RAM 5, then Lambda, ECS, CloudWatch Logs and API Gateway v2 at 4;
122 total
_ = json.Unmarshalincluding the state-read set the issue correctly puts out of scope. Thegrep in the body is also complete — no other discard form of a caller body exists in the tree.
Four corrections, one of which changes the shape of the work substantially.
1. The finding that most reduces the work: 35 of the 38 files already contain a checked
json.Unmarshal(req.Bodyguard. Only three do not —sqs_plugin.go(13 sites),sqs_messageattributes.go(1) andhealth_plugin.go(1). So 80 of the 95 sites need no new AWSarchaeology at all: the file already establishes which code that service answers for an unparseable
body, and the correction is to route the discarding site through it. Only the remaining 15 need a
code decided, and both services resolve to the common-errors
ValidationError/400 under #950's step 2.The issue frames classification as "most of the work"; classification is mostly already done, in the
files themselves.
2. Seven sites already carry the
//nolint:errcheck // optional bodyform, not two. The issuenames
kms_plugin.go:424and:1218; the pattern is atkms_plugin.go:471and:1324(drifted),stepfunctions_plugin.go:516,:760and:974,secretsmanager_plugin.go:512, andssm_plugin.go:553. That matters because it makes the third class the issue proposes an establishedconvention rather than a new one — and because those seven are already at the criterion's target state,
so they are 7 of the 95 that need no edit.
3. "It feeds all thirteen SQS sites through one helper" conflates two different thirteens.
sqsQueueURLFromRequest(sqs_plugin.go:129-137) is one of the 13 discard sites in that file, andit separately has 13 callers (14 occurrences of the name, one being the definition). The other 12
discard sites are separate handlers with their own
_ =. So fixing the helper fixes the wrong-codeoutcome for its 13 callers and leaves 12 discard sites in the same file. The acceptance criterion
that names "the thirteen SQS sites" is satisfiable only by reading it as the callers; the file's own
13 sites still need the sweep.
4. The "no bare
_ =remains" criterion is not lint-enforceable, which is worth knowing before it iswritten as a criterion.
errcheckignores assignments to the blank identifier unlesscheck-blankis set, and
.golangci.ymldoes not set it — so_ = json.Unmarshal(...)and_ = json.Unmarshal(...) //nolint:errcheck // reasonare treated identically: neither is reported. Thecriterion therefore needs a script plus a
maketarget to be enforced going forward, in the shapescripts/check-doc-versions.shestablished. Turningcheck-blankon globally is not the cheapalternative it looks like: it would light up every deliberate discard in the tree, including the
state-read set this issue puts out of scope.
Also:
servicequotas_plugin.go:263— the site the issue leads with — is bypassingsqUnmarshal(
:374), a checked helper that already exists in the same file and has three other callers. Thatis the single cheapest fix of the 95, and
sqUnmarshalis the canonical helper for the rest to copy:it treats an empty body as absent and a present-but-malformed one as a refusal, which is precisely the
distinction the issue argues
if len(req.Body) > 0gets wrong.Three slices
The issue ships as three PRs, in order, each narrowing the same sweep:
with no existing guard to follow.
sqsQueueURLFromRequestgains an error return so a malformed bodyis distinguishable from an absent
QueueUrl, which is what its 13 callers need.*InvalidBody()constructor — acm, efs, eventbridge,firehose, kinesis, kms, lambda, sagemaker, servicequotas, sesv2, ssm, stepfunctions. Mechanical:
each site routes through the constructor its own service's guarded sites already use.
where a per-service code has to be read off a page rather than out of the file.
Every slice carries its own
invalid_body_inventory_test.gorows, its own classification table indocs/services.mdunder "A request body that will not parse", and its own CHANGELOG entry. Theenforcement script lands with slice 3, when the last bare
_ =on a caller body is gone and it canactually pass.
test(sqs): the second decode in nine handlers catches a member of the…
fix(sqs,health): refuse a body that will not parse, and stop calling …
scttfrdmn commentedon Sep 18, 2026
Slice 1 of 3 shipped in #1059 (
0fb36e2). This issue stays open: 60 of the 95 sites remain.What shipped
SQS and AWS Health — the two services whose files contained no checked guard anywhere to copy a code
from, which is why they went first. Fifteen sites, fourteen of them corrected and one recorded as
unreachable:
sqs_plugin.gosqsInvalidBody()sqs_messageattributes.goReceiveMessage's own guardhealth_plugin.gohealthInvalidBody(), and moved aboveloadEventsBoth codes are
ValidationError/400 from the service's own common-errors page, under step 2 of #950'srule. The near-miss codes each page also publishes are unused with the reasoning recorded on the
constructor: SQS's
InvalidParameterValuenames a parameter a failed decode does not have,MalformedQueryStringis published at 404 and describes a query string,MissingParameterassertswhich parameter is absent; Health's
MalformedHttpRequestExceptionis about a body that cannot bedecompressed.
The strongest observable was worse than this issue's title says.
GetQueueAttributes,DeleteQueue,ListQueueTagsandPurgeQueueread the queue URL through one shared helper and passed the resultstraight into the queue lookup, so a discarded decode yielded an empty URL and the lookup answered
QueueDoesNotExist— not "a malformed body is not refused" but "a malformed body is refused as a missingqueue", which sends the reader to look at infrastructure rather than at the request. Fixing it meant
changing
sqsQueueURLFromRequest's signature across its thirteen callers, not editing handlers in place.Two corrections to this issue's premises, beyond the ones already posted
sqs_plugin.gohas thirteen request-body discard sites, not fourteen. The fourteenth,recordFIFODedup, decodes stored state, not a request. It is out of scope by construction: acorrupted state blob is not a caller error, and answering a caller-error code for one would be a new
defect rather than a fix. Worth checking for the same shape in the remaining 23-file tail before
assuming every
_ = json.Unmarshalthere is a request body.code. Those nine read the queue URL through the helper first, so a body that will not parse has been
refused one call earlier. What their own decode catches is a body that parses but contradicts a
member's type —
encoding/jsonskips a field the target struct does not declare withouttype-checking it, so the first decode succeeds and the type error surfaces only on the second. Codecov
is what surfaced this: nine guards showed as untested, and the fix was nine test cases rather than
nine deletions. Expect the same double-decode shape in the remaining slices wherever a handler
reads an identifier through a shared helper before decoding its own members — the guard needs a
wrong-typed-member case, not an unparseable-body case.
The member is deliberately not named in the message: naming it would mean
InvalidParameterValuefor atype mismatch and
ValidationErrorfor a syntax error on the same operation, which is theone-plugin-two-codes split #950 removed.
What remains
*InvalidBody()constructor —lambda(4),stepfunctions(3),kms(2),sesv2(2),firehose(2),eventbridge,efs,ssm,servicequotas,sagemaker,kinesis,acm(1 each)sso(9),apigateway(7),ram(5),ecs,cloudwatchlogs,apigatewayv2(4 each),opensearch,dynamodb(3 each),wafv2,timestream,redshiftdata,cognito_identity,backup,athena(2 each), andsecretsmanager,glue,fsx,emrserverless,ecr,cognito_idp,cloudtrail,batch,appsync(1 each)Acceptance criterion 3 — "no bare
_ =on a request-body unmarshal" — still needs a script plus a maketarget, as posted earlier:
errchecktreats a bare_ =identically to a//nolintwith a reason, so itcannot enforce this. That lands with slice 3, once the count it asserts is zero.
docs/services.mdcarries the slice under "A guard that was never there: the discarded unmarshalerror", including both provenance readings and the double-decode finding.
fix(#1007): refuse a body that will not parse in the twelve services …
scttfrdmn commentedon Sep 18, 2026
Second slice shipped in #1060 (
c36a5da). Twenty more sites, in the twelve services whose own*InvalidBody()constructor already held the answer — so no new AWS reading was needed for any of them: Lambda 4, Step Functions 3, KMS 2, SES v2 2, Firehose 2, and one each in EventBridge, EFS, Systems Manager, Service Quotas, SageMaker, Kinesis and ACM.Three findings worth recording against this issue's own analysis:
Fourteen of the twenty were hiding behind a true statement. They sat inside
if len(req.Body) > 0 { _ = json.Unmarshal(…) }, six of them under//nolint:errcheck // optional body. The body is optional on all fourteen — they are list operations whose answer to an empty request is "everything" — but that is what the length check is for. Discarding the error from a body that is present is a second and separate decision, and the stated reason for the first was covering it. That is a slightly different shape of defect from the one the issue describes: not an unconsidered discard, but a considered one whose consideration answered a different question.The corresponding risk runs the other way, so
TestInvalidBodyLeavesAnAbsentBodyAlonenow pins twelve operations still answering 200 to an absent body. Without it, a guard that refused an empty body would satisfy every refusal assertion in this sweep and break every consumer that lists without filters.Three sites needed more than the error checked.
ListAppshad no length check at all, so a plain guard would have refused the empty body AWS accepts. Service Quotas' site was bypassingsqUnmarshal— the helper in its own file that this issue already identifies as the canonical one — and was the only site in that file decoding by hand, which is exactly why it was the only one still discarding. And Lambda's four update operations parsed below their resource lookup, so the guard in place would have answered404for an unparseable body naming an absent function while the two #1006 moved answer400for the same request; all six of Lambda's guarded sites now parse first. That does not settle the tree-wide ordering question — S3's seven sites are still lookup-first with stated reasons — it makes one plugin answer one code.Six of the twenty are not reachable on
POST(four Lambda updates and EFSUpdateFileSystemroute onPUT,ListEmailIdentitiesonGETwith its filters in the body), so they carry their own test table rather than being quietly absent from the shared one.One recorded reading was reversed deliberately:
kms_error_status_test.gohad saidListKeys/ListAliaseswere excluded because "all three treat the body as optional and ignore a parse failure, which is a different decision and not one this issue disturbs". This is the issue that disturbs it, and the comment now says so.Remaining scope, and two new findings about it
60 sites in 23 files remain — the inline-literal tail — plus the script and make target for acceptance criterion 3, which
errcheckcannot express. 22 of the 23 files carry a precedent code in an existing checked guard in the same file, so the tail is mostly mechanical. Two of those precedents are wrong, and the third file has none at all:RAM answers
MalformedQueryString/400 for a body-parse failure, and that is wrong twice over. RAM's Common Errors page does not publishMalformedQueryStringat all. The code is real, but it belongs to the Query-protocol common list (EC2's page), where it is published at HTTP 404 and glossed "The query string contains a syntax error" — the URL's query string, not the body. RAM's own operation pages publishInvalidParameterException/400, "The operation failed because a parameter you specified isn't valid."CloudTrail answers
InvalidParameterCombinationException/400, which means something else. The code is published on CloudTrail operation pages, glossed "This exception is thrown when the combination of parameters provided is not valid" — mutually incompatible parameters, not a parse failure. It is also not published onLookupEventsat all, whose complete Errors list is seven codes with no parse or serialization code among them. CloudTrail publishes neitherInvalidRequestExceptionnorValidationExceptionon any page checked; its generic-input code isInvalidParameterException/400.A useful structural note behind both: AWS has consolidated the JSON-protocol Common Errors boilerplate, and the RAM, CloudTrail and DynamoDB pages are now byte-identical to one another and distinct from EC2's Query-protocol list. Any plugin that sourced a "common error" from the EC2 page needs the same check. The shared JSON list's only body-scoped code is
MalformedHttpRequestException/400, and its published text scopes it to decompression/content-encoding, not JSON syntax — the same finding fix(sqs,health): refuse a body that will not parse, and stop calling it a missing queue (#1007) #1059 recorded for Health.OpenSearch has no checked guard anywhere, and its three sites are search/index operations on the domain data plane rather than the AWS control plane, so the error shape is not an
AWSErrorquestion in the same way. That one needs its own decision rather than a copied precedent.Separately, nine of the 23 files leak
err.Error()into the message from their existing checked guards —encoding/json's own text, naming a Go struct field, from an endpoint whose purpose is to look like AWS. That is the #950 message-leak class reappearing in the files this sweep is about to touch, and the tail slice will have to decide whether to fix them in passing or file them.Staying open for the third slice.
test(#1007): assert every changed site over the wire, including the t…
docs(#1015): Lambda's table documented an operation that does not exi…
docs(#1064): the common-errors reference has three generations, not t…
fix(#1066): thirty-five body-parse refusals stop leaking the decoder'…
fix(#1365): no non-test code discards a json.Marshal or xml.Marshal e…