Skip to content

Build the export path from a validated organization UUID - #1

Open
apoorvarohilla wants to merge 2 commits into
mainfrom
fix/export-organization-path
Open

apoorvarohilla wants to merge 2 commits into
mainfrom
fix/export-organization-path

Conversation

@apoorvarohilla

@apoorvarohilla apoorvarohilla commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Problem

export_reviews is the only REST call in the client whose path is built by hand, and it interpolated organization_id without encoding:

f"/api/v1/organizations/{organization_id}/exports/{dataset}"

Every generated operation encodes the organization as one path segment (quote(str(org_id), safe="")), and the TypeScript SDK passes it as a typed path parameter, so this method was the outlier. Any value that is not a plain UUID changes which request is sent:

Call Request sent before this change
export_reviews(UUID(org), "reviews") /api/v1/organizations/<org>/exports/reviews
export_reviews("..", "reviews") /api/v1/exports/reviews
export_reviews(f"{org}/../../reviews", "reviews") /api/v1/reviews/exports/reviews
export_reviews(f"{org}/exports/spend?x=", "reviews") /api/v1/organizations/<org>/exports/spend

The last row is a silent wrong answer rather than an error. The caller asked for reviews, the client fetched spend, and because both datasets are row version 1, decode_export(..., "reviews") accepted the page. The caller received spend rows labeled as a reviews export. iter_export_pages repeats the same request on every page.

A string organization ID is a plausible input: every other method accepts one and encodes it, and the MCP helpers document organization_id as a UUID string.

Approach

_export_path converts organization_id to a UUID before building the path, and raises ValueError for anything else before a request is made. The method already raises ValueError for an unknown dataset or format, so a bad organization now fails the same way. iter_export_pages gets the check through export_reviews.

I chose rejection over percent-encoding because no non-UUID value can name an organization, and encoding .. would still leave a path that the URL resolves as a dot segment. Equivalent UUID spellings (string, upper case, braces, bare hex) are normalized to the canonical path, so existing callers that pass a UUID or its string keep working.

Verification

Reproduction against a loopback server that answers each export path with that dataset's rows:

asked for 'reviews' with organization_id='<org>/exports/spend?x='
  before: request path /api/v1/organizations/<org>/exports/spend
          rows returned: [{'dataset_version': 1, 'debit_microcredits': 125000, 'model': 'deep'}]
  after:  refused before any request: ValueError: Export organization_id must be a UUID.

Tests (sync and async clients, tests/test_http.py):

  • test_export_refuses_an_organization_id_that_is_not_a_uuid: nine invalid values (.., ., empty, slash, ?, #, non-UUID text, an int, None) raise ValueError from both export_reviews and iter_export_pages, and the server receives no request.
  • test_export_sends_the_canonical_organization_path: a UUID with hex letters, its string, upper case, braced and bare upper-case hex spellings all reach the canonical lower-case /api/v1/organizations/<org>/exports/reviews. test_organization_spellings_are_distinct keeps those five inputs distinct.

Against main, 24 of these 31 cases fail: all 18 refusal cases (each request is sent), and the upper-case, braced and hex spellings (sent as given instead of the canonical path). The UUID, its string and the distinctness check pass. With this change all 31 pass, and the full suite:

python -m pytest -q             248 passed, 8 subtests passed
python -m ruff check .          All checks passed
python -m ruff format --check . 237 files already formatted
python -m mypy proofline scripts  Success: no issues found

scripts/check.py does not run on Windows (prooflinedev#87), so I ran its ruff, mypy and pytest steps directly.

Review feedback

I ran Proofline on this change in my fork. It flagged one warning: the test fixture ORG has no hex letters, so str(ORG).upper() equaled str(ORG) and the upper-case case repeated the string case. I confirmed it and switched the spelling test to a UUID with hex letters, with a check that the inputs stay distinct (29c65fb).

Not changed

A UUID-typed argument passed as ".." to a generated operation is still resolved as a dot segment, for example list_repositories("..") requests /api/v1/repository-names. prooflinedev#84 handles the string coordinates of those operations; the UUID ones come from the generated templates, so I left them out of this hand-written fix.

export_reviews is the only REST call whose path is formatted by hand, and it
interpolated organization_id without encoding. A non-UUID value could add
path segments, leave the organization through dot segments, or replace the
dataset through "?": export_reviews(f"{org}/exports/spend?x=", "reviews")
requested the spend export, and because both datasets are row version 1 the
page decoded as reviews without an error.

Convert organization_id to a UUID before building the path and raise
ValueError otherwise, before any request, as the method already does for an
unknown dataset or format. iter_export_pages inherits the check. Equivalent
UUID spellings still reach the canonical path.

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

@prooflinedev prooflinedev Bot 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.

Proofline has 1 new finding to review.

View full review in Proofline

Comment thread tests/test_http.py Resolved
Review feedback: ORG has no hex letters, so str(ORG).upper() equaled
str(ORG) and the upper-case case repeated the string case. Use a UUID with
hex letters, check that every spelling is a distinct input, and expect its
canonical lower-case path. Also wrap EXPORT_WINDOW to the 100-column limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant