You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "mikyll (via GitHub)" <gi...@apache.org> on 2024/12/04 15:22:27 UTC

[I] bug/feat: As a user, I want to use '%2F' in a path parameter [apisix]

mikyll opened a new issue, #11810:
URL: https://github.com/apache/apisix/issues/11810

   ### Description
   
   ## User Story
   
   As a user, I want to include URL-encoded special characters such as `%2F` in request path parameters.
   
   Example:
   
   - APISIX config:
       - running on localhost;
       - dataplane exposed on port 9080;
       - router `radixtree_uri_with_parameter`;
   - API definition: `/api/:path_parameter/foo`;
   - request URL: `http://localhost:9080/api/test%2Ftest/foo`;
   
   ## Problem
   
   Currently, APISIX with [radixtree_uri_with_parameter](https://apisix.apache.org/docs/apisix/router-radixtree/#5-parameter-match) router **doesn't support** `%2F` in path parameters.
   
   See:
   
   - PR [apache/apisix#11788](https://github.com/apache/apisix/pull/11788)
   - Issue [api7/lua-resty-radixtree#148](https://github.com/api7/lua-resty-radixtree/issues/148), 
   
   ### MRE (Minimal Reproducible Example)
   
   The following MRE demonstrates the issue. For simplicity we use APISIX in standalone mode.
   **NB**: verify that the `lib-resty-radixtree` version is >= **`2.9.2`**. 
   
   File `config.yaml`:
   
   ```yaml
   apisix:
     router:
       http: radixtree_uri_with_parameter
   
   deployment:
     role: data_plane
     role_data_plane:
       config_provider: yaml
   ```
   
   File `apisix.yaml`:
   
   ```yaml
   routes:
     # Test path parameters
     - id: path-params
       uri: /v1/:id/products/electronics/list
       upstream:
         nodes:
           "httpbin.org": 1
         type: roundrobin
       plugins:
         proxy-rewrite:
           uri: /status/200
           method: GET
   #END
   ```
   
   Test the routes:
   
   - path parameter without special characters: 🟢 
   
       ```bash
       curl -s -i localhost:9080/v1/test/products/electronics/list | grep HTTP
       HTTP/1.1 200 OK
       ```
   
   - path parameter with `%20` (URL-encoded space ` `): 🟢 
   
       ```bash
       curl -s -i localhost:9080/v1/te%20st/products/electronics/list | grep HTTP
       HTTP/1.1 200 OK
       ```
   
   - path parameter with `%2F` (URL-encoded slash `/`): 🔴 
   
       ```bash
       curl -s -i localhost:9080/v1/te%2Fst/products/electronics/list | grep HTTP
       HTTP/1.1 404 Not Found
       ```
   
   ## Additional Information
   
   > Why is this feature important?
   
   The **current behaviour** should ideally be **wrong**, since the route exists but the request URL is parsed wrongly — contrary to what the `404` status code says. Some frameworks (see the examples below) provide a more expressive implementation, such as allowing further configuration for encoded `/` and returning `400 Bad Request` when it's not allowed.
   
   ### Other Technologies/Frameworks
   
   > How do other technologies handle this?
   
   For reference, we made some test with different technologies among the most popular web servers and frameworks and almost every of them support this behaviour.
   
   We collected some examples in a repository along with instructions for the setup and test ([xpicio/routing-with-encoded-slash](https://github.com/xpicio/routing-with-encoded-slash)) and below is a summary of what we have found:
   
   | Technology         | Supports URL-encoded chars | Behaviour              | Docs |
   | ------------------ | ---------------------------| ---------------------- | ---- |
   | Django (Python)    | 🟢                         | Using `<path:id>`      | [Django - Path Converters](https://docs.djangoproject.com/en/5.1/topics/http/urls/#path-converters) |
   | Fastapi (Python)   | 🟢                         | Using `{id:path}`      | [Fastapi - Path Convertor](https://fastapi.tiangolo.com/tutorial/path-params/?h=path+para#path-convertor) |
   | Flask (Python)     | 🟢                         | Using `<path:id>`      | [Flask - Variable Rules](https://flask.palletsprojects.com/en/stable/quickstart/#variable-rules) |
   | Express (JS)       | 🟢                         | Using `:id` (default)  | - |
   | Fastify (JS)       | 🟢                         | Using `:id` (default)  | - |
   | Actix Web (Rust)   | 🟢                         | Using `{id}` (default) | - |
   | ASP.NET Core (C#)  | 🟢                         | Using `{id}` (default) | - |
   | Spring Boot (Java) | 🟢                         | By default requests containing `%2F` in path parameters return `400: Bad Request`, but Tomcat can be configured to allow them | - |
   
   ### Our Scenario
   
   > Why is this feature important to us?
   
   Our company has some legacy APIs that expect **serial numbers** containing **`/`** (encoded as `%2F`) in path parameters. Since we maintain serial numbers _virtually forever_, we cannot change them.
   To bypass the problem we defined the routes with `*` instead of named path parameters, but that makes our APIs definition **not homogeneous** and introduces the risk of **unexpected collisions**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug/feat: As a user, I want to use '%2F' in a path parameter [apisix]

Posted by "membphis (via GitHub)" <gi...@apache.org>.
membphis commented on issue #11810:
URL: https://github.com/apache/apisix/issues/11810#issuecomment-2558958281

   @mikyll I agree with you, it is a bug
   
   welcome to submit PR, many thx
   
   # WHY: it should be low priority bug
   
   I make a test, try to file name to `12/3.txt` in different OS, here is the result:
   
   ```
   windows: failed, not allow to contain `/`
   linux: failed, error msg: 12/3.txt: No such file or directory
   mac os terminal: failed, same msg as linux
   mac os finder: success, but seems little strange(pls view the attached picture
   ```
   
   <img width="503" alt="image" src="https://github.com/user-attachments/assets/c52da761-4b97-4689-9918-a90a3deb3eee" />
   
   and I check the HTTP RFC: https://datatracker.ietf.org/doc/html/rfc3986
   
   <img width="760" alt="image" src="https://github.com/user-attachments/assets/e8b33fff-43d3-4a59-9713-b4a6cc61cae7" />
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: As a user, I want to use '%2F' in a path parameter [apisix]

Posted by "AlinsRan (via GitHub)" <gi...@apache.org>.
AlinsRan closed issue #11810: bug: As a user, I want to use '%2F' in a path parameter
URL: https://github.com/apache/apisix/issues/11810


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug/feat: As a user, I want to use '%2F' in a path parameter [apisix]

Posted by "codifierr (via GitHub)" <gi...@apache.org>.
codifierr commented on issue #11810:
URL: https://github.com/apache/apisix/issues/11810#issuecomment-2735869665

   We are also facing the same problem.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org