Skip to content

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

Open
zacchua-stripe wants to merge 5 commits into
masterfrom
zacchua/reject-dot-segments
Open

zacchua-stripe wants to merge 5 commits into
masterfrom
zacchua/reject-dot-segments

Conversation

@zacchua-stripe

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

Copy link
Copy Markdown
Contributor

Why?

Path params are escaped with CGI.escape, which leaves dots alone, so an ID of . or .. produces a dot segment in the path.

For example, client.v1.customers.payment_methods.retrieve("..", "pm_123") builds /v1/customers/../payment_methods/pm_123. Net::HTTP sends this as written, but a 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?

  • Util.validate_path! rejects any path segment that is . or .., including %2E forms, before any request is sent
  • also treat an encoded slash (%2F) as a separator for this check, since a proxy that decodes the path before normalizing it would turn it into a real one
  • raise ArgumentError for this check, like the other checks in validate_path!; nothing reaches the API when it fails
  • validate_path! runs on every request, so this covers services, resource methods, raw_request, and event helpers
  • add tests for rejected and still-accepted paths, services, nested IDs, resource methods, and raw_request
  • the error message shows only the path, leaving out query params that can carry secrets such as a client_secret

See Also

https://go/j/RUN_DEVSDK-3747

Configuration

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

CGI.escape leaves dots alone, so an ID of "." or ".." produced a dot
segment that proxies or servers may remove, changing the endpoint.
Util.validate_path! now rejects these segments, including percent-encoded
forms, with a Stripe::InvalidRequestError before any request is sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Committed-By-Agent: claude

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the request-path validation change.

No open issues 🎉

What changed in this PR

This PR strengthens the Stripe Ruby SDK’s request-path validation to reject . and .. segments before sending requests, preventing path normalization from routing requests to unintended endpoints.

Changes:

  • Reject literal and percent-encoded dot segments with Stripe::InvalidRequestError.
  • Add coverage for raw requests, service methods, and resource methods, while preserving valid paths containing dots.
  • Document the behavior in a patch release changefile.
File Description
test/​stripe/​api_requestor_test.rb Tests rejected dot segments, accepted dotted paths, and prevention of outgoing requests.
lib/​stripe/​util.rb Adds dot-segment detection to shared request-path validation.
.hark/​changes/​2026-11-20_zacchua_reject-dot-segments.change.md Documents the validation change and resulting error behavior.

Review effort: Balanced

Paths can carry query parameters such as a client_secret, which then
ended up in the exception message and any logs that record it. The
message now shows only the path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Committed-By-Agent: claude

@jar-stripe jar-stripe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to the stripe/stripe-python#2001; i think this is directionally right but I'm not sure why the error should be different.

Comment thread lib/stripe/util.rb Outdated
return unless dot_segment

# An InvalidRequestError rather than an ArgumentError, like an invalid ID
# in APIResource#resource_url, so callers' existing handling of API

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand this; why would this be different?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to ArgumentError 👍

Util.validate_path! already raises ArgumentError for paths it won't
send. Nothing reaches the API when this check fails, so an
InvalidRequestError (which normally describes an API response) was
misleading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Committed-By-Agent: claude
@zacchua-stripe
zacchua-stripe marked this pull request as ready for review November 23, 2026 20:13
@zacchua-stripe
zacchua-stripe requested a review from a team as a code owner November 23, 2026 20:13
@zacchua-stripe
zacchua-stripe requested review from xavdid and removed request for a team November 23, 2026 20:13

@jar-stripe jar-stripe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! I'd take another pass at that changefile entry before merging, but it's not a blocking concern

- RUN_DEVSDK-3747
---

Passing an ID of `.` or `..` to a method such as `client.v1.checkout.sessions.retrieve` or `Stripe::Checkout::Session.retrieve` now raises `ArgumentError` without sending a request. Proxies or servers that normalize URL paths could otherwise route such a request to a different endpoint; for example, `/v1/customers/../payment_methods/pm_123` becomes `/v1/payment_methods/pm_123`. Paths passed to `raw_request` are checked the same way, including percent-encoded forms such as `%2E`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a small nit but I think this can be simplified a lot

zacchua-stripe and others added 2 commits November 23, 2026 15:10
An ID like "x/../../customers/cus_B" is sent as one segment,
x%2F..%2F..%2Fcustomers%2Fcus_B, which passed the check. A proxy that
decodes the path before normalizing it (nginx's proxy_pass, for example)
would still turn it into a request for a different object. Splitting on
"%2F" as well as "/" rejects it, while IDs that merely contain a slash
keep working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Committed-By-Agent: claude
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Committed-By-Agent: claude

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.

3 participants