Skip to content

fix(#1086): five sites refuse a token substrate never issued, and the CFN decision is reversed - #1132

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

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

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Part of #1086, which stays open for the remaining ten sites (see ## Scope below). No
closing keyword here on purpose.

What this changes

Five pagination sites in four services carried the pre-#915 idiom that decodes a base64 offset and
discards both errors, so a token substrate never issued — one from another operation, a truncated
copy, a hand-written string — 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: the loop is handed the
first page again and either spins or processes the same records twice, and nothing in the response
says so.

All five now go through decodeOffsetPaginationToken / pageByOffsetToken and refuse.

Site Code Provenance
KMS ListKeys InvalidMarkerException/400 Published in the operation's own Errors section
KMS ListAliases InvalidMarkerException/400 Published, identically
Secrets Manager ListSecrets InvalidNextTokenException/400 Published, and published separately from InvalidParameterException
EventBridge ListRules InvalidToken/400 Published in prose only — see ## Provenance
CloudFormation DescribeStackEvents ValidationError/400 Substrate's reading of the two 400s on the Common Errors page

The recorded decision at cfn_events.go is reversed, in writing

That site is why this PR could not just convert the mechanical four. cfnPaginateEvents' doc comment
argued the silent page-one answer from DescribeStackEvents' Errors section being literally empty,
and cfn_events_test.go asserted the behaviour with that rationale attached. Both are rewritten
rather than deleted, because two things overturn the argument:

  1. The empty Errors section is not the whole of what CloudFormation publishes. The section still
    carries the boilerplate pointing at the Common Error Types page, which publishes ValidationError
    and InvalidParameterValue both at 400 — and this plugin already has a recorded house rule for
    choosing between them (ValidationError is what it answers for every other malformed parameter),
    so a caller sees one code per class of mistake rather than a second code invented for this member.
  2. A well-formed page one is the failure a caller cannot detect (S3 ListBuckets implements none of its request parameters and omits Owner, BucketArn and BucketRegion #884, A pagination token substrate never issued is silently answered with page one (CloudWatch, SSM x2, S3 ListObjectsV2) #915). Answering nothing is
    worse than answering an error whose code is substrate's reading of two published candidates.

The reversal fixes a second defect at that site for free. The old guard required
offset < len(events), so a token substrate itself had issued, over a listing that has since shrunk,
reset to page one instead of clamping to a final empty page — which is exactly the behaviour the
old comment claimed to be preserving, and exactly what #1086's "two things not to change" says must
clamp. pageByOffsetToken clamps. Asserted directly:
TestCFNEvents_UnissuedTokenIsRefused ends by requiring an offset ten past the end to yield an empty
page and no token, not a refusal and not page one.

Every one of the five validates the token before it reads any state

Four of the five loaded their index first, so a refusal could depend on how much state happened to
exist, and a store failure would surface as a 500 for a request that was already refusable — #887's
ordering criterion. The decode is hoisted above the state read at all five, and it is asserted the
way #915's sites assert it: by sealing the state store against reads and requiring the refusal to
arrive anyway. Reading the handler is not the assertion; a sealed store is.

Provenance

  • EventBridge's InvalidToken comes from prose, not from an error list, and the file says so.
    API_ListRules' Errors section is InternalException/500 and ResourceNotFoundException/400, and
    InvalidToken is absent from EventBridge's CommonErrors.html too. But the NextToken member's
    own description says "Using an expired pagination token results in an HTTP 400 InvalidToken
    error."
    The code, the status and the condition are all the page's, in the description of the very
    member being refused. This corrects Twenty-seven plugins answer twenty-one different codes for an unparseable body, and at least three are codes the service does not publish #950's sweep of EventBridge, which read Errors sections and
    so settled for the common-errors fallback here; the correction is recorded in
    eventbridge_errors.go's preamble beside the sweep it corrects.
    AWS names an expired token and substrate's tokens do not expire — that difference is stated in
    ebInvalidToken's doc comment rather than glossed over. What substrate refuses is the other way a
    token fails, and both are one observation for a caller: a token this service will not resume from.
  • Secrets Manager's code choice is load-bearing, not incidental. API_ListSecrets' Errors list is
    four entries and carries a code for the token and a code for a member, so answering
    InvalidParameterException would tell a caller that the value of some member was wrong when AWS
    publishes a code for exactly this condition.
  • KMS is the only one of the four that constrains the token itself — Marker is Length 1–1024,
    Pattern [\u0020-\u00FF]* — so a marker outside that range is refusable on the page's own terms as
    well. kmsInvalidMarker's doc comment records that substrate's issuability rule is the stricter
    test, and that every string it refuses inside the Pattern is still a string KMS could not have
    minted.
  • CloudFormation's is substrate's reading and is labelled as such in the code, the docs and the
    CHANGELOG.

Compatibility

A caller that fed a token substrate did not issue into one of these five operations previously got
HTTP 200 and page one; it now gets a 400 with the code in the table above.
Any test that relied on
the silent restart will start failing, which is the point. Three behaviours are unchanged and two of
them are asserted so they stay that way:

  • A token one of these operations issued still resumes the walk. Each new test asserts the round-trip
    first, so a handler that refused every token could not pass.
  • An offset past the end of the listing is not refused — that token was issued, and it clamps to
    a final empty page.
  • A decoded "0" is accepted, and an absent token is page one.

Scope — #1086 stays open

The issue lists fifteen sites in nine services. This PR ships five sites in four services. The
remaining ten are follow-up conversions under a stated reading, not divergences
— a correction to
an earlier comment of mine on the issue, which over-applied #671 and would have left the harmful
answer at ten sites. #671 forbids borrowing a sibling operation's code by analogy; a generic code
published on the operation's own page is the page's own vocabulary, and substrate has already made
exactly that choice twice in this class (S3 ListObjectsV2 → InvalidArgument,
GetResources → InvalidParameterException). All thirteen remaining references were read and the
reading each will take is tabulated on the issue and in docs/services.md, with the quotes, so the
follow-ups do not re-fetch.

Verification

  • Nine-command gate green; coverage held above the 85.5% emulator / 85.0% total floor.
  • codecov/patch pre-check: 0 uncovered added blocks.
  • Four new wire tests (pagination_token_refusal_test.go), each asserting the round-trip, all seven
    unissuable forms against that operation's published code, and the refusal from a sealed store —
    32 subtests. Plus a unit test for the cfn_events reversal and clamp, and a
    DescribeStackEvents wire subtest.

… CFN decision is reversed

KMS ListKeys/ListAliases, Secrets Manager ListSecrets, EventBridge ListRules
and CloudFormation DescribeStackEvents all decoded a base64 offset and
discarded both errors, so a token substrate never issued answered page one —
the one wrong answer a paginating caller cannot detect.

Three of the four codes are published: KMS's InvalidMarkerException and
Secrets Manager's InvalidNextTokenException in their own Errors sections, and
EventBridge's InvalidToken in the NextToken member's prose, which corrects
#950's Errors-section sweep of that service. CloudFormation's ValidationError
is substrate's reading of the two 400s on its Common Errors page.

The cfn_events recorded decision is reversed in writing rather than deleted,
which also fixes a second defect there: its offset < len(events) guard reset a
token substrate itself had issued to page one instead of clamping.

Every decode is hoisted above its state read (#887), asserted with a sealed
store rather than by reading the handler.

#1086 stays open: the remaining ten sites convert under a stated reading, not
as divergences.
@codecov

codecov Bot commented Sep 19, 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 a5b3306 into main Sep 19, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1086-unissued-pagination-token branch September 19, 2026 08:55
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