Skip to content

fix(python): decode routeTemplate to a fixed point before traversal checks - #18

Closed
PhilBot402 wants to merge 2 commits into
mainfrom
philbot-python-route-template-fixed-point-decode-ccdb
Closed

PhilBot402 wants to merge 2 commits into
mainfrom
philbot-python-route-template-fixed-point-decode-ccdb

Conversation

@PhilBot402

Copy link
Copy Markdown
Owner

Port of x402-foundation#3213 from TypeScript to Python SDK.

_is_valid_route_template used a single unquote pass before its traversal and scheme-injection checks. _ROUTE_TEMPLATE_RE allows %, so a double-encoded payload such as %252e%252e stayed percent-encoded after one decode and slipped past .. and ://. The helper now decodes to a fixed point with a pass budget of 5, matching TypeScript isValidRouteTemplate. Regression tests cover double and triple encoding, scheme injection, a legitimate caf%C3%A9 segment, and encoding deeper than the budget. Related tracking issue: x402-foundation#3439 (this PR covers the Python bazaar item only).

AI disclosure: Automated by @phdargen. Use your own judgement

Open in Web Open in Cursor 

PhilBot402 and others added 2 commits September 10, 2026 07:26
Port the TypeScript x402-foundation#3213 cases that a single unquote pass misses:
double- and triple-encoded traversal, double-encoded scheme injection,
a legitimate cafe segment, and encoding deeper than the decode budget.

Co-authored-by: phdargen <phdargen@users.noreply.github.com>
…hecks

_is_valid_route_template decoded a routeTemplate with a single unquote
pass before checking for ".." (traversal) and "://" (scheme injection).
_ROUTE_TEMPLATE_RE explicitly allows "%", so a double percent-encoded
payload (%252e%252e, %253a%252f%252f, ...) survives one decode still
percent-encoded. The substring checks never see the traversal or
injection content, and the function incorrectly returns true.

A single extra decode pass would only close the double-encoded case.
_fully_decode_route_template decodes repeatedly until a fixed point is
reached or a bounded pass budget (5) is exhausted, then runs the
existing checks against that canonical form.

Co-authored-by: phdargen <phdargen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant