-
Notifications
You must be signed in to change notification settings - Fork 594
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
StackOverflowError on invalid media range in accept header. #1072
Comments
Hi and thanks for the reproducer! |
We seem to have multiple problems here leading to the explained outcome:
History: In akka/akka#16494, support for In akka/akka#19397 and akka/akka#19842 (fixed in akka/akka#19849), it was attempted to make non-200 responses ignore the accept header. The solution was to rerun the marshalling with
|
…to fromStatusCodeAndHeadersAndValue marshaller This is an alternative solution for akka/akka#19397 that replaces the one introduced in akka/akka#19849. The former solution placed the special handling inside the main processing path of requests in Akka HTTP. This solution is simpler and fixes the issue in a narrower way. The code comment explains the solution: For non-2xx status, add an opaque fallback marshalling using the first returned marshalling that will be used if the result wouldn't otherwise be accepted. The reasoning is that users often use routes like `complete(400 -> "Illegal request in this context")` to fail a route (instead of using rejection handling). If the client uses narrow Accept headers like `Accept: application/json` the user supplied error message will not be rendered because it will only accept `text/plain` but not `application/json` responses and fail the whole request with a "406 Not Acceptable" response. Adding the opaque fallback rendering will give an escape hatch for those situations.
…to fromStatusCodeAndHeadersAndValue marshaller This is an alternative solution for akka/akka#19397 that replaces the one introduced in akka/akka#19849. The former solution placed the special handling inside the main processing path of requests in Akka HTTP. This solution is simpler and fixes the issue in a narrower way. The code comment explains the solution: For non-2xx status, add an opaque fallback marshalling using the first returned marshalling that will be used if the result wouldn't otherwise be accepted. The reasoning is that users often use routes like `complete(400 -> "Illegal request in this context")` to fail a route (instead of using rejection handling). If the client uses narrow Accept headers like `Accept: application/json` the user supplied error message will not be rendered because it will only accept `text/plain` but not `application/json` responses and fail the whole request with a "406 Not Acceptable" response. Adding the opaque fallback rendering will give an escape hatch for those situations.
…to fromStatusCodeAndHeadersAndValue marshaller This is an alternative solution for akka/akka#19397 that replaces the one introduced in akka/akka#19849. The former solution placed the special handling inside the main processing path of requests in Akka HTTP. This solution is simpler and fixes the issue in a narrower way. The code comment explains the solution: For non-2xx status, add an opaque fallback marshalling using the first returned marshalling that will be used if the result wouldn't otherwise be accepted. The reasoning is that users often use routes like `complete(400 -> "Illegal request in this context")` to fail a route (instead of using rejection handling). If the client uses narrow Accept headers like `Accept: application/json` the user supplied error message will not be rendered because it will only accept `text/plain` but not `application/json` responses and fail the whole request with a "406 Not Acceptable" response. Adding the opaque fallback rendering will give an escape hatch for those situations.
…to fromStatusCodeAndHeadersAndValue marshaller This is an alternative solution for akka/akka#19397 that replaces the one introduced in akka/akka#19849. The former solution placed the special handling inside the main processing path of requests in Akka HTTP. This solution is simpler and fixes the issue in a narrower way. The code comment explains the solution: For non-2xx status, add an opaque fallback marshalling using the first returned marshalling that will be used if the result wouldn't otherwise be accepted. The reasoning is that users often use routes like `complete(400 -> "Illegal request in this context")` to fail a route (instead of using rejection handling). If the client uses narrow Accept headers like `Accept: application/json` the user supplied error message will not be rendered because it will only accept `text/plain` but not `application/json` responses and fail the whole request with a "406 Not Acceptable" response. Adding the opaque fallback rendering will give an escape hatch for those situations. Added more tests to `FromStatusCodeAndXYZMarshallerSpec` (formerly known as `ContentNegotiationGivenResponseCodeSpec`) to cover the new behavior.
…to fromStatusCodeAndHeadersAndValue marshaller This is an alternative solution for akka/akka#19397 that replaces the one introduced in akka/akka#19849. The former solution placed the special handling inside the main processing path of requests in Akka HTTP. This solution is simpler and fixes the issue in a narrower way. The code comment explains the solution: For non-2xx status, add an opaque fallback marshalling using the first returned marshalling that will be used if the result wouldn't otherwise be accepted. The reasoning is that users often use routes like `complete(400 -> "Illegal request in this context")` to fail a route (instead of using rejection handling). If the client uses narrow Accept headers like `Accept: application/json` the user supplied error message will not be rendered because it will only accept `text/plain` but not `application/json` responses and fail the whole request with a "406 Not Acceptable" response. Adding the opaque fallback rendering will give an escape hatch for those situations. Added more tests to `FromStatusCodeAndXYZMarshallerSpec` (formerly known as `ContentNegotiationGivenResponseCodeSpec`) to cover the new behavior.
…extImpl =htp #1072 move special non-2xx handling from RequestContextImpl to fromStatusCodeAndHeadersAndValue marshaller
Thanks a lot, @mrumkovskis to make us aware of this issue. |
…to fromStatusCodeAndHeadersAndValue marshaller This is an alternative solution for akka/akka#19397 that replaces the one introduced in akka/akka#19849. The former solution placed the special handling inside the main processing path of requests in Akka HTTP. This solution is simpler and fixes the issue in a narrower way. The code comment explains the solution: For non-2xx status, add an opaque fallback marshalling using the first returned marshalling that will be used if the result wouldn't otherwise be accepted. The reasoning is that users often use routes like `complete(400 -> "Illegal request in this context")` to fail a route (instead of using rejection handling). If the client uses narrow Accept headers like `Accept: application/json` the user supplied error message will not be rendered because it will only accept `text/plain` but not `application/json` responses and fail the whole request with a "406 Not Acceptable" response. Adding the opaque fallback rendering will give an escape hatch for those situations. Added more tests to `FromStatusCodeAndXYZMarshallerSpec` (formerly known as `ContentNegotiationGivenResponseCodeSpec`) to cover the new behavior.
Route produces java.lang.StackOverflowError (shuts the server down) if http request contains Accept header with invalid media range like: '*/xml'
For example: Accept: */xml
Can be reproduced on almost any running akka-http server using routing DSL including sample one provided in the documentation: http://doc.akka.io/docs/akka-http/current/scala/http/introduction.html#using-akka-http
Was not able to reproduce error using ScalatestRouteTest
This seems due to the error in header parsing i.e.
akka.http.scaladsl.model.headers.Accept.parseFromValueString("*/xml").toOption.get.acceptsAll == true
akka-http version: 10.0.5
The text was updated successfully, but these errors were encountered: