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

UriComponent does not encode curly braces #5289

Closed
amarktl opened this issue Mar 23, 2023 · 1 comment · Fixed by #5387
Closed

UriComponent does not encode curly braces #5289

amarktl opened this issue Mar 23, 2023 · 1 comment · Fixed by #5387

Comments

@amarktl
Copy link

amarktl commented Mar 23, 2023

org.glassfish.jersey.uri.UriComponent._encode(String, Type, boolean, boolean) does not encode curly braces properly eg in Query parameters

Example Service

@GET
@Path("/world")
public String sayHelloWorld(@QueryParam("param") String param);

Test

 @Test
    public void testFaultyUrlEncoder() throws Exception {
        SimpleService svc = RSConsumerService.provider.getService().lookup(SimpleService.class);
        svc.sayHelloWorld("faulty {");
    }

Error

java.lang.IllegalStateException: Invalid syntax in the template "param=faulty+{". Check if a path parameter is terminated with a "}".
at org.glassfish.jersey.client.JerseyWebTarget.getUri(JerseyWebTarget.java:113)
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:198)
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:38)
at org.glassfish.jersey.client.proxy.WebResourceFactory.invoke(WebResourceFactory.java:298)
at com.wamas.platform.rest.impl.WamasWebResourceFactory.invoke(WamasWebResourceFactory.java:60)
at jdk.proxy27/jdk.proxy27.$Proxy92.sayHelloWorld(Unknown Source)
at com.wamas.platform.rest.tests.SimpleServiceTest.testFaultyUrlEncoder(SimpleServiceTest.java:140)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at com.wamas.platform.rest.tests.RSServiceRule$1.evaluate(RSServiceRule.java:53)
at com.wamas.platform.rest.tests.RSFrameworkRule$1.evaluate(RSFrameworkRule.java:70)
at com.wamas.platform.test.junit4.rules.ResetLocalServiceProviderRule$1.evaluate(ResetLocalServiceProviderRule.java:24)
at com.wamas.platform.test.junit4.rules.ClearJmsConnectionPoolRule$1.evaluate(ClearJmsConnectionPoolRule.java:24)
at com.wamas.platform.test.junit4.rules.DumpCoverageRule$1.evaluate(DumpCoverageRule.java:65)
at com.wamas.platform.test.junit4.rules.SecurityTestRule$1.evaluate(SecurityTestRule.java:120)
at com.wamas.platform.test.junit4.rules.EmbeddedBrokerRule$1.evaluate(EmbeddedBrokerRule.java:29)
at com.wamas.platform.test.junit4.rules.ClearActiveMQClientThreadPoolRule$1.evaluate(ClearActiveMQClientThreadPoolRule.java:24)
at com.wamas.platform.test.junit4.rules.ShutdownDelegatorRule$1.evaluate(ShutdownDelegatorRule.java:41)
at com.wamas.platform.test.junit4.rules.SystemPropertiesRule$1.evaluate(SystemPropertiesRule.java:34)
at com.wamas.platform.test.junit4.rules.LogThreadsRule$1.evaluate(LogThreadsRule.java:34)
at com.wamas.platform.test.junit4.rules.LogTestMethodsRule$1.evaluate(LogTestMethodsRule.java:35)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at com.wamas.platform.test.junit4.runners.WamasInVMSynchronizer$2.evaluate(WamasInVMSynchronizer.java:58)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: Invalid syntax in the template "param=faulty+{". Check if a path parameter is terminated with a "}".
at org.glassfish.jersey.uri.internal.UriTemplateParser.parse(UriTemplateParser.java:239)
at org.glassfish.jersey.uri.internal.UriTemplateParser.(UriTemplateParser.java:91)
at org.glassfish.jersey.uri.UriTemplate.createUriComponent(UriTemplate.java:980)
at org.glassfish.jersey.uri.UriTemplate.createURIWithStringValues(UriTemplate.java:946)
at org.glassfish.jersey.uri.UriTemplate.createURIWithStringValues(UriTemplate.java:882)
at org.glassfish.jersey.uri.UriTemplate.createURI(UriTemplate.java:847)
at org.glassfish.jersey.uri.internal.JerseyUriBuilder._build(JerseyUriBuilder.java:972)
at org.glassfish.jersey.uri.internal.JerseyUriBuilder.build(JerseyUriBuilder.java:886)
at org.glassfish.jersey.client.JerseyWebTarget.getUri(JerseyWebTarget.java:111)
... 32 more
Caused by: java.util.NoSuchElementException
at org.glassfish.jersey.uri.internal.CharacterIterator.next(CharacterIterator.java:57)
at org.glassfish.jersey.uri.internal.UriTemplateParser.consumeWhiteSpace(UriTemplateParser.java:452)
at org.glassfish.jersey.uri.internal.UriTemplateParser.parseName(UriTemplateParser.java:292)
at org.glassfish.jersey.uri.internal.UriTemplateParser.parse(UriTemplateParser.java:232)
... 40 more

Versions

jersey-proxy-client-2.38.jar
org.glassfish.jersey.core.jersey-common_2.38.0.jar

@jansupol
Copy link
Contributor

This is a bit similar to #5249. The { sign is the template sign and Jersey handles this as being a template.

However, the proxy possibly does not expect a template to be used, as there won't be a way to set the template value, and in this case of a proxy, the argument should never have been treated as a template. This can be fixed by the proxy module.

We should also check the implementation of MP Rest Client to not have the same issue.

@jansupol jansupol linked a pull request Aug 16, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants