Repository navigation
Reject "." and ".." path segments before sending requests - #2338
Draft
zacchua-stripe wants to merge 1 commit into
Draft
zacchua-stripe wants to merge 1 commit into
zacchua-stripe wants to merge 1 commit into
Conversation
ApiResource.urlEncodeId leaves dots alone, so an ID of "." or ".." produces a dot segment that a custom HttpClient, proxy, or server could remove, sending the request to a different endpoint. validatePath now rejects these segments, including percent-encoded forms, with an InvalidRequestException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Committed-By-Agent: claude
There was a problem hiding this comment.
🟡 Changes recommended
The path guard can be bypassed with trailing ASCII whitespace that URL construction later strips, allowing raw requests to send prohibited dot segments.
1 open issue
What changed in this PR
Extends the Stripe Java SDK’s shared path validation to reject dot segments that could cause requests to reach an unintended endpoint.
Changes:
- Rejects literal and percent-encoded
.and..segments withInvalidRequestException. - Adds tests for rejection before network activity across standard, raw, service, and legacy requests.
- Records the behavior change in a patch-release change note.
| File | Description |
|---|---|
src/test/java/com/stripe/net/OriginRelativePathTest.java |
Tests accepted paths and dot-segment rejection across request entry points. |
src/main/java/com/stripe/net/LiveStripeResponseGetter.java |
Adds dot-segment validation and propagates validation errors. |
.hark/changes/2026-11-20_zacchua_reject-dot-segments.change.md |
Documents the user-facing validation change. |
Review effort: Balanced
| "Request path must begin with a single \"/\", got: " + path); | ||
| } | ||
|
|
||
| for (String segment : path.split("[?#]", 2)[0].split("/", -1)) { |
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?
ApiResource.urlEncodeIdleaves dots alone, so an ID of.or..produces a dot segment in the path.For example,
client.v1().customers().paymentMethods().retrieve("..", "pm_123")builds/v1/customers/../payment_methods/pm_123.HttpURLConnectionClientsends this as written, but a customHttpClient, proxy, or server that normalizes the path would send it to/v1/payment_methods/pm_123, a different endpoint. If an integration passes an untrusted ID to one of these methods, the request could read or change a different object than intended.What?
LiveStripeResponseGetter.validatePathrejects any path segment that is.or.., including%2Eforms, before any request is sentInvalidRequestExceptionfor this check, so existing handling for API errors keeps working; both callers offullUrlalready declarethrows StripeExceptionrequestandrawRequest, services, nested IDs, and static resource methodsSee Also
https://go/j/RUN_DEVSDK-3747
Configuration
skip-changefile: This PR is not a user-facing change, so there's no changefile.