Skip to content

fix(stepfunctions,ssm): a parse guard answers a published code (#950) - #1003

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/parse-guard-codes-950
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/parse-guard-codes-950

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Part of #950 — the first two acceptance criteria for Step Functions and Systems Manager. The
inventory-wide criteria (the remaining ~19 services, MalformedData, MSK's unverifiable BadRequest)
remain and land in a second PR, so this carries no closing keyword.

What was wrong

Twenty-seven handlers answered an error code their own service does not publish, for a request body
that would not parse:

Service Sites Answered Published anywhere in the service's docs?
Step Functions 15 (12 in stepfunctions_plugin.go, 3 in stepfunctions_tags.go) InvalidRequest No
Systems Manager 10 InvalidRequest No
Systems Manager 2 (SendCommand, GetCommandInvocation) SerializationException, message err.Error() No

A consumer branching on either code was matching something no SDK models. This is the defect #923
found and fixed at twenty-one KMS sites.

The two SerializationException sites are beyond the issue's inventory, which counted ten for
Systems Manager. They are the same defect wearing a second wrong code, and they additionally passed
encoding/json's error text through as the message — so a caller was told which Go struct field failed
to unmarshal by an endpoint whose whole purpose is to look like AWS.

What it answers now

ValidationError at 400, from the service's own common-errors page: "The input doesn't meet the
required format or constraints. Check that all required parameters are included and that values are
valid."
The message is substrate's: "the request body is not valid JSON" — the only actionable fact a
caller has.

Why the common page and not an operation page. A body that will not parse belongs to no single
operation; nothing was decoded, so substrate knows only what X-Amz-Target claimed. For Systems Manager
that is not an argument from convenience but the only route: all twelve operation pages were read and
each publishes only narrow resource-specific 400s — ParameterNotFound, InvalidKeyId,
InvalidResourceType, HierarchyLevelLimitExceededException and the like — plus InternalServerError
at 500. None describes a request that could not be read at all.

Why the KMS answer transfers rather than coincides. Step Functions', Systems Manager's and KMS's
common-errors pages are byte-identical: the same fifteen entries, in the same order, with the same
statuses. All three spell the code ValidationError, with no Exception suffix.

Two near misses, declined on the record

Candidate Published Declined because
ValidationException Step Functions publishes it at 400 on five of the fifteen guarded operations — CreateStateMachine, UpdateStateMachine, DeleteStateMachine, StartExecution, StopExecution Answering it everywhere leaves ten sites reporting a code their own operation does not publish — this defect relocated. Answering it at five only makes one failure produce two codes inside one plugin.
MalformedHttpRequestException On the common page at 400 Published scope is the transport layer: "the request body can't be processed. This typically happens when the request body can't be decompressed using the specified content encoding algorithm." A body that arrived intact and then failed to parse is not that.

Two premise corrections to #950

  1. "Neither page lists ValidationException among its errors" is wrong. It is listed, at 400, in
    the Errors section of five Step Functions operations. The issue had checked API_DescribeStateMachine
    and API_GetParameter only, and both of those do omit it. The evidence is now the reason for
    declining
    it rather than an absence.

    The trap underneath: an error named in prose is not an error a shape publishes. Five Systems
    Manager pages name ValidationException in prose — "if the specified name for a parameter contains
    spaces between characters, the request fails with a ValidationException error"
    — and none of the
    five lists it in an Errors section. Four Step Functions pages do the same for their Distributed Map
    note.

  2. "Systems Manager already has ssm_errors.go-shaped precedent to extend" — it did not exist. The
    two constructors the issue meant were in ssm_tags.go. The file is created here.

Structure

New emulator/stepfunctions_errors.go and emulator/ssm_errors.go, following emulator/kms_errors.go:
one helper per published code, so a status is chosen once rather than at each call site. Seven existing
constructors moved in unchanged (sfnInvalidArnError, sfnResourceNotFoundError, the three
sfn*DoesNotExist, ssmInvalidResourceID, ssmInvalidResourceType) — compiler-verified as a pure move.

Why a green suite held twenty-seven wrong codes

Every test that builds a request from a Go value is structurally incapable of reaching these guards:
json.Marshal produces valid JSON by construction. New shared helper rawSignedCall (generalised from
kmsRawCall, which now delegates to it) hands the server raw bytes.

emulator/invalid_body_code_test.go has a case for each of the twenty-seven operations rather than a
representative sample — the defect was per-site duplication of one literal, so the assertion that matters
is that no site was missed. Each asserts the status and the code together, since a decoded error
struct carries only the code while a consumer's retry logic branches on the status, plus that the message
carries no encoding/json decoder text.

Compatibility

  • Step Functions: a caller matching InvalidRequest for an unparseable body at any of
    CreateStateMachine, DescribeStateMachine, UpdateStateMachine, DeleteStateMachine,
    StartExecution, StartSyncExecution, StopExecution, DescribeExecution, GetExecutionHistory,
    CreateActivity, DescribeActivity, DeleteActivity, TagResource, UntagResource or
    ListTagsForResource now sees ValidationError. The status was already 400 and is unchanged.
  • Systems Manager: the same for InvalidRequest at ten operations, and for SerializationException
    at SendCommand and GetCommandInvocation. Those two also stop reporting encoding/json's text, so
    an assertion on the message body changes.
  • No other service, status or success path changes.

Verification

The nine-command gate, all green. Coverage 84.7% emulator / 84.2% total, up from the 84.6/84.1
baseline.

Fifteen Step Functions handlers and ten Systems Manager ones answered
InvalidRequest for a request body that would not parse; the remaining two
Systems Manager handlers, SendCommand and GetCommandInvocation, answered
SerializationException with encoding/json's own error text as the message.
Neither string appears anywhere in either service's documentation, so a
consumer branching on either was matching something no SDK models -- the
defect #923 found and fixed at twenty-one KMS sites.

All twenty-seven now answer ValidationError at 400, from the service's own
common-errors page. The code has to come from that page because a body that
will not parse belongs to no single operation, and for Systems Manager it is
the only route: all twelve operation pages publish narrow resource-specific
400s plus InternalServerError, and none describes a request that could not be
read at all. That page is AWS boilerplate -- Step Functions', Systems
Manager's and KMS's are byte-identical, and all three spell the code without
an Exception suffix, which is what makes the KMS finding transfer.

Two near misses are declined on the record. ValidationException is real at
Step Functions but is in the Errors section of only five of the fifteen
guarded operations, so answering it everywhere relocates the defect and
answering it at five splits one failure across two codes.
MalformedHttpRequestException's published scope is the transport layer.
Five Systems Manager pages and four Step Functions pages name
ValidationException in prose without listing it as an error, which is the
trap; the issue's premise that neither service lists it at all is corrected
here.

Each service's refusals now live in one file -- new stepfunctions_errors.go
and ssm_errors.go, following kms_errors.go -- so a status is chosen once, and
seven existing constructors moved into them unchanged.

Every test that builds a request from a Go value is structurally incapable of
reaching these guards, since json.Marshal produces valid JSON. A shared
rawSignedCall helper hands the server raw bytes, and there is a case for each
of the twenty-seven operations rather than a sample, asserting the status and
the code together.
@scttfrdmn scttfrdmn added this to the v0.118.0 milestone Sep 17, 2026
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 212f8ef into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/parse-guard-codes-950 branch September 17, 2026 08:57
scttfrdmn added a commit that referenced this pull request Sep 18, 2026
…it a missing queue (#1007) (#1059)

* fix(sqs,health): refuse a body that will not parse, and stop calling 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.

* test(sqs): the second decode in nine handlers catches a member of the 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.
scttfrdmn added a commit that referenced this pull request Sep 18, 2026
…that already had the answer (#1060)

Twenty more sites, in the twelve services whose own *InvalidBody() constructor already carried the
provenance #950 and #1003 established: 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. No new
AWS reading was needed for any of them, which is why this slice is separable from the first.

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. A new test asserts the half a table of refusals cannot
see: an absent body still lists everything. Without it, a guard that refused an empty body would
satisfy every refusal assertion added here 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. It gained the check the other thirteen already had.
  - Service Quotas' site was bypassing sqUnmarshal, a helper in its own file that already handles
    the absent body and returns the refusal. It was the only site in that file decoding by hand,
    which is exactly why it was the only one still discarding.
  - Lambda's four update operations parsed below their resource lookup, so adding the guard there
    would have answered 404 for an unparseable body naming an absent function while AddPermission
    and TagResource — moved above the lookup by #1006 — answer 400 for the same request. One
    plugin, two codes, for one class of caller error is what #950 removed, so all six of Lambda's
    guarded sites now parse first. This does not settle the tree-wide ordering question
    docs/services.md records; it makes one plugin answer one code.

Six of the twenty are not reachable on POST — four Lambda updates and EFS's UpdateFileSystem are
routed on PUT, ListEmailIdentities on GET with its filters in the body — so they carry their own
table rather than being quietly absent from the POST one.

A stale comment in kms_error_status_test.go is corrected: it recorded ListKeys and ListAliases as
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". #1007 is the issue that disturbs it.

Sixty sites remain, in the twenty-three files that answer with an inline literal rather than
through a constructor.

Part of #1007.
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