Skip to content

Commit

Permalink
Handle inbound exceptions on streaming request APIs (elastic#113303)
Browse files Browse the repository at this point in the history
Today if we submit a request with e.g. invalid credentials to the
`/_bulk` API then we throw a `ClassCastException` trying to cast the
`DefaultHttpRequest` to a `FullHttpRequest` on the error path. This
commit fixes the problem.
  • Loading branch information
Tim-Brooks committed Sep 20, 2024
1 parent b2eb101 commit f920e52
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
assert msg instanceof HttpObject;
if (msg instanceof HttpRequest request) {
var preReq = HttpHeadersAuthenticatorUtils.asHttpPreRequest(request);
aggregating = decider.test(preReq) && IGNORE_TEST.test(preReq);
aggregating = (decider.test(preReq) && IGNORE_TEST.test(preReq)) || request.decoderResult().isFailure();
}
if (aggregating || msg instanceof FullHttpRequest) {
super.channelRead(ctx, msg);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
"Test basic response with invalid credentials":

- skip:
features: headers

- do:
headers:
Authorization: "Basic dGVzdF91c2VyOndyb25nLXBhc3N3b3Jk" # invalid credentials
info: {}
catch: unauthorized

- match:
error.root_cause.0.type: security_exception

---
"Test bulk response with invalid credentials":

- skip:
features: headers

- do:
headers:
Authorization: "Basic dGVzdF91c2VyOndyb25nLXBhc3N3b3Jk" # invalid credentials
bulk:
body: |
{"index": {}}
{}
catch: unauthorized
- match:
error.root_cause.0.type: security_exception

0 comments on commit f920e52

Please sign in to comment.