Repository navigation
Reject "." and ".." path segments before sending requests - #2045
zacchua-stripe wants to merge 5 commits into
Conversation
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
There was a problem hiding this comment.
🟢 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
left a comment
There was a problem hiding this comment.
similar to the stripe/stripe-python#2001; i think this is directionally right but I'm not sure why the error should be different.
| return unless dot_segment | ||
|
|
||
| # An InvalidRequestError rather than an ArgumentError, like an invalid ID | ||
| # in APIResource#resource_url, so callers' existing handling of API |
There was a problem hiding this comment.
I don't fully understand this; why would this be different?
There was a problem hiding this comment.
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
jar-stripe
left a comment
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
its a small nit but I think this can be simplified a lot
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
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::HTTPsends 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%2Eforms, before any request is sent%2F) as a separator for this check, since a proxy that decodes the path before normalizing it would turn it into a real oneArgumentErrorfor this check, like the other checks invalidate_path!; nothing reaches the API when it failsvalidate_path!runs on every request, so this covers services, resource methods,raw_request, and event helpersraw_requestclient_secretSee Also
https://go/j/RUN_DEVSDK-3747
Configuration
skip-changefile: This PR is not a user-facing change, so there's no changefile.