Repository navigation
fix: reject dot segments in request paths - #306
Open
RishavTiwari25 wants to merge 1 commit into
Open
RishavTiwari25 wants to merge 1 commit into
RishavTiwari25 wants to merge 1 commit into
Conversation
requests/urllib3 and httpx resolve '.' and '..' path segments before sending, so an id such as '../api-keys/key_id' passed to Domains.remove() sends DELETE /api-keys/key_id. Raise ValueError before any request is made when a path segment is '.' or '..', including the percent-encoded forms. Mirrors resend-node#1139.
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.
Problem
Path parameters go into the URL as they are passed (
f"/domains/{domain_id}"). Both HTTP clients the SDK uses resolve.and..segments before sending the request:So when an app passes user input as an id, the call can leave its own endpoint:
resend.Emails.cancel("..")sendsPOST /cancelresend.Domains.remove("../api-keys/KEY_ID")sendsDELETE /api-keys/KEY_ID, which deletes an API keyresend-node fixed the same problem in resend/resend-node#1139. This PR ports that fix to Python.
Fix
Request.perform()andAsyncRequest.perform()now callensure_no_dot_segments(self.path)before making the request. If any path segment is.or.., it raisesValueError("Path parameters cannot be.or...")and nothing is sent. The percent-encoded forms (%2E%2E,.%2e) count too, because servers decode them into the same dot segments. The check reuses the regex from the Node SDK and ignores the query string and the fragment.I used
ValueErrorbecause theResendErrordocstring says that client-side argument errors raiseValueError, andWebhooks.verifyalready does the same. I can switch it to aResendErrorsubclass if you'd rather match the Nodeinvalid_parametererror.Nothing that works today changes. A dot segment always reached the wrong endpoint. Ids that only contain dots (
example.com,...,john.doe@example.com) are still sent as they are.Tests
tests/dot_segment_path_test.py:Emails.get(".."),Emails.cancel(".."),Domains.remove("."),Domains.remove("../api-keys/key_id")andDomains.get("%2E%2E")raise and never reach the HTTP client. The same goes forDomains.remove_async. All six fail onmain.has_dot_segmentgets the same table of cases ashas-dot-segment.spec.tsin resend-node.