tornadoweb / tornadoweb/tornado

Broken routing for urlencoded paths

Open
#2,548 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

routing
Dominant language
Python
Stars
22.2k
Forks
5.6k
Avg merge
3h 42m
Merged PRs (30d)
16

Description

self.request.path is the raw urlencoded path from the HTTP start line (i.e. it doesn't even normalize anything and takes whatever the client gives).
The router PathMatches uses this to match the path against this.

Having a route definition like:

application = Application([
(r"/(cn=.*)/", MainHandler),
])

fails for /cn%3Dfoo/ and /cn%3dfoo/ but not for /cn=foo/.

A workaround is:

application = Application([
(r"/(cn(?:=|%3D|%3d).*)/", MainHandler),
])

In general I think it's wrong that request.path contains the urlencoded form of the path. It should be decoded. But it's probably an issue for backwards compatibility?
At least the routing component could decode the path before applying it to the routes!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the router's PathMatches logic and the use of self.request.path, then reproduce routing for /cn=foo/, /cn%3Dfoo/, and /cn%3dfoo/. Done means the routing behavior for equivalent urlencoded paths is defined and covered consistently, while accounting for the request.path backwards-compatibility concern.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.