From 5cd396e35054ca85da560befb7f08d060154b526 Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Fri, 26 Jun 2026 22:34:13 -0400 Subject: [PATCH] Remove unused BSA native SQL query helper Queries.queryUnblockablesByNames() interpolates domain label and TLD strings directly into a native SQL IN clause, creating a SQL injection surface if ever called with untrusted input. Auditing the codebase and git history confirms this package-private helper has had zero production callers since it was added in PR #2256: DomainsRefresher uses batchReadUnblockables() to inspect each row's reason during refresh, and LabelDiffUpdates queries by label via parameterized JPQL. Removing this dead helper eliminates both the unsafe native SQL pattern and unnecessary maintenance surface; if composite-key lookups on BsaUnblockableDomain are ever needed in the future, tm().loadByKeysIfPresent() with BsaUnblockableDomain.vKey() or a static UNNEST query should be used instead. - Delete Queries.queryUnblockablesByNames() and its now-unused imports. - Delete the corresponding unit tests and setup helper in QueriesTest. BUG=http://b/529387728 --- .../registry/bsa/persistence/Queries.java | 22 ----------- .../registry/bsa/persistence/QueriesTest.java | 37 ------------------- 2 files changed, 59 deletions(-) diff --git a/core/src/main/java/google/registry/bsa/persistence/Queries.java b/core/src/main/java/google/registry/bsa/persistence/Queries.java index d7343e92ded..42ae149dcad 100644 --- a/core/src/main/java/google/registry/bsa/persistence/Queries.java +++ b/core/src/main/java/google/registry/bsa/persistence/Queries.java @@ -14,9 +14,7 @@ package google.registry.bsa.persistence; -import static com.google.common.base.Verify.verify; import static com.google.common.collect.ImmutableList.toImmutableList; -import static google.registry.bsa.BsaStringUtils.DOMAIN_SPLITTER; import static google.registry.bsa.BsaTransactions.bsaQuery; import static google.registry.bsa.persistence.BsaTld.getActivatedBsaTldNames; import static google.registry.model.tld.Tld.isEnrolledWithBsa; @@ -30,9 +28,7 @@ import google.registry.model.tld.Tld; import google.registry.model.tld.Tld.TldType; import java.time.Instant; -import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; /** Helpers for querying BSA JPA entities. */ @@ -128,24 +124,6 @@ static ImmutableList batchReadUnblockables( .getResultList())); } - static ImmutableSet queryUnblockablesByNames(ImmutableSet domains) { - String labelTldParis = - domains.stream() - .map( - domain -> { - List parts = DOMAIN_SPLITTER.splitToList(domain); - verify(parts.size() == 2, "Invalid domain name %s", domain); - return String.format("('%s','%s')", parts.get(0), parts.get(1)); - }) - .collect(Collectors.joining(",")); - String sql = - String.format( - "SELECT CONCAT(d.label, '.', d.tld) FROM \"BsaUnblockableDomain\" d " - + "WHERE (d.label, d.tld) IN (%s)", - labelTldParis); - return ImmutableSet.copyOf(tm().getEntityManager().createNativeQuery(sql).getResultList()); - } - static ImmutableSet queryNewlyCreatedDomains( ImmutableCollection tlds, Instant minCreationTime, Instant now) { return ImmutableSet.copyOf( diff --git a/core/src/test/java/google/registry/bsa/persistence/QueriesTest.java b/core/src/test/java/google/registry/bsa/persistence/QueriesTest.java index 068abd0333a..ae30cbd987f 100644 --- a/core/src/test/java/google/registry/bsa/persistence/QueriesTest.java +++ b/core/src/test/java/google/registry/bsa/persistence/QueriesTest.java @@ -28,7 +28,6 @@ import static google.registry.bsa.persistence.Queries.queryBsaUnblockableDomainByLabels; import static google.registry.bsa.persistence.Queries.queryMissedRegisteredUnblockables; import static google.registry.bsa.persistence.Queries.queryNewlyCreatedDomains; -import static google.registry.bsa.persistence.Queries.queryUnblockablesByNames; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTlds; @@ -42,7 +41,6 @@ import static google.registry.util.DateTimeUtils.plusHours; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import google.registry.bsa.api.UnblockableDomain; import google.registry.bsa.persistence.BsaUnblockableDomain.Reason; import google.registry.bsa.persistence.Queries.DomainLifeSpan; @@ -215,41 +213,6 @@ void deleteBsaLabelByLabels_twoLabels() { .containsExactly(BsaUnblockableDomain.vKey("label3", "app")); } - private void setupUnblockableDomains() { - tm().transact( - () -> - tm().insertAll( - ImmutableList.of( - new BsaLabel("a", fakeClock.now()), - new BsaLabel("b", fakeClock.now())))); - BsaUnblockableDomain a1 = new BsaUnblockableDomain("a", "tld1", Reason.RESERVED); - BsaUnblockableDomain b1 = new BsaUnblockableDomain("b", "tld1", Reason.REGISTERED); - BsaUnblockableDomain a2 = new BsaUnblockableDomain("a", "tld2", Reason.REGISTERED); - tm().transact(() -> tm().insertAll(ImmutableList.of(a1, b1, a2))); - } - - @Test - void queryUnblockablesByNames_singleName_found() { - setupUnblockableDomains(); - assertThat(tm().transact(() -> queryUnblockablesByNames(ImmutableSet.of("a.tld1")))) - .containsExactly("a.tld1"); - } - - @Test - void queryUnblockablesByNames_singleName_notFound() { - setupUnblockableDomains(); - assertThat(tm().transact(() -> queryUnblockablesByNames(ImmutableSet.of("c.tld3")))).isEmpty(); - } - - @Test - void queryUnblockablesByNames_multipleNames() { - setupUnblockableDomains(); - assertThat( - tm().transact( - () -> queryUnblockablesByNames(ImmutableSet.of("a.tld1", "b.tld1", "c.tld3")))) - .containsExactly("a.tld1", "b.tld1"); - } - @Test void queryNewlyCreatedDomains_onlyLiveDomainsReturned() { Instant testStartTime = fakeClock.now();