Skip to content

fix(pagination): refuse a token substrate never issued at four operations (#915) - #1018

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/reject-unissued-pagination-token-915
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/reject-unissued-pagination-token-915

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #915.

Four operations decoded a pagination token inside an if err == nil and discarded the failure:

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

So a token substrate could not have issued — one from another operation, a truncated copy, a
hand-written string, an offset left over from an older recording — left the offset at zero and the
operation answered a well-formed page one. That is the one wrong answer a paginating caller
cannot detect: a loop that runs until the token comes back empty is handed the first page again, so
it either spins or processes the same records twice, and the response says nothing. #884 named the
shape and #887 fixed it for the RDS and ElastiCache markers; these four are the rest of it.

What each operation answers, and where the code comes from

Operation Code Message Provenance
CloudWatch DescribeAlarms InvalidNextToken / 400 The next token specified is invalid. Published. The only error API_DescribeAlarms lists, and the same code CloudWatch's Smithy model carries.
SSM DescribeParameters InvalidNextToken / 400 The specified token isn't valid. Published, on the operation's own page.
SSM GetParametersByPath InvalidNextToken / 400 The specified token isn't valid. Published, identically.
S3 ListObjectsV2 InvalidArgument / 400 The continuation token provided is incorrect. Substrate's reading. API_ListObjectsV2 publishes exactly one error, NoSuchBucket at 404, and nothing about an unusable continuation-token; the S3 ErrorResponses page returns an empty body to automated fetches.

CloudWatch and Systems Manager publish different messages for the same code, which is why the
error construction stays per caller (cwInvalidNextToken, ssmInvalidNextToken) while the rule for
what is issuable is stated once.

What counts as a token substrate could have issued

New emulator/offset_pagination_token.go holds the three offset cursors' decode and encode. The
rule is a round trip: the decoded text must be exactly what the encoder renders for the offset it
names, so +5, 05 and a trailing space are refused along with a negative offset and a
non-integer — forms strconv.Atoi accepts but nothing ever emitted.

An offset past the end of the listing is not refused. That token was issued, over a listing
that has since shrunk, and it clamps to a final empty page; refusing it would break a legitimate
walk whose records were deleted mid-loop. This is the same distinction parseQueryMarker records
for the value-based cursor.

ListObjectsV2' cursor is a key, not an offset, so any base64 is issuable there and a token
naming a deleted object resumes after it. Its decode moves into s3DecodeContinuationToken, shared
with ListBuckets, so the two operations that take that cursor cannot refuse it differently. The
1024-character ceiling stays at the ListBuckets call site — that is the one of the two whose page
publishes a Length Constraint on the parameter.

The token is validated before any state is read

The ordering rule #887 established. Three of the four read first — CloudWatch loaded its alarm
index, Systems Manager its parameter paths — so a refusal could depend on how much state happened to
exist. Each new test asserts it by sealing the state store against reads and requiring the refusal
to arrive anyway; a handler that read first answers 500 instead.

ListObjectsV2 is the deliberate exception: its bucket-existence 404 keeps precedence, because the
bucket is the resource the request addresses and AWS publishes nothing about which refusal wins. Its
test seals only List, so the object listing is what is guaranteed unread.

Tests

emulator/pagination_token_refusal_test.go, one test per operation, all through real wire calls per
#765. Each has two halves: seven hand-written tokens are refused, and a token the operation
actually issued still resumes the listing. The tests were proven to discriminate — with the
base64-failure branch of decodeOffsetPaginationToken reverted to accept, six subtests fail,
including all three sealed-store subtests.

Not fixed, and recorded so it is not read as fixed

All three offset cursors are still offsets, so a record added or removed behind the cursor still
shifts every later page. That is the other half of the tier-2 defect and the reason the RDS and
ElastiCache describes were converted to a value-based cursor; refusing an unissued token and
choosing a stable cursor basis are independent defects, and only the first is #915.

…ions (#915)

CloudWatch DescribeAlarms, SSM DescribeParameters and GetParametersByPath, and
S3 ListObjectsV2 each decoded their pagination token inside an `if err == nil`
and discarded the failure, so a token substrate could not have issued selected
the start of the listing and the operation answered a well-formed page one --
the one wrong answer a paginating caller cannot detect.

The three offset cursors now share decodeOffsetPaginationToken /
encodeOffsetPaginationToken, whose round-trip rule defines what is issuable, and
each refuses with the code its own page publishes. S3's decode moves into
s3DecodeContinuationToken, shared with ListBuckets, so the two operations taking
that cursor cannot refuse it differently. The token is validated before any
state is read, asserted by sealing the state store.
@scttfrdmn scttfrdmn added this to the v0.118.0 milestone Sep 17, 2026
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 2afc331 into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/reject-unissued-pagination-token-915 branch September 17, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant