Repository navigation
fix(#1007): refuse a body that will not parse in the twelve services that already had the answer - #1060
Merged
Conversation
…that already had the answer 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.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
The second of #1007's three slices: the twelve services whose own
*InvalidBody()constructoralready held the answer, so no new AWS reading was needed for any of the twenty sites. That is
what makes this slice separable from the first — #1059 had to decide a code for SQS and Health from
their Common Errors pages; here every file's constructor already carries the provenance #950 and
#1003 established.
lambdaInvalidBodysfnInvalidBodykmsInvalidBodysesv2InvalidBodyfirehoseInvalidBodyebInvalidBodyefsInvalidBodyssmInvalidBodysqUnmarshal(see below)sagemakerInvalidBodykinesisInvalidBodyacmInvalidBodyFourteen of the twenty were hiding behind a true statement
They sat inside
if len(req.Body) > 0 { _ = json.Unmarshal(…) }, and six carried the comment//nolint:errcheck // optional body. The body is optional on all fourteen — they are listoperations 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. Both hold at once now.
The risk in a change like this runs the other way, so a test pins the half a table of refusals
cannot see.
TestInvalidBodyLeavesAnAbsentBodyAloneasserts twelve operations still answer 200 to anabsent body (including
kms/ListKeys,kms/ListAliases,stepfunctions/ListStateMachines,stepfunctions/ListActivities,ssm/DescribeParameters). Without it, a guard that refused an emptybody would satisfy every refusal assertion added here 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 AWSaccepts. It gained the check the other thirteen already had.
sqUnmarshal— a helper in its own file that alreadyhandles 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. It now calls the helper, and the
helper's own length check replaces the one that used to be there.
would have answered
404for an unparseable body naming an absent function, whileAddPermissionand
TagResource— moved above the lookup by Lambda checks a function exists before parsing the body, so a malformed body on a missing function answers 404 rather than 400 #1006 — answer400for the same request. Oneplugin, two codes, for one class of caller error is what Twenty-seven plugins answer twenty-one different codes for an unparseable body, and at least three are codes the service does not publish #950 removed, so all six of Lambda's
guarded sites now parse first. This does not settle the tree-wide ordering question
docs/services.mdrecords (S3's seven sites are still lookup-first, with reasons); it makes oneplugin answer one code.
Six are not reachable on POST
Four Lambda updates and EFS's
UpdateFileSystemroute onPUT;ListEmailIdentitiesroutes onGETwith its filters in the body. Rather than let them be quietly absent from the sharedPOSTtable — which is how a site goes unasserted — they carry their own table,
invalidBodyMethodCases, driven byTestInvalidBodyOnANonPostOperation.A recorded reading, reversed deliberately
kms_error_status_test.gocarried: "CreateKey, ListKeys and ListAliases are absent from the listbecause 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. The comment now
says so and names the distinction that survives — optional body, yes; discarded error, no — and the
two operations join the list.
Verification
The nine-command gate:
gofmt/build/vetclean,golangci-lintclean, fullgo test -count=1 ./...green on the default toolchain and on go1.26.6, coverage/docs/authz checks clean, docs sitebuilds, e2e green. Coverage 85.3% emulator / 84.8% total, against the 85.1/84.6 floor.
Each of the twenty new assertions was mutation-checked: reverting the twelve plugin files to
mainfails exactly twenty leaves, one per site, then the files were restored.
Part of #1007 — one slice remains (the twenty-three-file, sixty-site inline-literal tail, plus
the script and make target for the "no bare
_ =" criterion thaterrcheckcannot express), so theissue stays open.