Skip to content

Commit d7a4369

Browse files
committed
Censor domain authcode by default in tools
When inspecting domain entities with tools like GetDomainCommand, displaying plaintext authentication codes is unnecessary and presents a security risk for credential exposure in logs and bug ticket comments (b/537293980). This commit modifies GetDomainCommand to override printResource, masking any sensitive password strings with [REDACTED] in the output string while preserving entity immutability. An optional --show_authcode flag with arity 1 is introduced to explicitly display authcodes when required for transfer authorization. BUG= http://b/537293980
1 parent a2f0035 commit d7a4369

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

core/src/main/java/google/registry/tools/GetDomainCommand.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.beust.jcommander.Parameter;
2020
import com.beust.jcommander.Parameters;
21+
import google.registry.model.EppResource;
2122
import google.registry.model.ForeignKeyUtils;
2223
import google.registry.model.domain.Domain;
2324
import google.registry.persistence.transaction.QueryComposer.Comparator;
@@ -32,6 +33,12 @@ final class GetDomainCommand extends GetEppResourceCommand {
3233
@Parameter(names = "--show_deleted", description = "Include deleted domains in the print out")
3334
private boolean showDeleted = false;
3435

36+
@Parameter(
37+
names = "--show_authcode",
38+
description = "Include domain authentication code in output",
39+
arity = 1)
40+
private boolean showAuthcode = false;
41+
3542
@Parameter(
3643
description = "Fully qualified domain name(s)",
3744
required = true)
@@ -61,4 +68,22 @@ public void runAndPrint() {
6168
}
6269
}
6370
}
71+
72+
@Override
73+
void printResource(
74+
String resourceType, String uniqueId, Optional<? extends EppResource> resource) {
75+
if (resource.isEmpty() || showAuthcode || !(resource.get() instanceof Domain domain)) {
76+
super.printResource(resourceType, uniqueId, resource);
77+
return;
78+
}
79+
String output = expand ? domain.toHydratedString() : domain.toString();
80+
if (domain.getAuthInfo() != null && domain.getAuthInfo().getPw() != null) {
81+
String secret = domain.getAuthInfo().getPw().getValue();
82+
if (secret != null && !secret.isEmpty()) {
83+
output = output.replace("value=" + secret, "value=[REDACTED]");
84+
}
85+
}
86+
System.out.println(
87+
String.format("%s\n\nWebsafe key: %s", output, domain.createVKey().stringify()));
88+
}
6489
}

core/src/test/java/google/registry/tools/GetDomainCommandTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import static org.junit.jupiter.api.Assertions.assertThrows;
2525

2626
import com.beust.jcommander.ParameterException;
27+
import google.registry.model.domain.DomainAuthInfo;
28+
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
2729
import google.registry.testing.DatabaseHelper;
2830
import org.junit.jupiter.api.BeforeEach;
2931
import org.junit.jupiter.api.Test;
@@ -136,4 +138,28 @@ void testSuccess_printsEntireDomainHistory() throws Exception {
136138
// Deleted
137139
assertInStdout("Websafe key: kind:Domain@sql:rO0ABXQABTMtVExE");
138140
}
141+
142+
@Test
143+
void testSuccess_censorsAuthcodeByDefault() throws Exception {
144+
persistResource(
145+
DatabaseHelper.newDomain("example.tld")
146+
.asBuilder()
147+
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("secret123")))
148+
.build());
149+
runCommand("example.tld");
150+
assertInStdout("value=[REDACTED]");
151+
assertNotInStdout("secret123");
152+
}
153+
154+
@Test
155+
void testSuccess_showAuthcode() throws Exception {
156+
persistResource(
157+
DatabaseHelper.newDomain("example.tld")
158+
.asBuilder()
159+
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("secret123")))
160+
.build());
161+
runCommand("example.tld", "--show_authcode=true");
162+
assertInStdout("value=secret123");
163+
assertNotInStdout("[REDACTED]");
164+
}
139165
}

0 commit comments

Comments
 (0)