mirror of
https://github.com/google/nomulus
synced 2026-09-21 07:24:26 +00:00
Use custom whois message for bsa-blocked domain (#2241)
* Use custom whois message for bsa-blocked domain
This commit is contained in:
@@ -1044,6 +1044,17 @@ public final class RegistryConfig {
|
||||
return config.registryPolicy.whoisDisclaimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message template for whois response when queried domain is blocked by BSA.
|
||||
*
|
||||
* @see google.registry.whois.WhoisResponse
|
||||
*/
|
||||
@Provides
|
||||
@Config("domainBlockedByBsaTemplate")
|
||||
public static String provideDomainBlockedByBsaTemplate(RegistryConfigSettings config) {
|
||||
return config.registryPolicy.domainBlockedByBsaTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum QPS for the Google Cloud Monitoring V3 (aka Stackdriver) API. The QPS limit can be
|
||||
* adjusted by contacting Cloud Support.
|
||||
|
||||
@@ -105,6 +105,7 @@ public class RegistryConfigSettings {
|
||||
public String reservedTermsExportDisclaimer;
|
||||
public String whoisRedactedEmailText;
|
||||
public String whoisDisclaimer;
|
||||
public String domainBlockedByBsaTemplate;
|
||||
public String rdapTos;
|
||||
public String rdapTosStaticUrl;
|
||||
public String registryName;
|
||||
|
||||
@@ -130,6 +130,12 @@ registryPolicy:
|
||||
unlawful behavior. We reserve the right to restrict or deny your access to
|
||||
the WHOIS database, and may modify these terms at any time.
|
||||
|
||||
# BSA blocked domain name template.
|
||||
domainBlockedByBsaTemplate: |
|
||||
Domain Name: %s
|
||||
>>> This name is not available for registration.
|
||||
>>> This name has been blocked by a GlobalBlock service.
|
||||
|
||||
# RDAP Terms of Service text displayed at the /rdap/help/tos endpoint.
|
||||
rdapTos: >
|
||||
By querying our Domain Database as part of the RDAP pilot program (RDAP
|
||||
|
||||
@@ -269,11 +269,15 @@ public class DomainFlowUtils {
|
||||
*/
|
||||
public static void verifyNotBlockedByBsa(String domainLabel, Tld tld, DateTime now)
|
||||
throws DomainLabelBlockedByBsaException {
|
||||
if (isEnrolledWithBsa(tld, now) && isLabelBlocked(domainLabel)) {
|
||||
if (isBlockedByBsa(domainLabel, tld, now)) {
|
||||
throw new DomainLabelBlockedByBsaException();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBlockedByBsa(String domainLabel, Tld tld, DateTime now) {
|
||||
return isEnrolledWithBsa(tld, now) && isLabelBlocked(domainLabel);
|
||||
}
|
||||
|
||||
/** Returns whether a given domain create request is for a valid anchor tenant. */
|
||||
public static boolean isAnchorTenant(
|
||||
InternetDomainName domainName,
|
||||
|
||||
@@ -14,34 +14,84 @@
|
||||
|
||||
package google.registry.whois;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.isBlockedByBsa;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
|
||||
import static google.registry.model.tld.Tlds.findTldForName;
|
||||
import static google.registry.model.tld.Tlds.getTlds;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Verify;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.tld.Tld;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Represents a WHOIS lookup on a domain name (i.e. SLD). */
|
||||
public class DomainLookupCommand extends DomainOrHostLookupCommand {
|
||||
public class DomainLookupCommand implements WhoisCommand {
|
||||
|
||||
private static final String ERROR_PREFIX = "Domain";
|
||||
|
||||
@VisibleForTesting final InternetDomainName domainName;
|
||||
|
||||
private final boolean fullOutput;
|
||||
private final boolean cached;
|
||||
private final String whoisRedactedEmailText;
|
||||
private final String domainBlockedByBsaTemplate;
|
||||
|
||||
public DomainLookupCommand(
|
||||
InternetDomainName domainName,
|
||||
boolean fullOutput,
|
||||
boolean cached,
|
||||
String whoisRedactedEmailText) {
|
||||
super(domainName, "Domain");
|
||||
String whoisRedactedEmailText,
|
||||
String domainBlockedByBsaTemplate) {
|
||||
this.domainName = checkNotNull(domainName, "domainOrHostName");
|
||||
this.fullOutput = fullOutput;
|
||||
this.cached = cached;
|
||||
this.whoisRedactedEmailText = whoisRedactedEmailText;
|
||||
this.domainBlockedByBsaTemplate = domainBlockedByBsaTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<WhoisResponse> getResponse(InternetDomainName domainName, DateTime now) {
|
||||
public final WhoisResponse executeQuery(final DateTime now) throws WhoisException {
|
||||
Optional<InternetDomainName> tld = findTldForName(domainName);
|
||||
// Google Registry Policy: Do not return records under TLDs for which we're not
|
||||
// authoritative.
|
||||
if (!tld.isPresent() || !getTlds().contains(tld.get().toString())) {
|
||||
throw new WhoisException(now, SC_NOT_FOUND, ERROR_PREFIX + " not found.");
|
||||
}
|
||||
// Include `getResponse` and `isBlockedByBsa` in one transaction to reduce latency.
|
||||
// Must pass the exceptions outside to throw.
|
||||
ResponseOrException result =
|
||||
tm().transact(
|
||||
() -> {
|
||||
final Optional<WhoisResponse> response = getResponse(domainName, now);
|
||||
if (response.isPresent()) {
|
||||
return ResponseOrException.of(response.get());
|
||||
}
|
||||
|
||||
String label = domainName.parts().get(0);
|
||||
String tldStr = tld.get().toString();
|
||||
if (isBlockedByBsa(label, Tld.get(tldStr), now)) {
|
||||
return ResponseOrException.of(
|
||||
new WhoisException(
|
||||
now,
|
||||
SC_NOT_FOUND,
|
||||
String.format(domainBlockedByBsaTemplate, domainName)));
|
||||
}
|
||||
|
||||
return ResponseOrException.of(
|
||||
new WhoisException(now, SC_NOT_FOUND, ERROR_PREFIX + " not found."));
|
||||
});
|
||||
return result.returnOrThrow();
|
||||
}
|
||||
|
||||
private Optional<WhoisResponse> getResponse(InternetDomainName domainName, DateTime now) {
|
||||
Optional<Domain> domainResource =
|
||||
cached
|
||||
? loadByForeignKeyCached(Domain.class, domainName.toString(), now)
|
||||
@@ -49,4 +99,29 @@ public class DomainLookupCommand extends DomainOrHostLookupCommand {
|
||||
return domainResource.map(
|
||||
domain -> new DomainWhoisResponse(domain, fullOutput, whoisRedactedEmailText, now));
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
abstract static class ResponseOrException {
|
||||
|
||||
abstract Optional<WhoisResponse> whoisResponse();
|
||||
|
||||
abstract Optional<WhoisException> exception();
|
||||
|
||||
WhoisResponse returnOrThrow() throws WhoisException {
|
||||
Verify.verify(
|
||||
whoisResponse().isPresent() || exception().isPresent(),
|
||||
"Response and exception must not both be missing.");
|
||||
return whoisResponse().orElseThrow(() -> exception().get());
|
||||
}
|
||||
|
||||
static ResponseOrException of(WhoisResponse response) {
|
||||
return new AutoValue_DomainLookupCommand_ResponseOrException(
|
||||
Optional.of(response), Optional.empty());
|
||||
}
|
||||
|
||||
static ResponseOrException of(WhoisException exception) {
|
||||
return new AutoValue_DomainLookupCommand_ResponseOrException(
|
||||
Optional.empty(), Optional.of(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.whois;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static google.registry.model.tld.Tlds.findTldForName;
|
||||
import static google.registry.model.tld.Tlds.getTlds;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Represents a WHOIS lookup on a domain name (i.e. SLD) or a nameserver. */
|
||||
public abstract class DomainOrHostLookupCommand implements WhoisCommand {
|
||||
|
||||
@VisibleForTesting final InternetDomainName domainOrHostName;
|
||||
|
||||
private final String errorPrefix;
|
||||
|
||||
DomainOrHostLookupCommand(InternetDomainName domainName, String errorPrefix) {
|
||||
this.errorPrefix = errorPrefix;
|
||||
this.domainOrHostName = checkNotNull(domainName, "domainOrHostName");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final WhoisResponse executeQuery(final DateTime now) throws WhoisException {
|
||||
Optional<InternetDomainName> tld = findTldForName(domainOrHostName);
|
||||
// Google Registry Policy: Do not return records under TLDs for which we're not authoritative.
|
||||
if (tld.isPresent() && getTlds().contains(tld.get().toString())) {
|
||||
final Optional<WhoisResponse> response = getResponse(domainOrHostName, now);
|
||||
if (response.isPresent()) {
|
||||
return response.get();
|
||||
}
|
||||
}
|
||||
throw new WhoisException(now, SC_NOT_FOUND, errorPrefix + " not found.");
|
||||
}
|
||||
|
||||
/** Renders a response record, provided its successfully retrieved entity. */
|
||||
protected abstract Optional<WhoisResponse> getResponse(
|
||||
InternetDomainName domainName, DateTime now);
|
||||
}
|
||||
@@ -14,26 +14,47 @@
|
||||
|
||||
package google.registry.whois;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
|
||||
import static google.registry.model.tld.Tlds.findTldForName;
|
||||
import static google.registry.model.tld.Tlds.getTlds;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import google.registry.model.host.Host;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Represents a WHOIS lookup on a nameserver based on its hostname. */
|
||||
public class NameserverLookupByHostCommand extends DomainOrHostLookupCommand {
|
||||
public class NameserverLookupByHostCommand implements WhoisCommand {
|
||||
|
||||
private static final String ERROR_PREFIX = "Nameserver";
|
||||
|
||||
@VisibleForTesting final InternetDomainName hostName;
|
||||
|
||||
boolean cached;
|
||||
|
||||
NameserverLookupByHostCommand(InternetDomainName hostName, boolean cached) {
|
||||
super(hostName, "Nameserver");
|
||||
this.hostName = checkNotNull(hostName, "hostName");
|
||||
this.cached = cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<WhoisResponse> getResponse(InternetDomainName hostName, DateTime now) {
|
||||
public final WhoisResponse executeQuery(final DateTime now) throws WhoisException {
|
||||
Optional<InternetDomainName> tld = findTldForName(hostName);
|
||||
// Google Registry Policy: Do not return records under TLDs for which we're not authoritative.
|
||||
if (tld.isPresent() && getTlds().contains(tld.get().toString())) {
|
||||
final Optional<WhoisResponse> response = getResponse(hostName, now);
|
||||
if (response.isPresent()) {
|
||||
return response.get();
|
||||
}
|
||||
}
|
||||
throw new WhoisException(now, SC_NOT_FOUND, ERROR_PREFIX + " not found.");
|
||||
}
|
||||
|
||||
private Optional<WhoisResponse> getResponse(InternetDomainName hostName, DateTime now) {
|
||||
Optional<Host> host =
|
||||
cached
|
||||
? loadByForeignKeyCached(Host.class, hostName.toString(), now)
|
||||
|
||||
@@ -48,8 +48,12 @@ public class WhoisCommandFactory {
|
||||
|
||||
/** Returns a new {@link WhoisCommand} to perform a domain lookup on the specified domain name. */
|
||||
public WhoisCommand domainLookup(
|
||||
InternetDomainName domainName, boolean fullOutput, String whoisRedactedEmailText) {
|
||||
return new DomainLookupCommand(domainName, fullOutput, cached, whoisRedactedEmailText);
|
||||
InternetDomainName domainName,
|
||||
boolean fullOutput,
|
||||
String whoisRedactedEmailText,
|
||||
String domainBlockedByBsaTemplate) {
|
||||
return new DomainLookupCommand(
|
||||
domainName, fullOutput, cached, whoisRedactedEmailText, domainBlockedByBsaTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,14 +75,17 @@ class WhoisReader {
|
||||
|
||||
private final WhoisCommandFactory commandFactory;
|
||||
private final String whoisRedactedEmailText;
|
||||
private final String domainBlockedByBsaTemplate;
|
||||
|
||||
/** Creates a new WhoisReader that extracts its command from the specified Reader. */
|
||||
@Inject
|
||||
WhoisReader(
|
||||
@Config("whoisCommandFactory") WhoisCommandFactory commandFactory,
|
||||
@Config("whoisRedactedEmailText") String whoisRedactedEmailText) {
|
||||
@Config("whoisRedactedEmailText") String whoisRedactedEmailText,
|
||||
@Config("domainBlockedByBsaTemplate") String domainBlockedByBsaTemplate) {
|
||||
this.commandFactory = commandFactory;
|
||||
this.whoisRedactedEmailText = whoisRedactedEmailText;
|
||||
this.domainBlockedByBsaTemplate = domainBlockedByBsaTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +127,8 @@ class WhoisReader {
|
||||
return commandFactory.domainLookup(
|
||||
InternetDomainName.from(canonicalizeHostname(tokens.get(1))),
|
||||
fullOutput,
|
||||
whoisRedactedEmailText);
|
||||
whoisRedactedEmailText,
|
||||
domainBlockedByBsaTemplate);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// If we can't interpret the argument as a host name, then return an error.
|
||||
throw new WhoisException(now, SC_BAD_REQUEST, String.format(
|
||||
@@ -202,7 +206,8 @@ class WhoisReader {
|
||||
// (SLD) and we should do a domain lookup on it.
|
||||
if (targetName.parent().equals(tld.get())) {
|
||||
logger.atInfo().log("Attempting domain lookup using %s as a domain name.", targetName);
|
||||
return commandFactory.domainLookup(targetName, fullOutput, whoisRedactedEmailText);
|
||||
return commandFactory.domainLookup(
|
||||
targetName, fullOutput, whoisRedactedEmailText, domainBlockedByBsaTemplate);
|
||||
}
|
||||
|
||||
// The target is more than one level above the TLD, so we'll assume it's a nameserver.
|
||||
|
||||
Reference in New Issue
Block a user