Repository navigation
Description
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
DescribeAlarmsrefuses aNextTokenit did not issue withInvalidNextToken/ 400 and the published message, cited in the doc comment. - SSM
DescribeParametersandGetParametersByPathdo the same, with their own published message. - S3
listObjectsV2refuses an undecodablecontinuation-token, followingparseS3ListBucketsParams' choice ofInvalidArgument/ 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.mdrecords the refusal and the provenance of each code — published for the three, substrate's reading for S3.
Found while working on #887.
Activity
feat(kinesis): ListTagsForStream pages its tags (#954) (#960)
fix(pagination): refuse a token substrate never issued at four operat…
fix(rds,elasticache): refuse a MaxRecords outside the published range (…
fix(ec2): one offset paginator, and two describes that publish a curs…
feat(pagination): the two cursors outside EC2 that published both hal…
feat(tagging): GetResources honors all eight of its request members (#…
fix(#1086): SNS's three listings refuse a token they never issued (#1220
fix(#1086): Athena's two listings refuse a token they never issued (#…
fix(#1086): CloudWatch Logs' four listings refuse a token they never …
fix(#1086): ListSchedules refuses a token it could not have issued (#…
fix(#1086): Batch's three describes refuse a token they could not hav…