-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
RequestRejectedException should be 400 by default #7568
Comments
@fhanik I would like to take this one. |
Additional information: It seems for me that in these cases the following exception is thrown:
If I understand properly the task is here that this exception should be handled with 400 http status (not 500). I could find an analogous solution in the BearerTokenAuthenticationFilter, where the exception is passed to authenticationFailureHandler which will return the necessary status code. So I think this issue should be solved with a similiar solution: maybe with authenticationFailureHandler, or with a new type of failure handler, which is called in org.springframework.security.web.FilterChainProxy#doFilterInternal if an exception is thrown. @fhanik What do you think about this solution? |
We cannot change the default, but you can now change the behavior with gh-7052 |
This commit changes default rejected handler to HttpStatusRequestRejectedHandler. Fixes spring-projectsgh-7568
Well, I have a few questions, but for illustration I sent a draft commit too.
|
This was the past behavior and it should remain this way for passivity. User's were encouraged to add their own error handling using a Filter or mapping the Exception to the servlet containers error handling
This will not change until Spring Security 6.x |
the default 500 code is just bad |
@walec51 Yes The plan is to change the behavior in the next major release. We need to remain passive for those that may be catching the RequestRejectedException and handling it in the container error handling or within a Filter that is before Spring Security |
Hi @rwinch , |
Yes, but it won't happen until 6.0 which we don't have branch for yet |
Spring firewall returns 500 when RequestRejectedException is thrown. The correct status code is 400. This is going to be addressed by spring-projects/spring-security#7568
…pring-projects/spring-security#7568 Change-Id: Ia9a5bbc21c4c36e32430d01a477d1545174c963a
I found a way to handle it according to my needs. First the log level and status code: @Override
public void handle(HttpServletRequest request, HttpServletResponse response, RequestRejectedException requestRejectedException) throws IOException {
LOGGER.warn("Application firewall: {}", requestRejectedException.getMessage(),
LOGGER.isDebugEnabled() ? requestRejectedException : null);
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, requestRejectedException);
response.sendError(403, "firewall rejected");
} And additionally the response body via the @RestController
public class ErrorPageController implements ErrorController {
@RequestMapping("/error")
public ResponseEntity<ErrorResponse> renderErrorPage(final HttpServletRequest request) {
return new ResponseEntity(request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE), new ErrorResponse(request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)));
}
} I would still prefer a simple |
I used Kotlin and the following is my workaround @Component
class RequestRejectedExceptionHandler : RequestRejectedHandler {
override fun handle(
request: HttpServletRequest,
response: HttpServletResponse,
requestRejectedException: RequestRejectedException
) {
logger.warn(requestRejectedException.toString())
response.sendError(HttpServletResponse.SC_BAD_REQUEST)
}
} |
I coudn't find the history, but found the my case:
There were // kotlin
@Configuration
class RequestRejectedHandlerConfig {
@Bean
fun requestRejectedHandler(): RequestRejectedHandler {
return HttpStatusRequestRejectedHandler()
}
}
edit) I've noticed that @Controller
class ErrorController {
@GetMapping("/error")
fun error(): ResponseEntity<Any> {
return ResponseEntity.status(400).build()
}
}
|
Summary
We are getting 500 from spring security jar if we use // in URL, ideally it should give 400 bad request.
Ex. - https://com.sap/Spring//Security - as it has // in URL is should give 400 bad request but we are getting 500
Actual Behavior
https://com.sap/Spring//Security - as it had // in URL is should give 400 bad request
Please describe step by step the behavior you are observing
Use any valid URL and add // in it ex. /ThingConfiguration/v1/Packages// and use spring security version - 5.1.5.RELEASE.
Expected Behavior
it should give 400 bad request
Configuration
Version
spring security version - 5.1.5.RELEASE.
Sample
The text was updated successfully, but these errors were encountered: