Skip to content

fix: encode endpoint and contentId as single URL path segments - #127

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/encode-content-path-segments-5c61
Closed

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/encode-content-path-segments-5c61

Conversation

@cursor

@cursor cursor Bot commented Nov 20, 2026

Copy link
Copy Markdown

Summary

makeRequest in src/createClient.ts built the request URL by concatenating the caller-supplied endpoint and contentId directly after /api/v1/. Applications often take a content id from the page address. A value containing ?, &, #, /, \ or dot segments (including percent-encoded %2e%2e) could therefore replace the query the application built, or send the request to another endpoint or another content item. The request still carried the service API key. This affected get, getList, getListDetail, getObject, getAllContentIds, getAllContents, create (PUT/POST), update (PATCH) and delete (DELETE).

Fix

  • New src/utils/encodePathSegment.ts: converts the value to a string once, refuses '', . and .. (these are the only values that encodeURIComponent leaves as dot segments for the URL parser to resolve), and returns encodeURIComponent(value).
  • makeRequest now builds the path from [endpoint, contentId?], with each value passed through encodePathSegment and joined with /. Every method that takes an endpoint or contentId goes through makeRequest, so they all get this fix.
  • Ordinary ids and endpoints (letters, digits, -, _, spaces, non-ASCII) produce the same URL as before. Refused values reject the promise before any request is sent.

I checked the other place that builds request URLs: createManagementClient uses only the constant path media, so no caller input reaches its path.

Tests

The tests that prove this fix are in #126 (tests/pathSegmentInjection.test.ts). They are not part of this PR.

  • npx jest tests/pathSegmentInjection.test.ts --coverage=false on unchanged main (5e228d6) with Add failing tests for content path injection #126 checked out: 9 failed, 1 passed. For example, content id ../inquiries/private-id was sent to /api/v1/inquiries/private-id, and article?depth=3&fields=body,email overrode the application's fields/depth.
  • The same file with this fix applied: 10 passed.
  • Full suite with Add failing tests for content path injection #126 and this fix: npx jest --coverage=false, 14 suites / 117 tests passed.
  • On this branch (fix only): npx jest --coverage=false, 13 suites / 107 tests passed. npm run typecheck, npm run lint, npm run format and npm run build all succeed.
  • I also ran a temporary harness of variations against delete, update and getList; it was not committed. Inputs: %2e, .%2e, %2E%2E, .\t., .\n. (tab/newline the URL parser strips), ..;, a/../b, //evil.example/x, https://evil.example/, @evil.example, ..%2f, %2e%2e%5c, fullwidth/one-dot-leader dots, ..\0, a lone surrogate, ?, #, &a=b. Every request stayed on the service host under /api/v1/, with each value in exactly one segment and no injected query or fragment. Exact ./.. and the lone surrogate were refused before any request.
Open in Web Open in Cursor 

makeRequest concatenated the caller-supplied endpoint and contentId into
the request URL, so '?', '#', '/', '\' or dot segments in those values
could add query parameters or rewrite the request to another endpoint or
content while still sending the service API key. Percent-encode each
value as one path segment and refuse '.', '..' and empty segments.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

Ask an organization administrator to verify that this bot has an active assigned CodeRabbit review seat. See the seat-assignment guide. After the seat is confirmed, request a review again.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7725f03b-a22b-4da4-b5a1-0e7767cce844

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@YouheiNozaki YouheiNozaki self-assigned this Nov 20, 2026
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.

2 participants