fix: percent-encode caller-supplied URL path segments - #1025
Open
vdusek wants to merge 4 commits into
Open
Conversation
Record keys, request IDs and resource IDs were interpolated into the request path with a plain f-string, so a value carrying `/`, `?` or `#` could reach a different endpoint under the caller's token, inject its own query parameters, or be silently truncated at a fragment and read the wrong record. An empty value, `.` and `..` cannot be carried in a path segment at all - a URL parser resolves dot segments after percent-decoding - so they are now rejected with a `ValueError` instead of landing on the parent or collection endpoint.
vdusek
marked this pull request as draft
August 21, 2026 11:36
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1025 +/- ##
==========================================
+ Coverage 94.95% 94.96% +0.01%
==========================================
Files 58 58
Lines 5436 5447 +11
==========================================
+ Hits 5162 5173 +11
Misses 274 274
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
vdusek
marked this pull request as ready for review
August 21, 2026 12:46
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.
Caller-supplied values were interpolated into the request path with a plain f-string, so they could restructure the URL. Reproduced against a mock server, reading the raw request line:
Requests carry the caller's token, so traversal acts with full privileges. The
#case is a plain correctness bug: any app forwarding user strings as record keys silently reads the wrong one.Fix
New
to_path_segment()in_utils/http.py, applied to the caller-supplied segment at everyrecords/{key}andrequests/{request_id}call site, plusresource_idinResourceClientBase._resource_url._build_urlitself is untouched, so literal paths likerequests/batchkeep their separator.The API routes these as a single Express param (
records/:recordKey) and decodes it once, so percent-encoding is what it expects — an unencoded/never matched. Signatures stay over the raw key, which is what the server verifies against (key_value_stores.ts:503HMACs the decodedreq.params.recordKey).Behavior change
'',.and..now raiseValueError. Encoding cannot protect them — a URL parser resolves dot segments after decoding, sorecords/%2E%2Ecollapses exactly likerecords/... They previously reached the parent endpoint, where the same verb means something else:delete_record('..')→DELETE /v2/key-value-stores/{id}, deleting the whole storeget_record('..')returned store metadata as record contentclient.dataset('..')→GET /v2/Also newly rejected: a non-
strkey, previously coerced by the f-string. A caller who pre-encoded keys as a workaround now gets double encoding — but such keys never resolved anyway, since the platform's key charset forbids both/and%.✍️ Drafted by Claude Code