ditto icon indicating copy to clipboard operation
ditto copied to clipboard

Basic auth in (mqtt) connection requires you to encode the username and password twice

Open BobClaerhout opened this issue 4 years ago • 4 comments

We upgraded from ditto 1.1.0 to 2.1.0 (big update I know) and somewhere in between the URI format for connections changed. Say you're using following configuration options:

  • host: my-host
  • port: 8883
  • username: "username"
  • password: "my password with spaces" Previously when you configured a URI you had to urlEncode the username and password: username:my%20password%20with%20spaces@my-host:8883

Right now, you have to configure the URI with double urlEncoded username and password: username:my%2520password%2520with%2520spaces@my-host:8883

thanks @thjaeckle for you support on this!

If you know this is required, you can do this but this is not documented somewhere. Besides the missing documentation this feels a bit weird and looks a bit ugly.

BobClaerhout avatar Sep 29 '21 14:09 BobClaerhout

Hey there, I'd like to work on this, if I may. Where would I look to get started with this?

marcluque avatar Oct 04 '21 16:10 marcluque

Hi @marcluque I would start looking at org.eclipse.ditto.connectivity.service.messaging.mqtt.hivemq.AbstractHiveMqttClientFactory.configureSimpleAuth() - that's where the password is passed into the used HiveMQ MQTT client. Maybe HiveMQ MQTT client needs the password URL encoded when there are spaces in it.

Could however also be that the password is URL decoded before it reaches this place.

Another suspicious place is org.eclipse.ditto.connectivity.model.ImmutableConnection$ConnectionUri.tryDecodeUriComponent(String) where the password is URL decoded when being read from the URI string.

thjaeckle avatar Oct 05 '21 06:10 thjaeckle

So I changed our business application to double url encode all usernames and password for connections. However, I noticed this is not required for http connections... I'm going for the assumption that this is only required for mqtt connections now.

BobClaerhout avatar Oct 05 '21 06:10 BobClaerhout

This issue should be fixed with #1407 and #1424 Can you confirm that @Yannic92 ?

thjaeckle avatar Aug 02 '22 09:08 thjaeckle

Yes, passwords should now work with single encoding everywhere.

Yannic92 avatar Sep 02 '22 05:09 Yannic92