-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Lenient URI parsing in ServletServerHttpRequest #30489
Comments
For anyone facing this issue. Here my work around. Work around is to monkey patch the java.net.URI class Uncomment lowMask and highMask. replacing L_MARK and H_MARK to add your relaxed characters.
|
Hi @alexisgayte, Could you please ellaborate on how I can monkey patch java.net.RMI class by giving a more detailed example. |
with Java 8, just add the tweaked java.net.URI into your project. It will override it. something like that : cf https://openjdk.org/projects/jigsaw/ Then you need to integrate it with your project builder.
|
Does this have fixed in a recent Spring framework? |
I don't think so. |
It should just pass it as a String, IMHO. |
I am a little bit confused by the report. You're talking about reactive and tomcat and the code that you link is from Spring MVC. I took the time to rebuild a small sample based on your description and it works fine. If you want support, please provide a small sample that we can run ourselves that reproduces the issue. You can attach it as a zip or you can push the code to a GitHub repository. Please note that while Spring Framework 5.3.x is still supported in OSS, Spring Boot 2.x is not. |
Hi Shephane, This was with spring boot 3.1.7 and I believe it hasn't changed with 3.2.1 BTW I am a big fan of your work. Thanks for all your work. |
Sorry, it happens quite often I get caught by this. There are two
Yeah, that's why I was surprised. I didn't know about the Spring Cloud Gateway bit and I guess it might be related. I've pushed my little sample that only uses framework https://github.com/snicoll-scratches/spring-framework-30489. Perhaps you can have a look to it and see what's missing to reproduce the issue? |
Hi Stéphane, your sample is correct, but the test is not, probably due to webClient. But if you run it as an app and use your browser you will get a 400. Side note:
You will get this log :
the important one is : I believe you will be back to this initial report then, I haven't digged into it but that seems to be the issue. |
I think the main difference between WebFlux and MVC is that The MVC variant has a fallback and only uses Lines 129 to 132 in f846d94
The WebFlux variant does not have such fallback and throws the URI exception, see https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java#L131 Note that Spring MVC doesn't alwaus uses this URI information, but will do in our filters and CORS support infrastructure. I don't think we should expand the lenient fallback in WebFlux but rather reconsider it in MVC, as the I'll repurpose this issue to discuss that change with @rstoyanchev . |
ServletServerHttpRequest
ServletServerHttpRequest
I agree that proceeding without the query is not ideal. Looking at #20960 it was added to ignore an invalid query, but as a measure it's rather imprecise, and could create new issues, while also masking the original one. I'm guessing that in the case of the example URI, dropping the query would not solve the issue as the request probably won't succeed without the id parameter. Ideally the client should encode the query, but when that's not possible something else would have to do it. We could consider a similar property to Tomcat's relaxed query chars, and create a fallback where we iterate over the query and encode any such configured chars, which would make it possible to create a URI. |
Linked to #25274 , #30475
url with relaxed char are not allowed even with the option set.
Url example : /test?id={64aaa32-3f4e-93b0-9cd9-986a0a34a650}
using reactive and tomcat with TomcatHttpHandlerAdapter, this url call will fail down the route.
as ServletHttpHandlerAdapter creates a ServletServerHttpRequest that tries to parse the url with java.net.URI which doesn't allow relaxed-query-chars.
The issue is here :
spring-framework/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java
Line 131 in c227fbf
the URI parser doesn't allow relaxed char.
Error thrown is : ServletHttpHandlerAdapter - Failed to get request URL: Illegal character in query at
The text was updated successfully, but these errors were encountered: