-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
REST Resource path matching behaves differently than HTTP policy path matching #13756
Comments
My understanding is that HTTP policy path matching algorithm is not meant to be equivalent to the JAX-RS matching algorithm - I think one should use the annotations if all the variations need to be covered. |
Is the HTTP policy path matching algorithm documented somewhere as being 'different' in regards like this to the JAX-RS matching algorithm? It seems, to me at least, that regardless of that extra stuff specified in JAX-RS like template variables, regular expressions, etc. that the basic case of URI matching should be functionally identical (e.g. the (I had forgotten about that extra stuff when I specified the 'identical' part, I really just meant in terms of this basic case. A bit too over-broad sorry.) |
Np; taking care of the duplicate segment slashes makes sense. |
Found this issue after a client reported that any user could access routes that were configured to be accessible only by a certain role. This is still a security problem and not mentioned in the docs. |
Yeah, I agree this is a security issue, if endpoint can be matched with |
note: I didn't test above mentioned example, just judging by comments you report. |
Correct, I reproduced the bug with the latest quarkus version ( Thanks for taking a look at this. |
This has been fixed in 2.16.11.Final, 3.2.6.Final and 3.3.3. |
Describe the bug
REST Resources not prefixed with "/" match against "/" or "//" (note: not "///", see below) but HTTP policies not prefixed with "/" only match against "/".
For clarity (or look at example): Assume a REST Resource annotated with
@Path("test/path")
. Do not change from defaultquarkus.resteasy.path
or set@ApplicationPath
(defaults to/
). It will match against/test/path
or//test/path
(but not///test/path
. However, defining an HTTP policy oftest/path
only matches against/test/path
. If this policy has required roles associated with it then going to/test/path
gives you a 401 as appropriate but going to//test/path
gives you a 200 even though this is clearly not the expected behavior.Expected behavior
HTTP policy paths behave identically to REST resource paths for basic cases, ignoring extra stuff specified in JAX-RS like template variables, regular expressions, etc.
REST resource paths and HTTP policies behave according to RFC 3986 Section 3.3. Per RFC 3986 Section 3.3 the following paths produce the following distinct path segments:
http://localhost:8080/test/path
= path segments{"test", "path"}
http://localhost:8080//test/path
= path segments{"", "test", "path"}
http://loclahost:8080///test/path
= path segments{"", "", "test", "path"}
Reading the JAX-RS Spec, it says that:
For Path Normalization in RFC 3986 (Section 6.2.2.3) it just talks about relative paths being normalized, not empty path segments.
Glancing over the algorithm specified in JAX-RS for matching against URIs (mapping a URI to a function), it doesn't explicitly address empty path segments. The closest I could find matching this scenario was Section 3.4 of the spec:
I couldn't find what the base application path should be if left unspecified in the spec, it seemed to imply it had to be specified (based on
@ApplicationPath
or equivalent). Based on the quarkus all-config documentation, I found that it is set to the value inquarkus.resteasy.path
which is defaulted to/
see here which, all together, would imply, I think, that@Path("test/path")
should only match against/test/path
and not also against//test/path
.Actual behavior
HTTP policies do not behave identically to REST resource paths. This leads to issues like the following:
$ curl --noproxy 'localhost' -X GET -i http://localhost:8080/test/path
HTTP/1.1 401 Unauthorized
www-authenticate: Bearer {token}
content-length: 0
$ curl --noproxy 'localhost' -X GET -i http://localhost:8080//test/path
HTTP/1.1 200 OK
Content-Length: 7
Content-Type: application/octet-stream
To Reproduce
minimal-quarkus-replicator.zip
Steps to reproduce the behavior:
./gradlew quarkusDev
curl --noproxy 'localhost' -X GET -i http://localhost:8080/test/path
= 401curl --noproxy 'localhost' -X GET -i http://localhost:8080//test/path
= 200Configuration
Screenshots
N/A
Environment (please complete the following information):
uname -a
orver
: Microsoft Windows [Version 10.0.17763.1577]java -version
: Java 11mvnw --version
orgradlew --version
): Gradle 6.7.1Additional context
N/A
The text was updated successfully, but these errors were encountered: