Skip to content

Authentication fails when password configured in spring.elasticsearch.uris contains a colon - #52047

Merged
snicoll merged 1 commit into
spring-projects:4.0.xfrom
lavinhoque33:fix/elasticsearch-uri-password-colon
Oct 12, 2026
Merged

snicoll merged 1 commit into
spring-projects:4.0.xfrom
lavinhoque33:fix/elasticsearch-uri-password-colon

Conversation

@lavinhoque33

Copy link
Copy Markdown
Contributor

When spring.elasticsearch.uris contains user info, PropertiesElasticsearchConnectionDetails splits it on every : and keeps only the first two parts. A password that contains a colon is therefore truncated: with http://user:pass:with:colons@localhost:9200, the REST client is configured with password pass and authentication fails.

The user info is now split at the first colon only, and everything after it is the password. This matches createUserInfoCredentials in the same class, and RFC 3986, where the user name is everything before the first colon. URIs with no password (user@) or an empty one (user:@) behave as before.

Tests: configureUriWithUsernameAndPasswordContainingColons in ElasticsearchRestClientAutoConfigurationTests checks the credentials registered for the node on the Rest5Client. Without the change it fails with Expecting actual: ['p', 'a', 's', 's'] to contain exactly ... ['p', 'a', 's', 's', ':', 'w', 'i', 't', 'h', ...].

checkFormat and checkstyle pass for the module.

@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 Oct 7, 2026
@wilkinsona wilkinsona changed the title Preserve colons in Elasticsearch URI passwords Authentication fails when password configured in spring.elastchsearch.uris contains a colon Oct 7, 2026
@wilkinsona wilkinsona 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 Oct 7, 2026
@wilkinsona wilkinsona added this to the 4.0.x milestone Oct 7, 2026
@wilkinsona wilkinsona changed the title Authentication fails when password configured in spring.elastchsearch.uris contains a colon Authentication fails when password configured in spring.elasticsearch.uris contains a colon Oct 7, 2026
@snicoll snicoll self-assigned this Oct 12, 2026
@snicoll snicoll modified the milestones: 4.0.x, 4.0.9 Oct 12, 2026
@snicoll
snicoll force-pushed the fix/elasticsearch-uri-password-colon branch from 51ab3e6 to bc7b3d1 Compare October 12, 2026 13:06
PropertiesElasticsearchConnectionDetails split the URI user info on
every colon and only used the first two components, so a password such
as 'pass:with:colon' was truncated to 'pass'.

Split the user info at the first colon only, keeping the remainder as
the password, which is consistent with how the credentials provider
already handles user info.

See spring-projectsgh-52047

Signed-off-by: lavinhoque33 <caspianprince33@yahoo.com>
@snicoll
snicoll force-pushed the fix/elasticsearch-uri-password-colon branch from bc7b3d1 to 006d6d5 Compare October 12, 2026 13:07
@snicoll
snicoll merged commit 0a6c6b9 into spring-projects:4.0.x Oct 12, 2026
2 checks passed
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.

4 participants