Skip to content

fix: reject malformed failure page tokens - #421

Merged
uniqueg merged 3 commits into
devfrom
fix/420-page-token-newline
Nov 19, 2026
Merged

uniqueg merged 3 commits into
devfrom
fix/420-page-token-newline

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

GET /failures answered 500 for page tokens that pass the schema's pattern ^[0-9]{1,15}\.[0-9a-f]{24}$ but can't be parsed:

  • a token with a line break at the end (pageToken=<valid>%0A): jsonschema matches patterns with re.search(), where $ also matches before a final line break (fix: schema patterns accept a trailing newline foca#797), and ObjectId() then raised InvalidId;
  • a token whose 15-digit time is after the year 9999 (e.g. 999999999999999.<24 hex digits>): datetime.fromtimestamp() raised ValueError.

_after() now checks tokens again with re.fullmatch() (PAGE_TOKEN, kept equal to the spec's pattern by a test) and catches the conversion error. Both answer 400 Bad Request with pageToken in errors (pattern-mismatch), without quoting the token, as drs-filer does for its page tokens (elixir-cloud-aai/drs-filer#140). docs/api.md (Failed operations) says how invalid tokens are answered.

The specification of pageToken now also says that tokens are opaque and that others get 400.

The other $-anchored patterns of additions.openapi.yaml aren't affected. In serviceId, subject and group, $ only appears inside negative lookaheads, where it rejects more values, not fewer. In id of renames, the final [^/]+$ takes a line break as part of the value anyway, and identifiers with line breaks are rejected later (unusable-id).

Verification

  • Regression test first: pytest tests/test_failures.py -k malformed failed for both tokens on dev (500) and passes with the fix.
  • coverage run --source cloud_registry,scripts -m pytest -W ignore::DeprecationWarning (mongomock, chart tests with Helm 3.22.1 after helm dependency build deployment): 2608 passed, 11 skipped; coverage report: 100%.
  • pre-commit run --all-files: all hooks pass except actionlint, which fails locally only because the mise shellcheck shim has no version set. No workflow changed; CI runs it.
  • mkdocs build --strict: passes.
  • Not run locally: the tests against a real MongoDB (MONGODB_TEST_URI) and the compose smoke test. CI runs both.
  • CI on f99224d: all checks green (Test (MongoDB 7.0), Test (mongomock), Smoke test, Chart, Docs, Lint, CodeQL, Scan image, CI passed). Sourcery: one thread (the docs claimed that every token the registry didn't issue gets 400), fixed in 47c356e and resolved.

Declined review findings

  • Quality reviewer (low): mention pageToken in the paragraph of docs/api.md (Errors) about pattern-mismatch for values that pass the schema. Declined: the Failed operations section, which describes the parameter, covers it.

Open questions

None.

Closes #420

🤖 Generated with Claude Code

uniqueg and others added 2 commits November 19, 2026 08:02
GET /failures checked pageToken only against the schema's pattern,
which jsonschema matches with re.search(), where `$` also matches
before a final line break (elixir-cloud-aai/foca#797). A token with a
trailing line break then reached ObjectId() and failed with a 500, as
did tokens whose 15-digit time is after the year 9999.

Check tokens again with re.fullmatch() and the datetime conversion,
and answer 400 with pageToken in `errors` (pattern-mismatch), without
quoting the token, as drs-filer does for its page tokens.

Closes #420

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Say in the specification of pageToken that tokens are opaque and that
others get 400, also if they match the pattern; re-wrap the paragraph
of docs/api.md. Also catch OSError of the time conversion, which some
platforms raise, and check in the tests that the token isn't quoted,
also JSON-escaped.

Refs #420

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added the type: bug Something isn't working label Nov 19, 2026
@uniqueg uniqueg self-assigned this Nov 19, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Clarify that pageToken values are opaque and that malformed tokens receive a 400 response.

  • cloud_registry/api/additions.openapi.yaml L1380-1382

Implementation

Validate failure page tokens with a full match and translate malformed values or out-of-range timestamps into a consistent client error.

  • cloud_registry/ga4gh/registry/failures.py L73-76, L334-354, L365-380 (+2 small edits)

Documentation

Document the 400 response and pageToken error details for malformed failure-page tokens.

  • docs/api.md L869-873

Tests

Cover malformed token responses, ensure token values are not exposed, and verify the implementation pattern matches the OpenAPI pattern.

  • tests/test_failures.py L21, L542-585

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a3273a8) to head (47c356e).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #421   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        29           
  Lines         3827      3836    +9     
=========================================
+ Hits          3827      3836    +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 19, 2026 07:42
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 47c356e

#420 GET /failures fails (500) for page tokens ending in a line break · 3 of 3 met

# Requirement Status Notes
1 Reject page tokens with a trailing line break using a full-pattern check. ✅ Met _after() uses PAGE_TOKEN.fullmatch(token) before parsing.
2 Return 400 with pageToken in errors as pattern-mismatch, without quoting the token. ✅ Met _invalid_page_token() creates that error, and the regression test checks the response and that the token is not included in the body.
3 Add a regression test for the malformed page token. ✅ Met test_malformed_page_token covers a token with a final line break.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="cloud_registry/api/additions.openapi.yaml" line_range="1380-1381" />
<code_context>
           required: false
           description: |
             `nextPageToken` of the previous page, to list the failures after it.
+            Tokens are opaque: pass them on as they are; others get `400`
+            (`pattern-mismatch`), also if they match the pattern.
           schema:
             type: string
</code_context>
<issue_to_address>
**Fabricated cursors are accepted**

When a caller supplies a well-formed token with an in-range timestamp that was not returned by the registry, `_after()` accepts any token with the required shape and an in-range timestamp, so a caller-created token such as `1.000000000000000000000000` is used as a cursor and returns failures instead of the documented `400`.

Clarify that only malformed or unparseable tokens are rejected, or authenticate tokens if the API must reject every token not issued by the registry.

Also at `docs/api.md:869-870`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: cloud_registry/api/additions.openapi.yaml:1381


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Well-formed tokens that the registry didn't issue are used as cursors,
so say that malformed tokens get 400, not all others.

Refs #420

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 6195b8a into dev Nov 19, 2026
32 checks passed
@uniqueg
uniqueg deleted the fix/420-page-token-newline branch November 19, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /failures fails (500) for page tokens ending in a line break

1 participant