From c641017232b368429bc4bfe92be67b651b88ff2c Mon Sep 17 00:00:00 2001 From: Rohan Singh <134646268+Rohan-Singhh@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:14:44 +0530 Subject: [PATCH 1/2] Refuse "", "." and ".." as path coordinates before any request Percent-encoding leaves "." and ".." unchanged, so the URL resolves them as dot segments and the request reaches another endpoint: get_deployment_review(org, "..") read list_reviews, and list_pull_request_reviews(org, "..", 7) read get_review for id "7". An empty value produced an empty segment. The caller got an API problem or an invalid-response error instead of a caller error. list_pull_request_reviews, get_pull_request_review and get_deployment_review now raise ValueError for these values in the sync and async clients, as the TypeScript SDK's coordinate() already does, and send nothing. Values that only contain dots, such as "..." or "owner/.github", stay one encoded segment. Co-Authored-By: Claude Opus 5.5 --- proofline/client.py | 23 +++++++++++++++++------ tests/test_http.py | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/proofline/client.py b/proofline/client.py index 1d8c1519..059f10a8 100644 --- a/proofline/client.py +++ b/proofline/client.py @@ -163,6 +163,14 @@ def _head_commit(value: str | None) -> None: raise ValueError("The head commit must be a full 40 or 64 character hexadecimal SHA.") +def _coordinate(value: str) -> str: + # Percent-encoding keeps "." and "..", which the URL then resolves as dot segments, so + # get_deployment_review(org, "..") would read list_reviews. The TypeScript SDK refuses them too. + if value in ("", ".", ".."): + raise ValueError("A path coordinate must be nonempty and not a traversal segment.") + return value + + def _next_cursor(page: ReviewPage, seen: set[str]) -> str | None: if not isinstance(page.truncated, bool): raise _transport.invalid_response() @@ -353,7 +361,7 @@ def list_pull_request_reviews( list_pull_request_reviews.sync_detailed, ReviewPage, organization_id, - repository, + _coordinate(repository), pull_request_number, **params, ) @@ -365,14 +373,17 @@ def get_pull_request_review( get_pull_request_review.sync_detailed, CustomerReviewDetail, organization_id, - repository, + _coordinate(repository), pull_request_number, run_number, ) def get_deployment_review(self, organization_id: UUID, public_key: str) -> CustomerReviewDetail: return self._call( - get_deployment_review.sync_detailed, CustomerReviewDetail, organization_id, public_key + get_deployment_review.sync_detailed, + CustomerReviewDetail, + organization_id, + _coordinate(public_key), ) def get_review(self, organization_id: UUID, review_id: UUID) -> CustomerReviewDetail: @@ -727,7 +738,7 @@ async def list_pull_request_reviews( list_pull_request_reviews.asyncio_detailed, ReviewPage, organization_id, - repository, + _coordinate(repository), pull_request_number, **params, ) @@ -739,7 +750,7 @@ async def get_pull_request_review( get_pull_request_review.asyncio_detailed, CustomerReviewDetail, organization_id, - repository, + _coordinate(repository), pull_request_number, run_number, ) @@ -751,7 +762,7 @@ async def get_deployment_review( get_deployment_review.asyncio_detailed, CustomerReviewDetail, organization_id, - public_key, + _coordinate(public_key), ) async def get_review(self, organization_id: UUID, review_id: UUID) -> CustomerReviewDetail: diff --git a/tests/test_http.py b/tests/test_http.py index 0af9d60f..31f0439e 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -14,7 +14,7 @@ import time import tomllib import traceback -from collections.abc import AsyncIterator +from collections.abc import AsyncIterator, Callable from contextlib import asynccontextmanager from datetime import UTC, datetime, timedelta from pathlib import Path @@ -1390,6 +1390,41 @@ async def test_head_commit_must_be_a_full_sha_before_any_request(mode: str) -> N assert len(server.requests) == 1 +@MODES +@pytest.mark.parametrize("value", ["", ".", ".."]) +@pytest.mark.parametrize( + ("name", "arguments"), + [ + ("list_pull_request_reviews", lambda value: (ORG, value, 7)), + ("get_pull_request_review", lambda value: (ORG, value, 7, 1)), + ("get_deployment_review", lambda value: (ORG, value)), + ], +) +async def test_traversal_path_coordinates_are_refused_before_any_request( + mode: str, name: str, arguments: Callable[[str], tuple[Any, ...]], value: str +) -> None: + # Percent-encoding leaves "." and ".." intact, so the URL would resolve them as dot segments + # and reach another endpoint, such as list_reviews for a deployment key of "..". + with Server(lambda request, index: Reply(body={})) as server: + async with session(mode, server.url) as client: + with pytest.raises(ValueError, match="traversal segment"): + await call(client, name, *arguments(value)) + assert server.requests == [] + + +@MODES +async def test_dotted_path_coordinates_stay_one_encoded_segment(mode: str) -> None: + detail = review_at("a" * 40) + with Server(lambda request, index: Reply(body=detail)) as server: + async with session(mode, server.url) as client: + await call(client, "get_deployment_review", ORG, "...") + await call(client, "get_pull_request_review", ORG, "owner/.github", 7, 1) + assert [request.path for request in server.requests] == [ + f"/api/v1/organizations/{ORG}/reviews/deployments/...", + f"/api/v1/organizations/{ORG}/reviews/pr/owner%2F.github/7/runs/1", + ] + + @MODES async def test_polling_backoff_and_timeout_keep_review_url_and_last_record( mode: str, monkeypatch: pytest.MonkeyPatch From a9bc23bce22d9d5c59d67c7371c04676f436a8f9 Mon Sep 17 00:00:00 2001 From: Rohan Singh <134646268+Rohan-Singhh@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:24:00 +0530 Subject: [PATCH 2/2] Cover list_pull_request_reviews with a dotted repository The dotted-coordinate test checked get_pull_request_review and get_deployment_review but never list_pull_request_reviews, so that method could reject or misroute a valid name such as "owner/.github" while the tests stayed green. It now asserts the exact encoded path for all three methods in both modes. Found by Proofline's review of this change. Co-Authored-By: Claude Opus 5.5 --- tests/test_http.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_http.py b/tests/test_http.py index 31f0439e..49943921 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -1415,13 +1415,19 @@ async def test_traversal_path_coordinates_are_refused_before_any_request( @MODES async def test_dotted_path_coordinates_stay_one_encoded_segment(mode: str) -> None: detail = review_at("a" * 40) - with Server(lambda request, index: Reply(body=detail)) as server: + + def reply(request: Request, index: int) -> Reply: + return Reply(body=page() if request.path.endswith("/7") else detail) + + with Server(reply) as server: async with session(mode, server.url) as client: - await call(client, "get_deployment_review", ORG, "...") + await call(client, "list_pull_request_reviews", ORG, "owner/.github", 7) await call(client, "get_pull_request_review", ORG, "owner/.github", 7, 1) + await call(client, "get_deployment_review", ORG, "...") assert [request.path for request in server.requests] == [ - f"/api/v1/organizations/{ORG}/reviews/deployments/...", + f"/api/v1/organizations/{ORG}/reviews/pr/owner%2F.github/7", f"/api/v1/organizations/{ORG}/reviews/pr/owner%2F.github/7/runs/1", + f"/api/v1/organizations/{ORG}/reviews/deployments/...", ]