-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Routing percent-encoded paths #2678
Comments
I wonder if it would be possible to instead do partial percent decoding before routing - only translating unreserved (pointlessly) percent-encoded characters to their regular character. Notably, this avoids any issues with The W.r.t. what we allow in |
We could decode just the unreserved characters, but then I think we should also encode reserved characters (like Regarding separators inside path segments, I assumed that this would be something that would come from matchit, I know there were some issues about matching based on extensions and such and I believe the change in its grammar was in part to be able to support things like that later. I'm not exactly sure how this is consideration here but it's been some time since I've seen this. Or we can just decode the unreserved characters and ignore the rest for now of course. |
Maybe just forbid Not sure about the rest of your comment, I also don't have the entire context rn. |
Feature Request
Motivation
URIs can be percent-encoded but that should not change what resource is accessed.
More specifically, RFC3986 says:
There are also some characters that are sometimes encoded and sometimes not in the real world, e.g. hyper will probably have handling of
{
,}
, and"
in paths configurable.Proposal
We can unescape unreserved characters inside the path, which can be decoded at any time. E.g. requests
, etc. to normalize these before routing).
/axum
and/%61xum
can be interpreted as the same one. We can also normalize reserved characters by percent-encoding them, if they are in the path (with some exceptions that already have special meaning like%
,?
,#
, and so on; we can however encode{
,"
,We can also encode special characters when registering a route such as internally turning current
.route("/100%",..)
into.route("/100%25", ...)
(%25
is percent encoding for%
). Special case of this is that a user can currently write.route("/what?",...)
which can never match any request.With these two changes users can use special characters in route like
r#"/"qoutes"/etc"#
and match it with both encdoed and not encoded variants.Alternatives
Using a middleware before
axum::Router
that decodes (or rather otherwise normalizes) the percent-encoding. Not all percent-decoded paths are valid paths in URI so it would most likely have to percent-decode unreserved characters and percent-encode reserved characters to normalize.This can be combined with encoding special characters when they are to be registered to
matchit
(e.g. braces, percent, question mark,...) either by providing something likeroute_encoded
or by having the user encode any needed characters themselves.I mention this primarily in case we would want to support people who want to have control over percent decoding themselves, but I think this can be also just built inside
axum
itself.The text was updated successfully, but these errors were encountered: