Repository navigation
Description
What is wrong
paginateIAMKeys (emulator/iam_plugin.go:2769-2771) silently rewrites an out-of-range page size:
if maxItems <= 0 || maxItems > 1000 {
maxItems = 100
}AWS's maxItemsType is min 1 / max 1000, and IAM refuses a value outside it rather than substituting one. API_ListUsers states verbatim:
MaxItems — Use this only when paginating results to indicate the maximum number of items you want in the response. […] If you do not include this parameter, the number of items defaults to 100. […] Type: Integer. Valid Range: Minimum value of 1. Maximum value of 1000. Required: No
So MaxItems=0, MaxItems=-5 and MaxItems=1001 are all outside the published range, and substrate answers 200 with a 100-item page instead of refusing. A caller who mistyped a page size gets a plausible-looking success and never learns the parameter was ignored — which is the same class of defect as #845's "200 having written nothing".
Eight non-test call sites inherit the coercion, so eight operations behave this way:
| Site | Operation |
|---|---|
emulator/iam_plugin.go:419 |
ListUsers |
emulator/iam_plugin.go:725 |
ListRoles |
emulator/iam_plugin.go:844 |
GetGroup |
emulator/iam_plugin.go:948 |
ListGroups |
emulator/iam_plugin.go:2123 |
ListInstanceProfiles |
emulator/iam_groups.go:130 |
ListGroupsForUser |
emulator/iam_list_policies.go:139 |
ListPolicies |
(emulator/iam_plugin.go:2753) |
the helper itself |
The absent case must keep working
iamInt's UnmarshalJSON (emulator/iam_query.go:57-79) maps both an absent parameter and an empty MaxItems= to zero, deliberately: its doc comment records that "a client that sent MaxItems= expressed no limit, and refusing it would fail a request AWS accepts." So the fix must distinguish absent (zero → default 100, as AWS documents) from present and out of range (refuse). The coercion in paginateIAMKeys stays as the defaulting path for an absent value; what is added is validation before the call.
Which error code, and why it differs from the existing precedent
The in-tree precedent for refusing is parseSimulateRequest (emulator/iam_simulate.go:221-226), which answers InvalidInput against iamSimulateMaxMaxItems (:54). That code is correct there because SimulatePrincipalPolicy publishes InvalidInput in its own Errors section.
These eight operations do not. ListUsers' Errors section publishes ServiceFailure/500 only; everything else must come from Common Error Types, which does not list InvalidInput at all. The applicable common error is:
ValidationError — The input doesn't meet the required format or constraints. Check that all required parameters are included and that values are valid. HTTP Status Code: 400
So the correct code for these eight is ValidationError/400, not InvalidInput, and the difference from iam_simulate.go is a property of which operation publishes which error rather than an inconsistency. iamErrorResponse("ValidationError", …, http.StatusBadRequest) is already the established call shape across iam_groups.go.
Acceptance criteria
- A
MaxItemsthat is present and outside 1–1000 is refused withValidationError/400 at all eight operations. - An absent
MaxItems(and an emptyMaxItems=) still defaults to 100 and is not refused, preserving the behaviouriamInt's doc comment describes. - The range is expressed as named constants rather than repeated literals, following
iamSimulateDefaultMaxItems/iamSimulateMaxMaxItems(emulator/iam_simulate.go:48,:54). - The message names the parameter and its range, as
iam_simulate.go:223already does. - Behavioural tests assert
MaxItems=0,MaxItems=-1andMaxItems=1001are refused, and thatMaxItems=1andMaxItems=1000are accepted, on at leastListUsersand one other operation. - A comment records why the code is
ValidationErrorhere andInvalidInputiniam_simulate.go, with the citation, so the two are not "fixed" into agreement later. -
docs/services.mdrecords the refusal.
Compatibility
A request carrying an out-of-range MaxItems now fails where it previously succeeded with a 100-item page. Any consumer relying on the coercion was relying on substrate accepting a request AWS rejects.
Surfaced while planning #848, which publishes the same MaxItems range and would otherwise have inherited the same coercion.
Activity
scttfrdmn commentedon Sep 15, 2026
Verified against the tree at
b30af41while implementing this. Everything in the body holds — the coercion, theValidationError-vs-InvalidInputreasoning and the absent-value carve-out are all exact. Three things changed during implementation, and each is recorded here rather than left to the diff. One of the body's eight rows is also stale.The eight sites are seventeen handlers, nineteen operations
The body's inventory is of
paginateIAMKeyscall sites, which is where the coercion lives — but that is not the set of operations that declareMaxItems. Grepping the declaration rather than the helper gives seventeen handlers, and becauselistInlinePoliciesserves three dispatch arms, nineteen operations:iam_plugin.go(10)listUsers,listRoles,getGroup,listGroups,listAttachedUserPolicies,listAttachedRolePolicies,listAccessKeys,listInlinePolicies(→ListUserPolicies,ListRolePolicies,ListGroupPolicies),listUserTags,listRoleTagsiam_groups.go(2)listGroupsForUser,listAttachedGroupPoliciesiam_list_policies.go(1)listPoliciesiam_policy_versions.go(1)listPolicyVersionsiam_tagging.go(2)listPolicyTags,listInstanceProfileTagsiam_account_authorization_details.go(1)getAccountAuthorizationDetails(#848)Nine of those handlers never reach
paginateIAMKeys. Four go throughiamTagListingResponse, whose guard wasif limit <= 0 { limit = 100 }— no upper bound at all, soMaxItems=1001there produced a 1001-item page rather than a 100-item one, a second variant of the same defect the body does not cover. The rest parse the parameter and then have nothing to truncate.All seventeen are guarded, including the ones with nothing to truncate, because AWS validates a request parameter before it decides whether the request has enough results to use it — and an operation that accepts
MaxItems=1001while its sibling refuses it is exactly the inconsistency this issue exists to remove. A caller cannot see which code path a listing happens to take.The guard is one function,
iamValidateMaxItems, called from each handler before it does any work, so the seventeen cannot drift apart. Presence is read fromreq.Paramsrather than inferred from the decoded value, which is what makes the body's absent-vs-zero criterion satisfiable at all: the query protocol flattens the form body intoParams, so a parameter the caller sent is a key there whatever its value, whileiamIntcannot tell an absent parameter fromMaxItems=0.Correction to the body:
ListInstanceProfilesis not one of themThe row
emulator/iam_plugin.go:2123→ListInstanceProfilesis line drift.listInstanceProfilesis at:3233today and it parses no request parameters at all — noparseIAMBody, no params struct. It ignoresMaxItems,MarkerandPathPrefix, lists the account's profiles, and hardcodes<IsTruncated>false</IsTruncated>.So it cannot be guarded by this fix: there is no decoded value to range-check, and adding one means implementing the pagination the operation has never had. That is the accepted-and-ignored defect class rather than the silently-coerced one, and it needs
Marker/PathPrefixalongsideMaxItemsto be worth anything — so it is filed separately rather than folded in here. Line:2123in the fixed tree is one of the two tag listings, which is guarded.The simulate pair took
MaxItems=0as absent, and no longer doesThe body cites
parseSimulateRequestas the precedent, and the code split is kept exactly as the body argues it: those two operations publishInvalidInputin their own Errors sections, the seventeen publish onlyNoSuchEntity/ServiceFailureand so can only draw fromCommonErrors.But the precedent had the same hole this issue is about. Its guard read
if params.MaxItems != 0 && (…), so an explicitMaxItems=0was treated as absent and answered a 100-result page — the below-minimum value slipping through at the one place already validating.SimulatePrincipalPolicyandSimulateCustomPolicynow apply the same bounds and the same presence rule as the seventeen.Only the error code differs across all twenty-one operations, and that difference is AWS's rather than substrate's. It is stated in a comment at both guards, so the two are not later "fixed" into agreement in the wrong direction.
Acceptance criteria, as delivered
ValidationError/400 at seventeen handlers / nineteen operations, not eight, plusInvalidInput/400 at the simulate pair.iamMaxItemsMin,iamMaxItemsMaxandiamMaxItemsDefaultare named constants;iam_simulate.gonow shares the minimum.0,-1and1001refused and1000, absent and empty accepted, onGetAccountAuthorizationDetails,ListUsers,ListPoliciesandListUserTags, plus0/1001on both simulate operations. They go through the query protocol, because a hand-marshaled JSON body leavesParamsempty and so cannot express the present-vs-absent distinction the fix turns on.ValidationError/InvalidInputcitation is recorded inemulator/iam_max_items.go's file preamble and again at the simulate guard.docs/services.mdrecords the refusal, the code split and the present-but-empty decision.Compatibility, restated
Broader than the body says: a request carrying an out-of-range
MaxItemsnow fails at nineteen IAM operations plus the two simulate operations, not eight. Four of those previously returned an over-large page rather than a coerced one, so a consumer that asked for 1001 items and got 1001 was relying on substrate exceeding AWS's published maximum.ListInstanceProfilesstill accepts and ignores the parameter, per the correction above.