Repository navigation
fix(stepfunctions,ssm): a parse guard answers a published code (#950) - #1003
Merged
Merged
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
9 tasks
This was referenced Sep 17, 2026
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.
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.
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 unverifiableBadRequest)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:
stepfunctions_plugin.go, 3 instepfunctions_tags.go)InvalidRequestInvalidRequestSendCommand,GetCommandInvocation)SerializationException, messageerr.Error()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
SerializationExceptionsites are beyond the issue's inventory, which counted ten forSystems 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 failedto unmarshal by an endpoint whose whole purpose is to look like AWS.
What it answers now
ValidationErrorat 400, from the service's own common-errors page: "The input doesn't meet therequired 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-Targetclaimed. For Systems Managerthat 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,HierarchyLevelLimitExceededExceptionand the like — plusInternalServerErrorat 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 noExceptionsuffix.Two near misses, declined on the record
ValidationExceptionCreateStateMachine,UpdateStateMachine,DeleteStateMachine,StartExecution,StopExecutionMalformedHttpRequestExceptionTwo premise corrections to #950
"Neither page lists
ValidationExceptionamong its errors" is wrong. It is listed, at 400, inthe Errors section of five Step Functions operations. The issue had checked
API_DescribeStateMachineand
API_GetParameteronly, and both of those do omit it. The evidence is now the reason fordeclining 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
ValidationExceptionin prose — "if the specified name for a parameter containsspaces between characters, the request fails with a
ValidationExceptionerror" — and none of thefive lists it in an Errors section. Four Step Functions pages do the same for their Distributed Map
note.
"Systems Manager already has
ssm_errors.go-shaped precedent to extend" — it did not exist. Thetwo constructors the issue meant were in
ssm_tags.go. The file is created here.Structure
New
emulator/stepfunctions_errors.goandemulator/ssm_errors.go, followingemulator/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 threesfn*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.Marshalproduces valid JSON by construction. New shared helperrawSignedCall(generalised fromkmsRawCall, which now delegates to it) hands the server raw bytes.emulator/invalid_body_code_test.gohas a case for each of the twenty-seven operations rather than arepresentative 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/jsondecoder text.Compatibility
InvalidRequestfor an unparseable body at any ofCreateStateMachine,DescribeStateMachine,UpdateStateMachine,DeleteStateMachine,StartExecution,StartSyncExecution,StopExecution,DescribeExecution,GetExecutionHistory,CreateActivity,DescribeActivity,DeleteActivity,TagResource,UntagResourceorListTagsForResourcenow seesValidationError. The status was already 400 and is unchanged.InvalidRequestat ten operations, and forSerializationExceptionat
SendCommandandGetCommandInvocation. Those two also stop reportingencoding/json's text, soan assertion on the message body changes.
Verification
The nine-command gate, all green. Coverage 84.7% emulator / 84.2% total, up from the 84.6/84.1
baseline.