Skip to content

fix(#1086): SNS's three listings refuse a token they never issued - #1220

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1086-sns-pagination-token
Sep 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1086-sns-pagination-token

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Part of #1086 — the first three of the ten sites #1132 left. Athena, CloudWatch Logs, Scheduler and
Batch remain, so this does not resolve the issue.

ListTopics, ListSubscriptions and ListSubscriptionsByTopic all carried the pre-#915 idiom that
decodes a base64 offset and discards both errors, so a token from another operation, a truncated copy or
an offset left over from an older recording selected the start of the listing and the operation answered
a well-formed page one — the one wrong answer a paginating caller cannot detect. All three now go
through decodeOffsetPaginationToken and pageByOffsetToken, which was already the cut each had
written out by hand.

The code is published; the condition is substrate's reading

The row #1132 wrote for SNS read the code as substrate's reading of a generic code published on the
operation's own page
. Reading all three references directly moves it up a step: InvalidParameter/400
is in each operation's own Errors section, glossed "Indicates that a request parameter does not
comply with the associated constraints."
So the code needs no appeal to SNS's common-errors page and
#671's borrowing question does not arise for it.

What is substrate's reading is only the condition. All three pages describe NextToken in one
sentence — "Token returned by the previous ListTopics request." — with no length, no pattern and no
error attributed to it, and the common-errors page names nothing about a token either. The message
therefore names the parameter and the operation rather than restating the gloss, because a caller handed
"does not comply with the associated constraints" cannot tell which of its parameters AWS means:

NextToken is not a token returned by a previous ListTopics request

Two claims deliberately not made: this is not an expiry refusal (SNS publishes no lifetime for a
NextToken, unlike the four CloudWatch Logs pages still to come), and the page size stays a constant
100, which is what all three pages state and what none publishes a parameter to change.

Three operations, two decode sites, and a token that was portable

ListSubscriptions and ListSubscriptionsByTopic share one paginator, so the decode moved out to the
two callers and the shared builder now takes an already-validated offset — a decode inside it could only
sit at one of the two callers' orderings and would be wrong for the other.

That sharing surfaced something the issue did not name: a token was silently portable between the
three.
All three encode an offset identically, so ListTopics' token decoded cleanly under
ListSubscriptions and indexed into the wrong listing. The round-trip rule refuses nothing there — the
token is issuable — so what catches it is the message naming the operation. Worth carrying to Batch,
whose three operations likewise share one paginator.

Ordering, and a new shape of assertion

ListSubscriptionsByTopic is the one site in the class whose token is deliberately not checked
first
. #926 gave it NotFound/404 for an absent topic; the topic is the resource the request
addresses and AWS publishes nothing about which refusal wins, so the 404 keeps precedence — the same
reading S3 ListObjectsV2 already records for its bucket. The token is still decoded before the
subscription index is read.

#915's ordering test seals Get and List independently, which works for S3 because the bucket check
is a Get and the object listing a List. Both SNS reads are Gets, so sealing by method would fail
the topic lookup and assert nothing about the token. tokenRefusalSealedState now takes a single key,
obtained from the plugin's own key builder via a new export_test.go accessor rather than spelled in the
test, plus a control call proving the sealed key is on the read path — without it the refusal could pass
because the key is never touched.

Verified the assertion has teeth by moving the decode below the index read: the subtest fails with
InternalFailure/500 and sns loadSubIDs: state store sealed by the test.

Verification

Full gate clean: gofmt/go build/go vet, golangci-lint, make test, make docs-reference-check docs-versions authz-reference-check, npm --prefix docs run build, test/e2e, and
discarded-unmarshal-check version-check wire-bookkeeping-check. Coverage 85.99% emulator / 85.5%
total
, against the 85.5%/85.0% floor.

Three new tests, each in the shape #915 established and #1132 extended: the issued token round-trips
first (so a handler that refused everything could not pass), then all seven unissuable forms are refused
with the published code and the operation's message, then the ordering is pinned against a sealed store.
Listings are 101 records built through real CreateTopic/Subscribe calls, per #765 — the page size is
a constant 100, so that is the smallest listing that makes the operation issue a token at all.

No existing test asserted SNS pagination in either direction, which is how three sites carried the defect.

ListTopics, ListSubscriptions and ListSubscriptionsByTopic all carried the
pre-#915 idiom that decodes a base64 offset and discards both errors, so a
token from another operation, a truncated copy or an offset left over from an
older recording answered a well-formed page one -- the one wrong answer a
paginating caller cannot detect. All three now go through
decodeOffsetPaginationToken and pageByOffsetToken.

The code is published: InvalidParameter/400 is in each of the three
operations' own Errors sections, so it needs no appeal to SNS's common-errors
page and #671's borrowing question does not arise. The condition is
substrate's reading -- none of the three publishes anything about NextToken
beyond "Token returned by the previous ListTopics request" -- so the message
names the parameter and the operation rather than restating the gloss. That
also refuses a token that was silently portable between the three, which all
encode an offset identically.

ListSubscriptionsByTopic keeps #926's NotFound/404 ahead of the token
refusal, the same reading S3 ListObjectsV2 records for its bucket, and
decodes before the subscription index is read. Both of its reads are Gets, so
the ordering is asserted by sealing that one state key -- obtained from the
plugin's own key builder -- with a control call proving the key is on the read
path.

#1086 stays open: Athena, CloudWatch Logs, Scheduler and Batch remain.
@codecov

codecov Bot commented Sep 20, 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 2cffa3a into main Sep 20, 2026
18 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1086-sns-pagination-token branch September 20, 2026 01:40
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.

1 participant