Skip to content

Encoded AMQP URI values are not decoded when no port is specified - #52644

Merged
philwebb merged 2 commits into
spring-projects:4.0.xfrom
zhoubiao188:fix-rabbit-uri-decode-without-port
Nov 12, 2026
Merged

philwebb merged 2 commits into
spring-projects:4.0.xfrom
zhoubiao188:fix-rabbit-uri-decode-without-port

Conversation

@zhoubiao188

@zhoubiao188 zhoubiao188 commented Nov 7, 2026 •

Copy link
Copy Markdown

RabbitUri.of only decodes percent-encoded values in the branch that parses an explicit port:

if (colonIndex == -1 || colonIndex < bracketIndex) {
	return new RabbitUri(secure, connection, null, username, password, virtualHost);
}
String host = connection.substring(0, colonIndex);
Integer port = Integer.parseInt(connection.substring(colonIndex + 1));
Assert.state(StringUtils.hasText(host), "Missing RabbitMQ host");
return new RabbitUri(secure, host, port, decode(username), decode(password), decode(virtualHost));

As a result, an address that omits the port (and therefore uses the default one) is not decoded, even though the scheme and port are both optional in an AMQP URI:

RabbitProperties properties = new RabbitProperties();
properties.setAddresses(List.of("amqp://us%3Aer:p%40ss@localhost/my%2Fvhost"));
System.out.println(properties.determineUsername());    // us%3Aer
System.out.println(properties.determinePassword());    // p%40ss
System.out.println(properties.determineVirtualHost()); // my%2Fvhost

Adding :5672 to the same address gives us:er, p@ss and my/vhost, so the connection authenticates only when the port happens to be written out. This is the same failure that #52623 describes, and it also affects the default virtual host written as %2F (amqp://localhost/%2F currently yields the virtual host %2F).

This commit decodes the values right after they have been split off, before the host and port are parsed, so that both paths construct the record with the same values. Splitting still happens on the encoded form, so an encoded @, : or / keeps working as a delimiter and + is still preserved by StringUtils.uriDecode.

Three tests have been added: credentials and virtual host without a port, and the encoded default virtual host
without a port, both of which fail before the change and pass after it, plus + preservation without a port,
which fails if the no-port path ever stops using the same decoder as the other one.

Note for the merge forward: RabbitUri was duplicated on main when the RabbitMQ modules were split, in spring-boot-amqp-rabbitmq and spring-boot-rabbitmq. Both copies contain the same branch and need the same change.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Nov 7, 2026
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Nov 8, 2026
@philwebb philwebb added this to the 4.0.x milestone Nov 8, 2026
@wilkinsona wilkinsona changed the title Decode encoded AMQP URI values when no port is specified Encoded AMQP URI values are not decoded when no port is specified Nov 9, 2026
@philwebb
philwebb force-pushed the fix-rabbit-uri-decode-without-port branch 2 times, most recently from 60ee1fb to 0e1adc0 Compare November 12, 2026 22:11
zhoubiao188 and others added 2 commits November 12, 2026 14:14
Update `RabbitUri` to also decode relevant parts of the URI when
no port is specified.

See spring-projectsgh-52644

Signed-off-by: zhoubiao188 <[email protected]>
@philwebb
philwebb force-pushed the fix-rabbit-uri-decode-without-port branch from 0e1adc0 to 9fe6bea Compare November 12, 2026 22:15
@philwebb philwebb self-assigned this Nov 12, 2026
@philwebb
philwebb merged commit cb47b14 into spring-projects:4.0.x Nov 12, 2026
1 of 2 checks passed
@philwebb philwebb modified the milestones: 4.0.x, 4.0.10 Nov 12, 2026
@philwebb

philwebb commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Thanks @zhoubiao188!

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

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants