Skip to content

Commit 2b6af84

Browse files
committed
Merge pull request #45290 from nosan
* pr/45290: Trim "\x00" from a decoded Docker Registry password Closes gh-45290
2 parents 4531d9e + e69de96 commit 2b6af84

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerConfigurationMetadata.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ static final class Auth extends MappedObject {
219219
Auth(JsonNode node) {
220220
super(node, MethodHandles.lookup());
221221
String auth = valueAt("/auth", String.class);
222-
if (StringUtils.hasText(auth)) {
222+
if (StringUtils.hasLength(auth)) {
223223
String[] parts = new String(Base64.getDecoder().decode(auth)).split(":", 2);
224224
Assert.state(parts.length == 2, "Malformed auth in docker configuration metadata");
225225
this.username = parts[0];
226-
this.password = parts[1];
226+
this.password = trim(parts[1], Character.MIN_VALUE);
227227
}
228228
else {
229229
this.username = valueAt("/username", String.class);
@@ -244,6 +244,11 @@ String getEmail() {
244244
return this.email;
245245
}
246246

247+
private static String trim(String source, char character) {
248+
source = StringUtils.trimLeadingCharacter(source, character);
249+
return StringUtils.trimTrailingCharacter(source, character);
250+
}
251+
247252
}
248253

249254
static final class DockerContext extends MappedObject {

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerConfigurationMetadataTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void configWithAuthIsRead() throws Exception {
125125
.containsEntry("gcr.io", "gcr");
126126
assertThat(configuration.getAuths()).hasSize(3).hasEntrySatisfying("https://index.docker.io/v1/", (auth) -> {
127127
assertThat(auth.getUsername()).isEqualTo("username");
128-
assertThat(auth.getPassword()).isEqualTo("password");
128+
assertThat(auth.getPassword()).isEqualTo("pass\u0000word");
129129
assertThat(auth.getEmail()).isEqualTo("[email protected]");
130130
}).hasEntrySatisfying("custom-registry.example.com", (auth) -> {
131131
assertThat(auth.getUsername()).isEqualTo("customUser");

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/configuration/with-auth/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"auths": {
33
"https://index.docker.io/v1/": {
4-
"auth": "dXNlcm5hbWU6cGFzc3dvcmQ=",
4+
"auth": "dXNlcm5hbWU6AABwYXNzAHdvcmQAAA==",
55
"email": "[email protected]"
66
},
77
"custom-registry.example.com": {

0 commit comments

Comments
 (0)