apisix icon indicating copy to clipboard operation
apisix copied to clipboard

bug: 404 route not found if URI contains %0A

Open gxthrj opened this issue 5 years ago • 10 comments

Issue description

If URI contains %0A, will cause route match failed.

Environment

  • apisix version (cmd: apisix version): 2.6

Minimal test code / Steps to reproduce the issue

Bug report without steps to reproduce will be ignored or closed.

  1. create a route
curl http://127.0.0.1:9080/apisix/admin/routes/31 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
    "uri": "*",
    "hosts": ["foo.com"],
    "methods": ["PUT", "GET"],
    "enable_websocket": true,
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "httpbin.org": 1
        }
    }
}'
  1. have a try with normal request
curl -i http://127.0.0.1:9080/ip -H "Host:foo.com"

It will be success.

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 45
Connection: keep-alive
Date: Tue, 06 Jul 2021 14:47:10 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/2.6

{
  "origin": "172.19.0.1, 114.220.17.103"
}
  1. If URI contains %0A
curl -i http://127.0.0.1:9080/ip%0AVega -H "Host:foo.com"

will get 404

HTTP/1.1 404 Not Found
Date: Tue, 06 Jul 2021 14:35:51 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.6

{"error_msg":"404 Route Not Found"}

What's the expected result?

Expect normal routing, and upstream returns 404

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

gxthrj avatar Jul 06 '21 14:07 gxthrj

What is the exact behavior if you access the upstream directly with this URL?

tokers avatar Jul 07 '21 02:07 tokers

What is the exact behavior if you access the upstream directly with this URL?

It has been written here.

image

gxthrj avatar Jul 07 '21 02:07 gxthrj

What is the exact behavior if you access the upstream directly with this URL?

It has been written here.

image

I mean, don't use APISIX as the proxy.

tokers avatar Jul 07 '21 02:07 tokers

Look like it is a bug in the route match library.

spacewander avatar Jul 07 '21 02:07 spacewander

What is the exact behavior if you access the upstream directly with this URL?

It has been written here. image

I mean, don't use APISIX as the proxy.

Using Nginx, it will return from upstream. Because the location is '*'.

gxthrj avatar Jul 07 '21 02:07 gxthrj

Look like it is a bug in the route match library.

Yep

gxthrj avatar Jul 07 '21 02:07 gxthrj

Is there an easy fix for this? When can we expect a fix?

JanLi-air avatar Jul 07 '21 09:07 JanLi-air

fixed: https://github.com/api7/lua-resty-radixtree/pull/99

membphis avatar Jul 07 '21 09:07 membphis

Great~

gxthrj avatar Jul 07 '21 10:07 gxthrj

need to use new version before closing this issue. my bad

Yiyiyimu avatar Jul 07 '21 16:07 Yiyiyimu