Skip to content

Reject "." and ".." path segments before sending requests - #2001

Open
zacchua-stripe wants to merge 1 commit into
masterfrom
zacchua/reject-dot-segments
Open

zacchua-stripe wants to merge 1 commit into
masterfrom
zacchua/reject-dot-segments

Conversation

@zacchua-stripe

@zacchua-stripe zacchua-stripe commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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 call quote_plus directly) 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(".") sends GET /v1/checkout/sessions and returns a list of sessions, and client.v1.customers.payment_methods.retrieve("..", "pm_123") sends GET /v1/payment_methods/pm_123 with 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_path rejects any path segment that is . or .. after percent-decoding (some clients decode %2E before removing dot segments), before any request is sent
  • raise InvalidRequestError rather than ValueError for this check: with the default sync client, the API already rejects these paths with an InvalidRequestError, so existing error handling keeps working
  • validate_path runs on every request, so this covers generated services, legacy resources, raw_request, and fetch_related_object, regardless of HTTP client
  • add tests for rejected and still-accepted paths across sync/async requests, StripeClient services, nested IDs, and the legacy API

See Also

https://go/j/RUN_DEVSDK-3747

Configuration

  • skip-changefile: This PR is not a user-facing change, so there's no changefile.

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

Copilot AI 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.

🟢 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 .., raising InvalidRequestError before 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
zacchua-stripe marked this pull request as ready for review November 20, 2026 19:09
@zacchua-stripe
zacchua-stripe requested a review from a team as a code owner November 20, 2026 19:09
@zacchua-stripe
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants