Repository navigation
fix(pagination): refuse a token substrate never issued at four operations (#915) - #1018
Merged
Merged
Conversation
…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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #915.
Four operations decoded a pagination token inside an
if err == niland discarded the failure: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
DescribeAlarmsInvalidNextToken/ 400API_DescribeAlarmslists, and the same code CloudWatch's Smithy model carries.DescribeParametersInvalidNextToken/ 400GetParametersByPathInvalidNextToken/ 400ListObjectsV2InvalidArgument/ 400API_ListObjectsV2publishes exactly one error,NoSuchBucketat 404, and nothing about an unusablecontinuation-token; the S3ErrorResponsespage 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 forwhat is issuable is stated once.
What counts as a token substrate could have issued
New
emulator/offset_pagination_token.goholds the three offset cursors' decode and encode. Therule is a round trip: the decoded text must be exactly what the encoder renders for the offset it
names, so
+5,05and a trailing space are refused along with a negative offset and anon-integer — forms
strconv.Atoiaccepts 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
parseQueryMarkerrecordsfor the value-based cursor.
ListObjectsV2' cursor is a key, not an offset, so any base64 is issuable there and a tokennaming a deleted object resumes after it. Its decode moves into
s3DecodeContinuationToken, sharedwith
ListBuckets, so the two operations that take that cursor cannot refuse it differently. The1024-character ceiling stays at the
ListBucketscall site — that is the one of the two whose pagepublishes 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.
ListObjectsV2is the deliberate exception: its bucket-existence 404 keeps precedence, because thebucket 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
decodeOffsetPaginationTokenreverted 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.