Skip to content

95 sites discard the body-unmarshal error, so a malformed body is not refused at all #1007

Closed

Description

@scttfrdmn

#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.go files) 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 in if len(req.Body) > 0 for 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) > 0 is the wrong guard for
    the wrong condition.
  • The body is genuinely irrelevant to the operation, in which case //nolint:errcheck with a stated
    reason is the honest outcome — kms_plugin.go:424 and :1218 already 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:errcheck and a stated reason, so a
    later reader can tell a decision from an oversight — no bare _ = remains on a caller body.
  • listRequestedServiceQuotaChangeHistory no longer answers 200 with an unfiltered result set for a
    malformed body, asserted over the wire on raw bytes.
  • sqsQueueURLFromRequest distinguishes a malformed body from an absent QueueUrl, 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.go established.
  • docs/services.md records the classification under the existing "A request body that will not
    parse"
    section, so the 95 are not re-derived.
  • CHANGELOG.md updated.

Activity

  1. added this to the v0.119.0 milestone on Sep 17, 2026
  2. added
    type: bug
    on Sep 17, 2026
  3. scttfrdmn commented on Sep 18, 2026

    @scttfrdmn
    OwnerAuthor

    Premise check before the PRs open

    Re-counted against the tree at 5bd5177. The headline numbers all hold exactly: 95 sites in 38
    files; SQS 13, SSO 9, API Gateway 7, RAM 5, then Lambda, ECS, CloudWatch Logs and API Gateway v2 at 4;
    122 total _ = json.Unmarshal including the state-read set the issue correctly puts out of scope. The
    grep 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.Body guard.
    Only three do not — sqs_plugin.go (13 sites),
    sqs_messageattributes.go (1) and health_plugin.go (1). So 80 of the 95 sites need no new AWS
    archaeology 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 body form, not two. The issue
    names kms_plugin.go:424 and :1218; the pattern is at kms_plugin.go:471 and :1324 (drifted),
    stepfunctions_plugin.go:516, :760 and :974, secretsmanager_plugin.go:512, and
    ssm_plugin.go:553. That matters because it makes the third class the issue proposes an established
    convention 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, and
    it 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-code
    outcome 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 is
    written as a criterion.
    errcheck ignores assignments to the blank identifier unless check-blank
    is set, and .golangci.yml does not set it — so _ = json.Unmarshal(...) and
    _ = json.Unmarshal(...) //nolint:errcheck // reason are treated identically: neither is reported. The
    criterion therefore needs a script plus a make target to be enforced going forward, in the shape
    scripts/check-doc-versions.sh established. Turning check-blank on globally is not the cheap
    alternative 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 bypassing sqUnmarshal
    (:374), a checked helper that already exists in the same file and has three other callers. That
    is the single cheapest fix of the 95, and sqUnmarshal is 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) > 0 gets wrong.

    Three slices

    The issue ships as three PRs, in order, each narrowing the same sweep:

    1. SQS and Health (15 sites, 3 files) — the only sites needing a code decided, and the only files
      with no existing guard to follow. sqsQueueURLFromRequest gains an error return so a malformed body
      is distinguishable from an absent QueueUrl, which is what its 13 callers need.
    2. The 12 services that already have a *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.
    3. The remaining files, whose guarded sites use an inline literal — the tail, and the only slice
      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.go rows, its own classification table in
    docs/services.md under "A request body that will not parse", and its own CHANGELOG entry. The
    enforcement script lands with slice 3, when the last bare _ = on a caller body is gone and it can
    actually pass.

  4. scttfrdmn commented on Sep 18, 2026

    @scttfrdmn
    OwnerAuthor

    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:

    File Sites Disposition
    sqs_plugin.go 13 refused with sqsInvalidBody()
    sqs_messageattributes.go 1 retained; unreachable behind ReceiveMessage's own guard
    health_plugin.go 1 refused with healthInvalidBody(), and moved above loadEvents

    Both codes are ValidationError/400 from the service's own common-errors page, under step 2 of #950's
    rule. The near-miss codes each page also publishes are unused with the reasoning recorded on the
    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; Health's MalformedHttpRequestException is about a body that cannot be
    decompressed.

    The strongest observable was worse than this issue's title says. 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 — not "a malformed body is not refused" but "a malformed body is refused as a missing
    queue", 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

    1. sqs_plugin.go has thirteen request-body discard sites, not fourteen. The fourteenth,
      recordFIFODedup, decodes stored state, not a request. It is out of scope by construction: 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. Worth checking for the same shape in the remaining 23-file tail before
      assuming every _ = json.Unmarshal there is a request body.
    2. Nine of the twelve SQS handler guards are unreachable by an unparseable body, and are still not dead
      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/json skips a field the target struct does not declare without
      type-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 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.

    What remains

    Slice Scope Sites New code decisions
    2 The twelve services with an existing *InvalidBody() constructor — lambda (4), stepfunctions (3), kms (2), sesv2 (2), firehose (2), eventbridge, efs, ssm, servicequotas, sagemaker, kinesis, acm (1 each) 20 none — each file's own constructor is the answer
    3 The twenty-three-file inline-literal tail — sso (9), apigateway (7), ram (5), ecs, cloudwatchlogs, apigatewayv2 (4 each), opensearch, dynamodb (3 each), wafv2, timestream, redshiftdata, cognito_identity, backup, athena (2 each), and secretsmanager, glue, fsx, emrserverless, ecr, cognito_idp, cloudtrail, batch, appsync (1 each) 60 one per service, under the same two-step rule

    Acceptance criterion 3 — "no bare _ = on a request-body unmarshal" — still needs a script plus a make
    target, as posted earlier: errcheck treats a bare _ = identically to a //nolint with a reason, so it
    cannot enforce this. That lands with slice 3, once the count it asserts is zero.

    docs/services.md carries the slice under "A guard that was never there: the discarded unmarshal
    error"
    , including both provenance readings and the double-decode finding.

  5. added a commit that references this issue on Sep 18, 2026
  6. scttfrdmn commented on Sep 18, 2026

    @scttfrdmn
    OwnerAuthor

    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 TestInvalidBodyLeavesAnAbsentBodyAlone now 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. ListApps had no length check at all, so a plain guard would have refused the empty body AWS accepts. Service Quotas' site was bypassing sqUnmarshal — 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 answered 404 for an unparseable body naming an absent function while the two #1006 moved answer 400 for 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 EFS UpdateFileSystem route on PUT, ListEmailIdentities on GET with 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.go had said ListKeys/ListAliases were 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 errcheck cannot 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:

    1. RAM answers MalformedQueryString/400 for a body-parse failure, and that is wrong twice over. RAM's Common Errors page does not publish MalformedQueryString at 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 publish InvalidParameterException/400, "The operation failed because a parameter you specified isn't valid."

    2. 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 on LookupEvents at all, whose complete Errors list is seven codes with no parse or serialization code among them. CloudTrail publishes neither InvalidRequestException nor ValidationException on any page checked; its generic-input code is InvalidParameterException/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.

    3. 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 AWSError question 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.

  7. added a commit that references this issue on Sep 18, 2026
  8. added 3 commits that reference this issue on Sep 18, 2026
  9. added a commit that references this issue on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions