Skip to content

A pagination token substrate never issued is silently answered with page one (CloudWatch, SSM x2, S3 ListObjectsV2) #915

Closed

Description

@scttfrdmn

Found while auditing #887's pagination cursors. It is the same defect #887 fixed for the RDS and ElastiCache Marker, at four sites in three other services, and AWS publishes the error code for three of them.

What substrate does

A pagination token it never issued is silently treated as page one. The decode error is discarded and the offset stays 0:

emulator/cloudwatch_plugin.go — DescribeAlarms

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

emulator/ssm_plugin.go — GetParametersByPath (:486) and DescribeParameters (:555) — the identical block, twice.

emulator/s3_plugin.go — listObjectsV2 (~:1643) — the same shape, but it falls back to start-after rather than to zero:

afterKey := startAfter
if contToken != "" {
	if decoded, decErr := base64.StdEncoding.DecodeString(contToken); decErr == nil {
		afterKey = string(decoded)
	}
}

So an undecodable continuation-token restarts the listing at start-after, which is usually the beginning.

Why it matters

The failure is invisible in a well-formed response. A consumer that persisted a token across a restart, truncated one, or hand-wrote one gets a 200 with page one rather than being told the token is unusable, and its walk silently starts over — or, with a stable set and a small page size, loops. There is nothing in the body to distinguish that from a legitimate first page.

#887 recorded exactly this for the RDS/ElastiCache Marker, where strconv.Atoi's error was discarded so any unparseable marker became 0.

What AWS publishes

Three of the four have a published code and an exact message, so this is not a judgement call:

Operation Error Status Message, verbatim
CloudWatch DescribeAlarms InvalidNextToken 400 "The next token specified is invalid."
SSM DescribeParameters InvalidNextToken 400 "The specified token isn't valid."
SSM GetParametersByPath InvalidNextToken 400 "The specified token isn't valid."
S3 ListObjectsV2 — — publishes no code for a bad continuation-token

For S3 the code would be substrate's reading. parseS3ListBucketsParams (emulator/s3_list_buckets.go) already made this exact decision for ListBuckets' continuation-token, choosing InvalidArgument / 400 under a doc comment that begins "The error code is unverified." listObjectsV2 should follow that precedent and say so the same way.

ec2_describetags.go is the in-tree model for the refusal itself: it validates its token and refuses one it did not issue, and its comment already states the argument — "an offset-based NextToken over an unordered list could…".

Related, and deliberately not folded in

All three published operations also constrain MaxResults in ways substrate does not enforce — CloudWatch MaxRecords 1–100, SSM DescribeParameters MaxResults 1–50, SSM GetParametersByPath MaxResults 1–10. That is the same class as #913 and belongs with it, not here: this issue is about which records a page contains, not how many.

Acceptance criteria

  • CloudWatch DescribeAlarms refuses a NextToken it did not issue with InvalidNextToken / 400 and the published message, cited in the doc comment.
  • SSM DescribeParameters and GetParametersByPath do the same, with their own published message.
  • S3 listObjectsV2 refuses an undecodable continuation-token, following parseS3ListBucketsParams' choice of InvalidArgument / 400 and recording it as unverified in the same words.
  • The token is validated before any state is read, as Audit the remaining ~60 List call sites for an AWS-documented order that differs from lexicographic #887 established, so a request substrate cannot serve is refused rather than answered.
  • A test at each of the four operations asserts that a hand-written token is refused, and that a token the operation actually issued still round-trips.
  • docs/services.md records the refusal and the provenance of each code — published for the three, substrate's reading for S3.

Found while working on #887.

Activity

  1. added this to the v0.118.0 milestone on Sep 16, 2026
  2. added
    type: bug
    on Sep 16, 2026
  3. added 9 commits that reference this issue on Sep 17, 2026
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