Skip to content

Percent-encode caller-supplied path segments and refuse dot segments - #14

Open
robrigo wants to merge 6 commits into
wharfkit:masterfrom
robrigo:feat/encode-path-segments
Open

Percent-encode caller-supplied path segments and refuse dot segments#14
robrigo wants to merge 6 commits into
wharfkit:masterfrom
robrigo:feat/encode-path-segments

Conversation

@robrigo

@robrigo robrigo commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Stacked on #12: the last commit is this change, the five before it are #12. Rebases cleanly once #12 merges.

Why

Every endpoint interpolates its NameType, UInt64Type, or string argument raw into the request path. A value carrying /, ?, or # escapes its own segment and rewrites the request target, and a . or .. segment survives percent-encoding and is collapsed by the URL parser onto a sibling route of the same origin, so an application that passes a user-controlled string into get_collection or get_royalty_config lets that user choose the route. One helper, pathSegment in src/endpoints/utils.ts, now encodes each of the 52 segments where the path is assembled and throws on an empty, missing, or dot value, which is never an id or a name. Dotted Antelope names such as alien.worlds pass unchanged. The helper is not part of the public API.

Tests

make check and make test pass at 256 tests. All 95 recorded fixtures replay unchanged, since every value they carry is already unreserved, which also shows the paths are byte-identical for real ids and names. test/utils.ts covers the encoding, the Name and UInt64 coercions, the rejections, and a get_asset('..') call rejecting before any fetch.

Every endpoint interpolated its NameType, UInt64Type, or string argument raw into
the request path, so a value carrying a slash, a question mark, or a hash escaped
its own segment and rewrote the request target, and a dot segment survived
percent-encoding and was collapsed by the URL parser onto a sibling route of the
same origin. One helper now encodes each segment where the path is assembled and
throws on an empty, missing, or dot value, which is never an id or a name. The
recorded fixtures replay unchanged, since every value they carry is already
unreserved.
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