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

[JerseyWebTarget] QueryParam not complete encoded #5249

Open
CallMeFlanby opened this issue Feb 2, 2023 · 6 comments
Open

[JerseyWebTarget] QueryParam not complete encoded #5249

CallMeFlanby opened this issue Feb 2, 2023 · 6 comments

Comments

@CallMeFlanby
Copy link

Hello,

I have to report that I noticed that the WebTarget from Jersey Client (Version 2.37) is not encoding query parameters correctly.
We are using it to send a password and that is how we noticed, that something is happening. Currently, we encode the password before we set it as query parameters.

An exception is also thrown:
java.lang.IllegalArgumentException: Illegal character ";" at position 76 is not allowed as a part of a name in a path template "UserLogin=(MYLOGIN)&Password=%C3%98%C3%92%C3%8C%C3%A9%C2%A2%C3%A2%5Bi{ùÁe;ª3jË6ð1nLB/X¢.
Please notice that (MYLOGIN) is not the correct UserLogin and the correct UserLogin was replaced in order to post this issue.

Example:

  • Plain password:
    ØÒÌé¢â[i{ùÁe;ª3jË6ð1nLB/X¢
  • From JettyWebTarget encoded:
    %C3%98%C3%92%C3%8C%C3%A9%C2%A2%C3%A2%5Bi{ùÁe;ª3jË6ð1nLB/X¢
  • From Java URLEncoder with StandardCharsets UTF8:
    %C3%98%C3%92%C3%8C%C3%A9%C2%A2%C3%A2%5Bi%7B%C3%B9%C3%81e%3B%C2%AA3j%C3%8B6%C3%B01nLB%2FX%C2%A2

As you see, JettyWebTarget is not encoding the query parameter to 100%.

Please check and let me know if this issue was not opened in the correct forum. I also searched, but could not find another issue related to this problem.

Best regards

@CallMeFlanby CallMeFlanby changed the title [JerseyWebTarget] QueryParam not complete encoded - Jersey Client 2.37 [JerseyWebTarget] QueryParam not complete encoded Feb 10, 2023
@CallMeFlanby
Copy link
Author

Do you have new info?

@jansupol
Copy link
Contributor

jansupol commented Jul 4, 2023

Related #5289, #5269.
WIP

@CallMeFlanby
Copy link
Author

Related #5289, #5269. WIP

Thanks for your reply. I do see my issue is older than those two but at least #5269 has more comments. Should I close this issue then? Or should it rather be left open?

@jansupol
Copy link
Contributor

The actual problem is the { symbol. The symbols say the template parameter starts, and the next string ùÁe is an acceptable name, but the semicolon is not an acceptable part of the name in the template variable.

Now there are two options.

  • One option is to continue parsing and check whether there is an end of the template '}` and if so, throw the exception, otherwise, think of it as not a template and properly percent encode.
  • The second option, used by Jersey is to inform the user that there is an illegal name, or in the case the name was legal, to inform the } symbol is missing.

The first approach brings additional complexity and open questions.

  • What if more { symbols occur? Are all of them non-template symbols, or is any of them a template symbol?

@jansupol
Copy link
Contributor

jansupol commented Jul 25, 2023

What exactly is the Jersey code you use?

@CallMeFlanby
Copy link
Author

What exactly is the Jersey code you use?

This was our code:

    private final WebTarget target = ClientBuilder.newBuilder()
            .withConfig(new ClientConfig().register(JacksonJaxbJsonProvider.class))
            .build()
            .target(URI.create(otrsPaths.mainPath()));
        var req = target
            .path(otrsPaths.sessionPath())
            .queryParam(OTRSUserLogin, username)
            .queryParam(OTRSPass, URLEncoder.encode(password, StandardCharsets.UTF_8));

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

No branches or pull requests

2 participants