Skip to content

ServletServerHttpRequest.getURI() may throw a java.net.URISyntaxException [SPR-16414] #20960

@spring-projects-issues

Description

@spring-projects-issues

Oliver Becker opened SPR-16414 and commented

We just encountered an error in our Spring Boot application that came from the innocent looking call

ServletUriComponentsBuilder.fromRequest(httpServletRequest)

which uses internally

ServletServerHttpRequest.getURI()

The URL of this request was indeed illegal since it had an illegal escape sequence in its query part, something like http://app.org/request?query=foo% or http://app.org/request?query=foo%xx. Typing this URL into a browser will cause normal request processing (the controller will handle the query parameter as not present, the corresponding @RequestParam is null), however using the ServletUriComponentsBuilder as mentioned above will cause a java.net.URISyntaxException. (In our case this exception occurred during the rendering of the view, which is even worse.)

I wonder if the framework (i.e. ServletUriComponentsBuilder or ServletUriComponentsBuilder) should handle this illegal URI. Or is it the job of the application using the framework? Either way, the user shouldn't see an error 500.


Affects: 4.3.13

Referenced from: commits 0e6f8df, 04f9549

Backported to: 4.3.15

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions