Skip to content

RequestRejectedHandler does not reliable prevent Internal Server Error #11645

Closed
@osiegmar

Description

@osiegmar

Describe the bug
The RequestRejectedHandler was added to provide a configurable way of handling RequestRejectedException thrown by HttpFirewall. When using a HttpStatusRequestRejectedHandler the exception is handled by returning a HTTP status code (400 by default) to the client. Unfortunately this is not reliably the case and I consider this as a bug.

To Reproduce

  • Use StrictHttpFirewall with HttpStatusRequestRejectedHandler
  • Send a request with a HTTP header X-Test with a value containing \u0099

Then two things can happen:

  1. Internal Server Error
  • Implement an endpoint that reads the header X-Test
  • A HTTP status code 500 is returned (org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the header value "Test Â�" is not allowed.)

or

  1. Success
  • Implement an endpoint that does not read headers
  • A HTTP status code 200 is returned

Expected behavior

  • Consistent behavior in both cases
  • The configured status code of HttpStatusRequestRejectedHandler (400 by default).

Sample

https://github.com/osiegmar/spring-firewall-bug

Additional notes

  • The character value \u0099 is considered invalid by StrictHttpFirewall (via regex pattern [\p{IsAssigned}&&[^\p{IsControl}]]*) but it seems to be valid according section 3.2 of RFC 7230 (field-vchar = VCHAR / obs-text ; VCHAR = %x21-7E ; obs-text = %x80-FF)
  • I assume that there are more cases when this can happen (e.g. invalid parameter names)

Metadata

Metadata

Labels

in: webAn issue in web modules (web, webmvc)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