Skip to content

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

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

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?

ApiResource.urlEncodeId leaves 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. HttpURLConnectionClient sends this as written, but a custom HttpClient, 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.validatePath rejects any path segment that is . or .., including %2E forms, before any request is sent
  • throw InvalidRequestException for this check, so existing handling for API errors keeps working; both callers of fullUrl already declare throws StripeException
  • add tests for rejected and still-accepted paths, request and rawRequest, services, nested IDs, and static resource methods

See Also

https://go/j/RUN_DEVSDK-3747

Configuration

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

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

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.

🟡 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 with InvalidRequestException.
  • 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

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