hivemq-mqtt-client icon indicating copy to clipboard operation
hivemq-mqtt-client copied to clipboard

Pre-encoded query string is decoded

Open jpg0 opened this issue 1 year ago • 1 comments

🐛 Bug Report

Currently it's not possible to connect with a URL that contains a %2F (for example). This will always be decoded to '/'.

🔬 How To Reproduce

Pass in a query string with a %2F: .webSocketConfig(MqttClientWebSocketConfig.builder().uri("wss://foo/path?query%2Fstring"))

The problem

AWS IOT Signature v4 expects this escaping and appears to require it. The JDK URLEncoder class seems to think it's not necessary. This is currently blocking me from being able to connect to an AWS endpoint - the reason being that the passed in URI is copied into and out of a URI class (which decodes, then doesn't re-encode the characters). Paho, for example, does not do this and instead leaves the String as-is, hence can connect fine.

jpg0 avatar Nov 02 '24 03:11 jpg0

@Donnerbart sorry for tagging you directly, but hope to get some insight in the feasability of a fix. The current behavior prevents us from using HiveMQ as alternative to the (bloated) Amazon SDK.

lsiepel avatar Dec 18 '24 17:12 lsiepel

To add an explicit test case; the following is how the query string is handled. Note that it is impossible to have a %2F in the query string processed by Netty.

import java.net.URI;

class Main {
    public static void main(String[] args) throws Exception {
        String input = "x/y";
        URI uri = new URI(
            "wss", null, "host", 8080, "/test", input, null);
            
        //Try to output: x%2Fy
        System.out.println(uri.getRawQuery());
    }
}

jpg0 avatar Aug 15 '25 06:08 jpg0

@jpg0 Are we able to come up with a PR? This might speed up a fix. Maybe default to curent behaviour and introduce a setting or overload or something to apply the correct behaviour?

lsiepel avatar Aug 23 '25 08:08 lsiepel