Skip to content

Commit fd4da62

Browse files
authored
Handle inbound exceptions on streaming request APIs (#113303) (#113318)
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.
1 parent b2eb101 commit fd4da62

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
4646
assert msg instanceof HttpObject;
4747
if (msg instanceof HttpRequest request) {
4848
var preReq = HttpHeadersAuthenticatorUtils.asHttpPreRequest(request);
49-
aggregating = decider.test(preReq) && IGNORE_TEST.test(preReq);
49+
aggregating = (decider.test(preReq) && IGNORE_TEST.test(preReq)) || request.decoderResult().isFailure();
5050
}
5151
if (aggregating || msg instanceof FullHttpRequest) {
5252
super.channelRead(ctx, msg);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
"Test basic response with invalid credentials":
3+
4+
- skip:
5+
features: headers
6+
7+
- do:
8+
headers:
9+
Authorization: "Basic dGVzdF91c2VyOndyb25nLXBhc3N3b3Jk" # invalid credentials
10+
info: {}
11+
catch: unauthorized
12+
13+
- match:
14+
error.root_cause.0.type: security_exception
15+
16+
---
17+
"Test bulk response with invalid credentials":
18+
19+
- skip:
20+
features: headers
21+
22+
- do:
23+
headers:
24+
Authorization: "Basic dGVzdF91c2VyOndyb25nLXBhc3N3b3Jk" # invalid credentials
25+
bulk:
26+
body: |
27+
{"index": {}}
28+
{}
29+
catch: unauthorized
30+
- match:
31+
error.root_cause.0.type: security_exception

0 commit comments

Comments
 (0)