Merge pull request #45290 from nosan
* pr/45290: Trim "\x00" from a decoded Docker Registry password Closes gh-45290
This commit is contained in:
commit
2b6af84ae8
|
@ -219,11 +219,11 @@ final class DockerConfigurationMetadata {
|
|||
Auth(JsonNode node) {
|
||||
super(node, MethodHandles.lookup());
|
||||
String auth = valueAt("/auth", String.class);
|
||||
if (StringUtils.hasText(auth)) {
|
||||
if (StringUtils.hasLength(auth)) {
|
||||
String[] parts = new String(Base64.getDecoder().decode(auth)).split(":", 2);
|
||||
Assert.state(parts.length == 2, "Malformed auth in docker configuration metadata");
|
||||
this.username = parts[0];
|
||||
this.password = parts[1];
|
||||
this.password = trim(parts[1], Character.MIN_VALUE);
|
||||
}
|
||||
else {
|
||||
this.username = valueAt("/username", String.class);
|
||||
|
@ -244,6 +244,11 @@ final class DockerConfigurationMetadata {
|
|||
return this.email;
|
||||
}
|
||||
|
||||
private static String trim(String source, char character) {
|
||||
source = StringUtils.trimLeadingCharacter(source, character);
|
||||
return StringUtils.trimTrailingCharacter(source, character);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final class DockerContext extends MappedObject {
|
||||
|
|
|
@ -125,7 +125,7 @@ class DockerConfigurationMetadataTests extends AbstractJsonTests {
|
|||
.containsEntry("gcr.io", "gcr");
|
||||
assertThat(configuration.getAuths()).hasSize(3).hasEntrySatisfying("https://index.docker.io/v1/", (auth) -> {
|
||||
assertThat(auth.getUsername()).isEqualTo("username");
|
||||
assertThat(auth.getPassword()).isEqualTo("password");
|
||||
assertThat(auth.getPassword()).isEqualTo("pass\u0000word");
|
||||
assertThat(auth.getEmail()).isEqualTo("test@gmail.com");
|
||||
}).hasEntrySatisfying("custom-registry.example.com", (auth) -> {
|
||||
assertThat(auth.getUsername()).isEqualTo("customUser");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"auths": {
|
||||
"https://index.docker.io/v1/": {
|
||||
"auth": "dXNlcm5hbWU6cGFzc3dvcmQ=",
|
||||
"auth": "dXNlcm5hbWU6AABwYXNzAHdvcmQAAA==",
|
||||
"email": "test@gmail.com"
|
||||
},
|
||||
"custom-registry.example.com": {
|
||||
|
|
Loading…
Reference in New Issue