Repository navigation
Reject "." and ".." path segments before sending requests - #2001
Open
zacchua-stripe wants to merge 1 commit into
Open
zacchua-stripe wants to merge 1 commit into
zacchua-stripe wants to merge 1 commit into
Conversation
HTTP clients such as httpx, requests and aiohttp remove "." and ".." segments from a URL before sending it. Since quote_plus leaves dots alone, an ID of "." or ".." changed which endpoint a method called. validate_path now rejects these segments, including percent-encoded forms, with an InvalidRequestError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Committed-By-Agent: claude
There was a problem hiding this comment.
🟢 Approval recommended
The review reports no active issues with the request-path validation change.
No open issues 🎉
What changed in this PR
This PR hardens the shared request-path validation to prevent HTTP clients from redirecting requests to unintended endpoints by normalizing dot segments.
Changes:
- Reject path segments that decode to
.or.., raisingInvalidRequestErrorbefore sending a request. - Add rejection and acceptance tests covering sync/async requests, generated services, nested IDs, and legacy resources.
- Add a patch release change note.
| File | Description |
|---|---|
tests/test_api_requestor.py |
Tests dot-segment rejection without sending requests and preserves valid dotted paths. |
stripe/_util.py |
Rejects literal and percent-encoded dot segments in shared path validation. |
.hark/changes/2026-11-20_zacchua_reject-dot-segments.change.md |
Documents the request-path safety fix for release. |
Review effort: Balanced
zacchua-stripe
marked this pull request as ready for review
November 20, 2026 19:09
zacchua-stripe
requested review from
jar-stripe,
mark-kogan-stripe and
mnorth-stripe
and removed request for
a team
November 20, 2026 19:09
This branch has not been deployed
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.
Why?
Some HTTP clients, including httpx/httpx2 (the default async client), requests, and aiohttp, remove
.and..segments from a URL path before sending it.sanitize_id(and the legacy resources, which callquote_plusdirectly) escape/in IDs but leave dots alone, so an ID of.or..changes which endpoint a method calls.For example, with httpx,
client.v1.checkout.sessions.retrieve_async(".")sendsGET /v1/checkout/sessionsand returns a list of sessions, andclient.v1.customers.payment_methods.retrieve("..", "pm_123")sendsGET /v1/payment_methods/pm_123with any of those clients.If an integration passes an untrusted ID to one of these methods, the request can read or change a different object than intended.
What?
validate_pathrejects any path segment that is.or..after percent-decoding (some clients decode%2Ebefore removing dot segments), before any request is sentInvalidRequestErrorrather thanValueErrorfor this check: with the default sync client, the API already rejects these paths with anInvalidRequestError, so existing error handling keeps workingvalidate_pathruns on every request, so this covers generated services, legacy resources,raw_request, andfetch_related_object, regardless of HTTP clientStripeClientservices, nested IDs, and the legacy APISee Also
https://go/j/RUN_DEVSDK-3747
Configuration
skip-changefile: This PR is not a user-facing change, so there's no changefile.