Skip to content

RGTA GetResources accepts a ResourcesPerPage outside the published 1-100 range #1004

Closed

Description

@scttfrdmn

What AWS publishes

API_GetResources publishes ResourcesPerPage as:

ResourcesPerPage — Specifies the maximum number of results to be returned in each page. A query can return fewer than this maximum, even if there are more results still to return. You should always check the PaginationToken response value to see if there are more results. You can specify a minimum of 1 and a maximum value of 100.

Type: Integer

Required: No

A minimum of 1 and a maximum of 100 is a published constraint, and the operation publishes
InvalidParameterException/400 for exactly this class — its gloss covers, among six bullets, a
parameter value that is out of range
.

What substrate does

getResources (emulator/tagging_plugin.go:101-102) defaults an absent or non-positive value and
never range-checks anything:

	if in.ResourcesPerPage <= 0 {
		in.ResourcesPerPage = 100
	}

So:

  • ResourcesPerPage: 0 is silently rewritten to 100 rather than refused. AWS's minimum is 1.
  • ResourcesPerPage: -5 is likewise rewritten to 100.
  • ResourcesPerPage: 5000 is accepted, and :151-153 then cuts the page at 5000, so a single
    call can return every resource in the account in one page. AWS's maximum is 100.

The <= 0 arm is doing two different jobs at once — supplying the default for the absent member
(Required: No, and encoding/json leaves an omitted integer at zero, which substrate cannot
distinguish from an explicit 0) and swallowing an out-of-range value. Only the first is correct.

Why it matters beyond tidiness

A consumer that pages RGTA and picks its page size from a config value has no way to learn the value
is wrong: substrate answers 200 with a page of a size AWS would have refused, so the code ships and
fails against real AWS. That is the shape of defect this emulator exists to catch, inverted.

Precedent in the tree

Substrate already refuses an out-of-range page-size parameter rather than coercing it, with the same
reasoning: parseSimulateRequest (emulator/iam_simulate.go:221-226) answers InvalidInput with
"MaxItems must be between 1 and %d" against named constants, and #916's fix to paginateIAMKeys
established that a silent rewrite of an out-of-range MaxItems is a defect at eight IAM operations.
This is the same defect in the tagging plugin.

Acceptance criteria

  • An explicit ResourcesPerPage below 1 answers InvalidParameterException/400, with a message
    naming the parameter and the published range.
  • An explicit ResourcesPerPage above 100 answers the same.
  • An absent ResourcesPerPage still defaults to 100 and succeeds — the two cases must be
    distinguished, which means the field becomes a pointer or the raw body is consulted, not
    <= 0.
  • ResourcesPerPage: 1 and ResourcesPerPage: 100 both succeed, since both are in range.
  • The bound is a named constant with the citation in its doc comment, following
    iam_simulate.go's constants.
  • Wire tests for all five cases through emulator.StartTestServer, asserting the status
    alongside the code
    (per fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923).
  • docs/services.md's tagging section records the refusal and the absent-vs-zero distinction.
  • CHANGELOG.md under ### Fixed.

Out of scope

PaginationTokenExpiredException/400 is also published on this operation (the token is valid for 15
minutes), and substrate must not model it — the expiry is wall-clock, which no substrate
behaviour may depend on. Worth a sentence in docs/services.md next to the range check so the
omission is a recorded decision rather than a gap.

Found while verifying #938's citations against API_GetResources.

Activity

  1. added this to the v0.119.0 milestone on Sep 17, 2026
  2. added
    type: bug
    on Sep 17, 2026
  3. scttfrdmn commented on Sep 18, 2026

    @scttfrdmn
    OwnerAuthor

    Premise corrections, verified at 298c213 before the PR opens

    Everything the issue reports about the behaviour is accurate — ResourcesPerPage: 0 and -5 are rewritten to 100, and 5000 is accepted and honoured. Four corrections to the citations and one addition.

    1. The line numbers have drifted by five. The <= 0 arm is at tagging_plugin.go:106-108, not :101-102; the page cut is at :155-159, not :151-153; getResourcesInput is at :66.

    2. The precedent is #868, not #916. #916 fixed paginateIAMKeys' silent rewrite, but the constants-and-refusal shape the acceptance criteria ask for was established by #868, which created emulator/iam_max_items.go — iamMaxItemsMin/iamMaxItemsMax at :46-47, iamMaxItemsDefault at :52, and the iamValidateMaxItems helper at :71. That file, not iam_simulate.go, is the template.

    3. parseSimulateRequest's check is at iam_simulate.go:232-239, not :221-226.

    4. Neither existing helper transfers as-is, and the reason decides the implementation. iamValidateMaxItems and queryMaxRecords both read the member's presence from req.Params, which parser.go:131 fills from the query string and form body only. RGTA is a JSON-body / X-Amz-Target service, so req.Params is empty for every RGTA request and neither helper can tell absent from zero here. Only the shape is reusable: named constants carrying the citation in their doc comment, refuse rather than clamp, and a message naming the range. The presence test has to come from a *int on the decoded struct — which is also exactly what #1010's pagination-exclusion check needs, and why these two issues land in one PR rather than writing that pointer twice.

    5. Addition — the token site in the same function is the same class of defect. :141-147 decodes PaginationToken while discarding both the base64 error and the Atoi error, so a token substrate never issued silently means page one:

    	if in.PaginationToken != "" {
    		if decoded, err := base64.StdEncoding.DecodeString(in.PaginationToken); err == nil {
    			if n, err := strconv.Atoi(string(decoded)); err == nil && n > 0 {
    				offset = n
    			}
    		}
    	}

    This is one of sixteen sites of that class found while planning v0.119.0 (the remainder of #915). The other fifteen are being filed as their own issue, but this one is folded into the same PR because it is in the same function as both fixes and ResourceARNList's mutual exclusion has to name PaginationToken anyway. It resolves to InvalidParameterException/400 on the operation's own published gloss — "a provided string parameter is malformed" — and the 0–2048 length constraint the member publishes is enforced alongside it.

    On the out-of-scope note, which is right and now has a second reason. PaginationTokenExpiredException/400 stays unimplemented because the 15-minute expiry is wall-clock, which no substrate behaviour may depend on. Worth adding: it is also not the code for the defect above. A token substrate never issued is malformed, not expired — the two are distinguishable to a consumer, since an expired token means "retry from page one" and a malformed one means "your code composed this wrong". So the token refusal takes InvalidParameterException and PaginationTokenExpiredException is recorded as published-but-unreachable.

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

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions