Repository navigation
fix: encode endpoint and contentId as single URL path segments - #127
Closed
cursor[bot] wants to merge 1 commit into
Closed
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
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.
|
Important Review skippedBot 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.
|
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.
Summary
makeRequestinsrc/createClient.tsbuilt the request URL by concatenating the caller-suppliedendpointandcontentIddirectly 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 affectedget,getList,getListDetail,getObject,getAllContentIds,getAllContents,create(PUT/POST),update(PATCH) anddelete(DELETE).Fix
src/utils/encodePathSegment.ts: converts the value to a string once, refuses'',.and..(these are the only values thatencodeURIComponentleaves as dot segments for the URL parser to resolve), and returnsencodeURIComponent(value).makeRequestnow builds the path from[endpoint, contentId?], with each value passed throughencodePathSegmentand joined with/. Every method that takes anendpointorcontentIdgoes throughmakeRequest, so they all get this fix.-,_, 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:
createManagementClientuses only the constant pathmedia, 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=falseon unchangedmain(5e228d6) with Add failing tests for content path injection #126 checked out: 9 failed, 1 passed. For example, content id../inquiries/private-idwas sent to/api/v1/inquiries/private-id, andarticle?depth=3&fields=body,emailoverrode the application'sfields/depth.npx jest --coverage=false, 14 suites / 117 tests passed.npx jest --coverage=false, 13 suites / 107 tests passed.npm run typecheck,npm run lint,npm run formatandnpm run buildall succeed.delete,updateandgetList; 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.