|
49 | 49 | import org.checkerframework.checker.nullness.qual.NonNull; |
50 | 50 | import org.junit.jupiter.api.Test; |
51 | 51 | import org.junit.jupiter.api.extension.ExtendWith; |
52 | | -import org.junit.jupiter.params.ParameterizedTest; |
53 | | -import org.junit.jupiter.params.provider.ValueSource; |
54 | 52 | import org.mockito.junit.jupiter.MockitoExtension; |
55 | 53 |
|
56 | 54 | /** |
@@ -271,62 +269,6 @@ void maxHeaderSizeExceeded_setBadRequestStatus() { |
271 | 269 | .isEqualTo("Invalid request provided: Decode failure"); |
272 | 270 | } |
273 | 271 |
|
274 | | - @Test |
275 | | - void invalidUri_setBadRequestStatus() { |
276 | | - ClientRequestReceiver receiver = new ClientRequestReceiver(null); |
277 | | - EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestEncoder()); |
278 | | - PassportLoggingHandler loggingHandler = new PassportLoggingHandler(new DefaultRegistry()); |
279 | | - |
280 | | - channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234); |
281 | | - channel.pipeline().addLast(new HttpServerCodec()); |
282 | | - channel.pipeline().addLast(receiver); |
283 | | - channel.pipeline().addLast(loggingHandler); |
284 | | - |
285 | | - HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/{invalid}"); |
286 | | - |
287 | | - channel.writeOutbound(httpRequest); |
288 | | - ByteBuf byteBuf = channel.readOutbound(); |
289 | | - channel.writeInbound(byteBuf); |
290 | | - channel.readInbound(); |
291 | | - channel.close(); |
292 | | - |
293 | | - HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel); |
294 | | - SessionContext context = request.getContext(); |
295 | | - assertThat(context.get(CommonContextKeys.BAD_URI_REASON)).isNotNull(); |
296 | | - assertThat(StatusCategoryUtils.getStatusCategory(context)) |
297 | | - .isEqualTo(ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST); |
298 | | - // Raw URI preserved for access logging, not replaced with a placeholder. |
299 | | - assertThat(request.getPath()).isEqualTo("/{invalid}"); |
300 | | - } |
301 | | - |
302 | | - @Test |
303 | | - void invalidPercentEncoding_setBadRequestStatus() { |
304 | | - // %GG is invalid (G is not a hex digit) — old fallback forwarded the un-normalized path to origin |
305 | | - ClientRequestReceiver receiver = new ClientRequestReceiver(null); |
306 | | - EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestEncoder()); |
307 | | - PassportLoggingHandler loggingHandler = new PassportLoggingHandler(new DefaultRegistry()); |
308 | | - |
309 | | - channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234); |
310 | | - channel.pipeline().addLast(new HttpServerCodec()); |
311 | | - channel.pipeline().addLast(receiver); |
312 | | - channel.pipeline().addLast(loggingHandler); |
313 | | - |
314 | | - HttpRequest httpRequest = |
315 | | - new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/%GG/../../actuator/env"); |
316 | | - |
317 | | - channel.writeOutbound(httpRequest); |
318 | | - ByteBuf byteBuf = channel.readOutbound(); |
319 | | - channel.writeInbound(byteBuf); |
320 | | - channel.readInbound(); |
321 | | - channel.close(); |
322 | | - |
323 | | - HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel); |
324 | | - SessionContext context = request.getContext(); |
325 | | - assertThat(context.get(CommonContextKeys.BAD_URI_REASON)).isNotNull(); |
326 | | - assertThat(StatusCategoryUtils.getStatusCategory(context)) |
327 | | - .isEqualTo(ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST); |
328 | | - } |
329 | | - |
330 | 272 | @Test |
331 | 273 | void multipleHostHeaders_setBadRequestStatus() { |
332 | 274 | ClientRequestReceiver receiver = new ClientRequestReceiver(null); |
@@ -594,55 +536,20 @@ void pathTraversal_withQueryString() { |
594 | 536 | channel.close(); |
595 | 537 | } |
596 | 538 |
|
597 | | - @ParameterizedTest |
598 | | - @ValueSource(strings = {"/public/%2e%2e/admin/", "/public/%2E%2E/admin/"}) |
599 | | - void pathTraversal_encodedDotDot(String uri) { |
| 539 | + @Test |
| 540 | + void pathTraversal_withOpaqueURI() { |
600 | 541 | EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null)); |
601 | 542 | channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234); |
602 | 543 | HttpRequestMessageImpl result; |
603 | 544 | { |
604 | | - channel.writeInbound( |
605 | | - new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri, Unpooled.buffer())); |
| 545 | + channel.writeInbound(new DefaultFullHttpRequest( |
| 546 | + HttpVersion.HTTP_1_1, HttpMethod.GET, "foo.netflix.net:443", Unpooled.buffer())); |
606 | 547 | result = channel.readInbound(); |
607 | 548 | result.disposeBufferedBody(); |
608 | 549 | } |
609 | 550 |
|
610 | | - assertThat(result.getPath()).isEqualTo("/admin/"); |
611 | | - channel.close(); |
612 | | - } |
613 | | - |
614 | | - @ParameterizedTest |
615 | | - @ValueSource(strings = {"/public/%2F../secret", "/public/%2f../secret"}) |
616 | | - void encodedSlash_rejected(String uri) { |
617 | | - EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null)); |
618 | | - channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234); |
619 | | - channel.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri, Unpooled.buffer())); |
620 | | - channel.readInbound(); |
| 551 | + assertThat(result.getPath()).isEqualTo("foo.netflix.net:443"); |
621 | 552 | channel.close(); |
622 | | - |
623 | | - SessionContext context = |
624 | | - ClientRequestReceiver.getRequestFromChannel(channel).getContext(); |
625 | | - assertThat(context.get(CommonContextKeys.BAD_URI_REASON)).isNotNull(); |
626 | | - assertThat(StatusCategoryUtils.getStatusCategory(context)) |
627 | | - .isEqualTo(ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST); |
628 | | - assertThat(StatusCategoryUtils.getStatusCategoryReason(context)).isEqualTo("encoded slash in path"); |
629 | | - } |
630 | | - |
631 | | - @Test |
632 | | - void opaqueUri_rejected() { |
633 | | - EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null)); |
634 | | - channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234); |
635 | | - channel.writeInbound(new DefaultFullHttpRequest( |
636 | | - HttpVersion.HTTP_1_1, HttpMethod.GET, "foo.netflix.net:443", Unpooled.buffer())); |
637 | | - channel.readInbound(); |
638 | | - channel.close(); |
639 | | - |
640 | | - SessionContext context = |
641 | | - ClientRequestReceiver.getRequestFromChannel(channel).getContext(); |
642 | | - assertThat(context.get(CommonContextKeys.BAD_URI_REASON)).isNotNull(); |
643 | | - assertThat(StatusCategoryUtils.getStatusCategory(context)) |
644 | | - .isEqualTo(ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST); |
645 | | - assertThat(StatusCategoryUtils.getStatusCategoryReason(context)).isEqualTo("opaque URI"); |
646 | 553 | } |
647 | 554 |
|
648 | 555 | @Test |
|
0 commit comments