Skip to content

iam: paginateIAMKeys silently rewrites an out-of-range MaxItems to 100 at eight operations AWS refuses #868

Closed

Description

@scttfrdmn

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 MaxItems that is present and outside 1–1000 is refused with ValidationError/400 at all eight operations.
  • An absent MaxItems (and an empty MaxItems=) still defaults to 100 and is not refused, preserving the behaviour iamInt'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:223 already does.
  • Behavioural tests assert MaxItems=0, MaxItems=-1 and MaxItems=1001 are refused, and that MaxItems=1 and MaxItems=1000 are accepted, on at least ListUsers and one other operation.
  • A comment records why the code is ValidationError here and InvalidInput in iam_simulate.go, with the citation, so the two are not "fixed" into agreement later.
  • docs/services.md records 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

  1. added this to the v0.116.0 milestone on Sep 15, 2026
  2. added
    type: bug
    area: iam
    on Sep 15, 2026
  3. scttfrdmn commented on Sep 15, 2026

    @scttfrdmn
    OwnerAuthor

    Verified against the tree at b30af41 while implementing this. Everything in the body holds — the coercion, the ValidationError-vs-InvalidInput reasoning 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 paginateIAMKeys call sites, which is where the coercion lives — but that is not the set of operations that declare MaxItems. Grepping the declaration rather than the helper gives seventeen handlers, and because listInlinePolicies serves three dispatch arms, nineteen operations:

    File Handlers
    iam_plugin.go (10) listUsers, listRoles, getGroup, listGroups, listAttachedUserPolicies, listAttachedRolePolicies, listAccessKeys, listInlinePolicies (→ ListUserPolicies, ListRolePolicies, ListGroupPolicies), listUserTags, listRoleTags
    iam_groups.go (2) listGroupsForUser, listAttachedGroupPolicies
    iam_list_policies.go (1) listPolicies
    iam_policy_versions.go (1) listPolicyVersions
    iam_tagging.go (2) listPolicyTags, listInstanceProfileTags
    iam_account_authorization_details.go (1) getAccountAuthorizationDetails (#848)

    Nine of those handlers never reach paginateIAMKeys. Four go through iamTagListingResponse, whose guard was if limit <= 0 { limit = 100 } — no upper bound at all, so MaxItems=1001 there 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=1001 while 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 from req.Params rather 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 into Params, so a parameter the caller sent is a key there whatever its value, while iamInt cannot tell an absent parameter from MaxItems=0.

    Correction to the body: ListInstanceProfiles is not one of them

    The row emulator/iam_plugin.go:2123 → ListInstanceProfiles is line drift. listInstanceProfiles is at :3233 today and it parses no request parameters at all — no parseIAMBody, no params struct. It ignores MaxItems, Marker and PathPrefix, 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/PathPrefix alongside MaxItems to be worth anything — so it is filed separately rather than folded in here. Line :2123 in the fixed tree is one of the two tag listings, which is guarded.

    The simulate pair took MaxItems=0 as absent, and no longer does

    The body cites parseSimulateRequest as the precedent, and the code split is kept exactly as the body argues it: those two operations publish InvalidInput in their own Errors sections, the seventeen publish only NoSuchEntity/ServiceFailure and so can only draw from CommonErrors.

    But the precedent had the same hole this issue is about. Its guard read if params.MaxItems != 0 && (…), so an explicit MaxItems=0 was treated as absent and answered a 100-result page — the below-minimum value slipping through at the one place already validating. SimulatePrincipalPolicy and SimulateCustomPolicy now 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

    • Present-and-out-of-range refused with ValidationError/400 at seventeen handlers / nineteen operations, not eight, plus InvalidInput/400 at the simulate pair.
    • Absent and present-but-empty still default to 100.
    • iamMaxItemsMin, iamMaxItemsMax and iamMaxItemsDefault are named constants; iam_simulate.go now shares the minimum.
    • The message names the parameter, its range and the value received.
    • Behavioural tests assert 0, -1 and 1001 refused and 1000, absent and empty accepted, on GetAccountAuthorizationDetails, ListUsers, ListPolicies and ListUserTags, plus 0/1001 on both simulate operations. They go through the query protocol, because a hand-marshaled JSON body leaves Params empty and so cannot express the present-vs-absent distinction the fix turns on.
    • The ValidationError/InvalidInput citation is recorded in emulator/iam_max_items.go's file preamble and again at the simulate guard.
    • docs/services.md records 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 MaxItems now 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. ListInstanceProfiles still accepts and ignores the parameter, per the correction above.

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

    area: iamtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions