Repository navigation
fix: reject malformed failure page tokens - #421
Conversation
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]>
Reviewer's GuideAPIClarify that
ImplementationValidate failure page tokens with a full match and translate malformed values or out-of-range timestamps into a consistent client error.
DocumentationDocument the 400 response and
TestsCover malformed token responses, ensure token values are not exposed, and verify the implementation pattern matches the OpenAPI pattern.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 47c356e #420 GET /failures fails (500) for page tokens ending in a line break · 3 of 3 met
|
There was a problem hiding this comment.
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
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]>
Summary
GET /failuresanswered500for page tokens that pass the schema's pattern^[0-9]{1,15}\.[0-9a-f]{24}$but can't be parsed:pageToken=<valid>%0A): jsonschema matches patterns withre.search(), where$also matches before a final line break (fix: schema patterns accept a trailing newline foca#797), andObjectId()then raisedInvalidId;999999999999999.<24 hex digits>):datetime.fromtimestamp()raisedValueError._after()now checks tokens again withre.fullmatch()(PAGE_TOKEN, kept equal to the spec's pattern by a test) and catches the conversion error. Both answer400 Bad RequestwithpageTokeninerrors(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
pageTokennow also says that tokens are opaque and that others get400.The other
$-anchored patterns ofadditions.openapi.yamlaren't affected. InserviceId,subjectandgroup,$only appears inside negative lookaheads, where it rejects more values, not fewer. Inidof renames, the final[^/]+$takes a line break as part of the value anyway, and identifiers with line breaks are rejected later (unusable-id).Verification
pytest tests/test_failures.py -k malformedfailed for both tokens ondev(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 afterhelm dependency build deployment): 2608 passed, 11 skipped;coverage report: 100%.pre-commit run --all-files: all hooks pass exceptactionlint, which fails locally only because the miseshellcheckshim has no version set. No workflow changed; CI runs it.mkdocs build --strict: passes.MONGODB_TEST_URI) and the compose smoke test. CI runs both.CI passed). Sourcery: one thread (the docs claimed that every token the registry didn't issue gets400), fixed in 47c356e and resolved.Declined review findings
pageTokenin the paragraph ofdocs/api.md(Errors) aboutpattern-mismatchfor 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