Skip to content

Enforce registrar ownership in bulk domain action - #3287

Open
CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:bulk-domain-registrar-ownership
Open

CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:bulk-domain-registrar-ownership

Conversation

@CydeWeys

@CydeWeys CydeWeys commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

ConsoleBulkDomainAction (/console-api/bulk-domain) executes EPP commands with isSuperuser = user.getUserRoles().isAdmin(), which bypasses EPP's verifyResourceOwnership check in DomainDeleteFlow and DomainUpdateFlow. As a result, a bulk delete, suspend, or unsuspend request tagged with registrarId = B can mutate domains sponsored by registrar A when submitted by an admin (for example, during a UI registrar-switch race).

Other Console mutation endpoints already enforce server-side registrar scoping (ConsoleUsersAction.validateUserRegistrarAssociation, ContactAction, and DomainLockUtils.getDomain).

Changes

  • For each target domain, load the active domain via ForeignKeyUtils.loadResource inside the same per-domain tm().transact(...) block that FlowRunner enlists in so ownership is verified atomically at the flow's transaction timestamp (eliminating TOCTOU races with concurrent transfers or registrations).
  • Return a per-domain EPP 2201 (AUTHORIZATION_ERROR) without invoking EPP or recording ConsoleUpdateHistory for any domain whose currentSponsorRegistrarId does not match the request's registrarId.
  • For nonexistent or deleted domains, invoke EPP with isSuperuser = false to preserve existing EPP 2303 behavior without superuser fallthrough.
  • Reject null domain list or null entries upfront with HTTP 400 (IllegalArgumentException), and deduplicate domainList (preserving order) after the size limit check so duplicates never execute EPP twice or fail in toImmutableMap after mutating the DB.
  • Add unit tests in ConsoleBulkDomainActionTest covering admin cross-registrar DELETE, admin cross-registrar SUSPEND, mixed batches, duplicate domains, null list entries, nonexistent/deleted domains, and expired pending transfers projected to another registrar.

BUG= http://b/588464773


This change is Reviewable

@CydeWeys
CydeWeys requested a review from ptkach November 20, 2026 19:40
Comment on lines +108 to +110
// Admin requests execute EPP with isSuperuser=true, which bypasses EPP's own
// verifyResourceOwnership check. Load active domains up front so we always enforce that
// each target domain is sponsored by the request's registrarId.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross-PR conflict & semantic drift with #3278:

Comment on lines +117 to +121
ImmutableMap<String, ConsoleEppOutput> result =
domainList.domainList.stream()
.collect(
toImmutableMap(d -> d, d -> executeEpp(actionType.getXmlContentsToRun(d), user)));
toImmutableMap(
d -> d, d -> executeIfOwned(d, activeDomains.get(d), actionType, user)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If domainList.domainList contains duplicate domain names (e.g., ["example.tld", "example.tld"]), ForeignKeyUtils.loadResources succeeds (SQL IN + GROUP BY deduplicates), executeIfOwned executes EPP twice (committing the mutation in the DB), and then .collect(toImmutableMap(...)) throws IllegalArgumentException: Multiple entries with same key—returning HTTP 400 after mutating the domain and skipping handleHistoryAdditions (leaving no ConsoleUpdateHistory audit entry).

Also, if domainList.domainList contains null, activeDomains.get(null) throws NullPointerException (ImmutableMap.get(null)), returning HTTP 500 instead of 400.

Comment on lines +128 to +136
private ConsoleEppOutput executeIfOwned(
String domainName, @Nullable Domain domain, ConsoleDomainActionType actionType, User user) {
if (domain != null && !domain.getCurrentSponsorRegistrarId().equals(registrarId)) {
return new ConsoleEppOutput(
String.format("Domain %s is not owned by registrar %s", domainName, registrarId),
Result.Code.AUTHORIZATION_ERROR.code);
}
return executeEpp(actionType.getXmlContentsToRun(domainName), user);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOCTOU window between upfront loadResources transaction and per-domain EPP transactions:
activeDomains is loaded once in a standalone transaction for up to consoleBulkDomainActionLimit (500) domains, and then each executeEpp runs sequentially in its own transaction with isSuperuser = true:

  1. domain == null superuser fallthrough: Because domain == null falls through to superuser executeEpp (to preserve 2303), if a domain did not exist at the upfront load timestamp but is registered/restored by another registrar before the batch reaches it, executeEpp runs with isSuperuser = true and mutates/deletes the other registrar's domain. Passing isSuperuser = false when domain == null still preserves 2303 while closing this gap.
  2. Concurrent transfer completion: If a domain's PENDING_TRANSFER expires (implicit server approval) or is approved between the upfront loadResources transaction and its executeEpp transaction, DomainUpdateFlow/DomainDeleteFlow projects the domain at the later transaction time and mutates the gaining registrar's domain as superuser.

.containsNoneIn(serverSuspensionStatuses);
ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get();
assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_SUSPEND);
assertThat(history.getDescription()).hasValue("example.tld");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up when rebasing with #3278: #3278 prefixes ConsoleUpdateHistory descriptions with <registrarId>|, so this assertion will fail unless updated to "TheRegistrar|example.tld".

ConsoleBulkDomainAction executes EPP commands with isSuperuser=true for
admin users, which bypasses EPP's verifyResourceOwnership check in
DomainDeleteFlow and DomainUpdateFlow. As a result, a bulk delete,
suspend, or unsuspend request tagged with registrarId=B could mutate
domains sponsored by registrar A when submitted by an admin (e.g. during
a UI registrar switch race).

For each target domain, load the active domain via
ForeignKeyUtils.loadResource inside the same transaction that the EPP
flow enlists in so ownership is verified atomically at the flow's
transaction timestamp (eliminating TOCTOU races with concurrent
transfers or registrations). Return an EPP 2201 authorization error
without running EPP or recording ConsoleUpdateHistory when the domain's
current sponsor does not match registrarId. For nonexistent or deleted
domains, invoke EPP with isSuperuser=false to preserve existing 2303
behavior without superuser fallthrough.

Also reject null entries in domainList with HTTP 400 and deduplicate
domainList (preserving order) before execution so duplicate entries do
not execute EPP twice or fail in toImmutableMap after mutating the DB.

Add unit tests covering admin cross-registrar delete, suspend, mixed
batches, duplicate domains, null list entries, nonexistent/deleted
domains, and expired pending transfers projected to another registrar.

BUG= http://b/588464773
@CydeWeys
CydeWeys force-pushed the bulk-domain-registrar-ownership branch from b2acea4 to 5db581b Compare November 22, 2026 18:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants