Skip to content
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

[3.9.x] HttpServerRequest#absoluteURI runs into URI parsing error and then returns null #1654

Closed
jaikiran opened this issue Jul 4, 2020 · 2 comments
Labels

Comments

@jaikiran
Copy link

jaikiran commented Jul 4, 2020

This was raised as an issue in Quarkus, here quarkusio/quarkus#10177. However, looking into the details, it turns out to be an issue in vertx-web project.

If the request URI path contains special character like [, any calls to HttpServerRequest.absoluteURI will (internally) run into a URI parsing exception (which is only logged) and the method ends up returning null.

Here's a test case which reproduces this against the latest 3.9 branch:

diff --git a/vertx-web/src/test/java/io/vertx/ext/web/handler/HttpRequestPathTest.java b/vertx-web/src/test/java/io/vertx/ext/web/handler/HttpRequestPathTest.java
new file mode 100644
index 00000000..b1b05628
--- /dev/null
+++ b/vertx-web/src/test/java/io/vertx/ext/web/handler/HttpRequestPathTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2020 Red Hat, Inc.
+ *
+ *  All rights reserved. This program and the accompanying materials
+ *  are made available under the terms of the Eclipse Public License v1.0
+ *  and Apache License v2.0 which accompanies this distribution.
+ *
+ *  The Eclipse Public License is available at
+ *  http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  The Apache License v2.0 is available at
+ *  http://www.opensource.org/licenses/apache2.0.php
+ *
+ *  You may elect to redistribute this code under either of these licenses.
+ */
+
+package io.vertx.ext.web.handler;
+
+import io.vertx.core.http.HttpMethod;
+import io.vertx.ext.web.WebTestBase;
+import org.junit.Test;
+
+public class HttpRequestPathTest extends WebTestBase {
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+
+  }
+
+  @Test
+  public void testSpecialCharAbsoluteURI() throws Exception {
+    router.route().handler((rc) -> {
+      final String absoluteURI = rc.request().absoluteURI();
+      if (absoluteURI == null) {
+        throw new RuntimeException("Absolute URI was null");
+      }
+      rc.next();
+    });
+    router.route().handler(rc -> rc.response().end());
+    testSyncRequest("GET", "/[hello", 200, "OK", "");
+  }
+
+}

This test run results in the following log messages and the failure:

Failed to create abs uri 
java.net.URISyntaxException: Illegal character in path at index 1: /[hello
	at java.base/java.net.URI$Parser.fail(URI.java:2915)
	at java.base/java.net.URI$Parser.checkChars(URI.java:3086)
	at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3168)
	at java.base/java.net.URI$Parser.parse(URI.java:3127)
	at java.base/java.net.URI.<init>(URI.java:600)
	at io.vertx.core.http.impl.HttpUtils.absoluteURI(HttpUtils.java:366)
	at io.vertx.core.http.impl.HttpServerRequestImpl.absoluteURI(HttpServerRequestImpl.java:370)
	at io.vertx.ext.web.impl.HttpServerRequestWrapper.absoluteURI(HttpServerRequestWrapper.java:210)
	at io.vertx.ext.web.handler.HttpRequestPathTest.lambda$testSpecialCharAbsoluteURI$0(HttpRequestPathTest.java:34)
...
java.lang.AssertionError: expected:<200> but was:<500>
	at org.junit.Assert.fail(Assert.java:88)
	at org.junit.Assert.failNotEquals(Assert.java:834)
	at org.junit.Assert.assertEquals(Assert.java:645)
	at org.junit.Assert.assertEquals(Assert.java:631)
	at io.vertx.test.core.AsyncTestBase.assertEquals(AsyncTestBase.java:235)
	at io.vertx.ext.web.WebTestBase.testSyncRequest(WebTestBase.java:196)
	at io.vertx.ext.web.handler.HttpRequestPathTest.testSpecialCharAbsoluteURI(HttpRequestPathTest.java:41)

@pmlopes
Copy link
Member

pmlopes commented Jul 8, 2020

brackets should be url encoded if i'm not mistaken. Also this isn't reproducible on master, in order to fix it we need to apply on core what we now do on web.

@pmlopes pmlopes added invalid and removed bug Something isn't working labels Jul 8, 2020
@pmlopes
Copy link
Member

pmlopes commented Jul 8, 2020

@vietj should we be less strict on core? and fix this for 3.9.2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants