perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

In tomcat with -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true, the FilterTools.getRelativePath does not works correctly #1026

Open miguoliang opened 6 years ago

miguoliang commented 6 years ago

if a URL contains a %2F, e.g. http://localhost:8080/api/v1/permissionrole/permission/get%2Fabc, the HttpServletRequest.getRequestURI could return the raw uri correctly, but the FilterTools.getRelativePath decoded the %2F in the path. Maybe it's not right.

the correct result should be /api/v1/permissionrole/permission/get%2Fabc, but /api/v1/permissionrole/permission/get/abc returned by FilterTools.getRelativePath.

this PR works for this case, https://github.com/perwendel/spark/pull/553.

Thanks.

https://github.com/perwendel/spark/blob/c697d981268c538dfeeb38786bd9eb0a03ab86f0/src/main/java/spark/servlet/FilterTools.java#L55

Bugjudger commented 3 years ago

I would like to work on this issue

Bugjudger commented 3 years ago

I want to use UTF-8 to solve this problem. When the path in URL has %, the user can not put the URL in the address bar in the browser directly. They should encode URL in UTF-8 . There are two ways:

  1. url_encode = encodeURL(URL) (in JavaScript language). Then put url_encode into address bar,
  2. open the setting: send url by UTF-8 in browser. And then change the % to %25.