You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not a security expert and I don't know if that feature might generate vulnerabilities or anything similar (e.g. path traversal attacks). If that's the case, you can directly close or delete the issue, but I'd love to be redirected to some relevant documentation on the topic and/or to receive some guidance on how to approach this task in the correct way 🙂
Describe the feature you'd like to add to nginx
I'd like to introduce a configuration flag named decode_percent_characters (or something similar):
by default set to on, so that it doesn't change NGiNX default behaviour;
if set to off, NGiNX doesn't replace percent-encoded characters in request URIs, with their respective decoded values (i.e. %2f doesn't get decoded to / if we set decode_percent_characters off; in nginx.conf);
Example
Show/Hide example
Suppose we have a file /usr/local/nginx/html/path%2fslash/index.html:
<!DOCTYPE html><html><head><title>Welcome to nginx!</title></head><body><h1>Welcome to nginx!</h1></body></html>
Without this change we would get a 404: Not Found error, and the following log entry in /usr/local/nginx/logs/error.log:
2025/02/07 12:15:26 [error] 103512#0: *9 "/usr/local/nginx/html/path/slash/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /path%2fslash/ HTTP/1.1", host: "localhost"
Describe the problem this feature solves
With this feature, we would be able to serve pages containing percent-encoded characters in their path (e.g. /usr/local/nginx/html/path%2fslash/index.html).
Additionally, when NGiNX is used as a reverse proxy, such as when it's distributed via OpenResty and used as an API Gateway (e.g. APISIX, Kong, etc.), we can match routes that have path parameters containing percent-encoded characters, and delegate their decoding to upstreams/other web servers.
Notice that many popular web frameworks already support percent-encoded characters in path parameters:
I already implemented two versions of this feature in a fork:
flag decode_percent_characters, to handle decoding of all percent-encoded characters: mikyll/nginx:http_parse_complex_uri_decode_percent. It's pretty straightforward, if decode_percent_characters is true, then the ngx_http_parse_complex_uri() function doesn't decode % characters (when encountering them it simply do not enter sw_quoted status);
With this feature, we could make APISIX correctly match routes containing %-encoded characters in path parameters (when using router radixtree_uri_with_parameters, see APISIX Docs | Router), by simply setting the following configuration in /apisix/path/conf/config.yaml:
Note
I'm not a security expert and I don't know if that feature might generate vulnerabilities or anything similar (e.g. path traversal attacks). If that's the case, you can directly close or delete the issue, but I'd love to be redirected to some relevant documentation on the topic and/or to receive some guidance on how to approach this task in the correct way 🙂
Describe the feature you'd like to add to nginx
I'd like to introduce a configuration flag named
decode_percent_characters
(or something similar):on
, so that it doesn't change NGiNX default behaviour;merge_slashes
, it's passed tongx_http_parse_complex_uri()
;off
, NGiNX doesn't replace percent-encoded characters in request URIs, with their respective decoded values (i.e.%2f
doesn't get decoded to/
if we setdecode_percent_characters off;
innginx.conf
);Example
Show/Hide example
Suppose we have a file
/usr/local/nginx/html/path%2fslash/index.html
:File
/usr/local/nginx/conf/nginx.conf
:Test request:
curl "localhost:80/path%2fslash/"
Result:
Without this change we would get a
404: Not Found
error, and the following log entry in/usr/local/nginx/logs/error.log
:Describe the problem this feature solves
With this feature, we would be able to serve pages containing percent-encoded characters in their path (e.g.
/usr/local/nginx/html/path%2fslash/index.html
).Additionally, when NGiNX is used as a reverse proxy, such as when it's distributed via OpenResty and used as an API Gateway (e.g. APISIX, Kong, etc.), we can match routes that have path parameters containing percent-encoded characters, and delegate their decoding to upstreams/other web servers.
Notice that many popular web frameworks already support percent-encoded characters in path parameters:
<path:id>
{id:path}
<path:id>
:id
(default):id
(default){id}
(default){id}
(default)%2F
in path parameters return400: Bad Request
, but Tomcat can be configured to allow themAdditional context
Some References
%
in request URIs, from a StackOverflow answer;Feature Implementation
I already implemented two versions of this feature in a fork:
decode_percent_characters
, to handle decoding of all percent-encoded characters: mikyll/nginx:http_parse_complex_uri_decode_percent. It's pretty straightforward, ifdecode_percent_characters
is true, then thengx_http_parse_complex_uri()
function doesn't decode%
characters (when encountering them it simply do not entersw_quoted
status);decode_slashes
, to handle decoding of only%2f
(slash/
) character: mikyll/nginx:http_parse_complex_uri_decode_slashesAPISIX Example
With this feature, we could make APISIX correctly match routes containing %-encoded characters in path parameters (when using router
radixtree_uri_with_parameters
, see APISIX Docs | Router), by simply setting the following configuration in/apisix/path/conf/config.yaml
:OpenResty
Maybe there's a simpler way to handle this via OpenResty
ngx_http_lua_module
?The text was updated successfully, but these errors were encountered: