Skip to content

Commit 9395785

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 redact sensitive authcodes by default using an in-memory entity builder snapshot while preserving database records. 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 9395785

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.beust.jcommander.Parameters;
2121
import google.registry.model.ForeignKeyUtils;
2222
import google.registry.model.domain.Domain;
23+
import google.registry.model.domain.DomainAuthInfo;
24+
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
2325
import google.registry.persistence.transaction.QueryComposer.Comparator;
2426
import google.registry.util.DomainNameUtils;
2527
import java.util.List;
@@ -32,6 +34,12 @@ final class GetDomainCommand extends GetEppResourceCommand {
3234
@Parameter(names = "--show_deleted", description = "Include deleted domains in the print out")
3335
private boolean showDeleted = false;
3436

37+
@Parameter(
38+
names = "--show_authcode",
39+
description = "Include domain authentication code in output",
40+
arity = 1)
41+
private boolean showAuthcode = false;
42+
3543
@Parameter(
3644
description = "Fully qualified domain name(s)",
3745
required = true)
@@ -51,14 +59,26 @@ public void runAndPrint() {
5159
.stream()
5260
.forEach(
5361
d -> {
54-
printResource("Domain", canonicalDomain, Optional.of(d));
62+
printResource(
63+
"Domain", canonicalDomain, Optional.of(censorAuthcode(d)));
5564
}));
5665
} else {
5766
printResource(
5867
"Domain",
5968
canonicalDomain,
60-
ForeignKeyUtils.loadResource(Domain.class, canonicalDomain, readTimestamp));
69+
ForeignKeyUtils.loadResource(Domain.class, canonicalDomain, readTimestamp)
70+
.map(this::censorAuthcode));
6171
}
6272
}
6373
}
74+
75+
private Domain censorAuthcode(Domain domain) {
76+
if (showAuthcode || domain.getAuthInfo() == null) {
77+
return domain;
78+
}
79+
return domain
80+
.asBuilder()
81+
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("[REDACTED]")))
82+
.build();
83+
}
6484
}

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)