fix(dns): answer an own-suffix name with the emulator's address when its stored record has no resolvable target (#9360)

Since #8926 a stored public zone under an emulator suffix answers A and AAAA,
and a public alias to a target Floci does not serve, such as a Cognito custom
domain aliased to CloudFront, got REFUSED, so a container asked public DNS and
got its own loopback address. An A or AAAA standard query for a name under an
emulator suffix that the stored zone refuses is now answered as the emulator's
own name, after the VPC forwarding-rule check. A query with more than one
question, a class other than IN, or a non-standard opcode or flag stays
REFUSED. Closes #9359.
This commit is contained in:
Mario Toffia authored and GitHub committed 2026-11-24 14:42:38 -04:00
1 parent 5b2fa9a30d
commit 398d34239e
4 files changed
+90 -17

No files matched your search

@@ -317,8 +317,9 @@ public class EmbeddedDnsServer {
short qtype = buf.getShort();
short qclass = buf.getShort();
int questionEnd = buf.position();
boolean standardQuery = qdCount == 1 && qclass == 1 && (flags & 0x7840) == 0;
vertx.<QueryPlan>executeBlocking(() -> planQuery(qname, senderHost, myIp, qtype), false)
vertx.<QueryPlan>executeBlocking(() -> planQuery(qname, senderHost, myIp, qtype, standardQuery), false)
.onSuccess(plan -> {
if (plan.answer().isEmpty()) {
if (!plan.ruleTargets().isEmpty()) {
@@ -334,8 +335,7 @@ public class EmbeddedDnsServer {
return;
}
DnsAnswer records = plan.answer().orElseThrow();
if (records.isPublicAuthorityAnswer()
&& (qdCount != 1 || qclass != 1 || (flags & 0x7840) != 0)) {
if (records.isPublicAuthorityAnswer() && !standardQuery) {
records = DnsAnswer.refused();
}
byte[] response = records.isPublicAuthorityAnswer()
@@ -427,6 +427,10 @@ public class EmbeddedDnsServer {
}
}
QueryPlan planQuery(String name, String clientAddress, String myIp, int type) {
return planQuery(name, clientAddress, myIp, type, true);
}
/**
* Stored public authority answers take precedence over broad emulator suffix spoofing.
* Other names the emulator itself owns come first, whatever the rules say. Route 53 Resolver does
@@ -436,9 +440,12 @@ public class EmbeddedDnsServer {
*
* <p>A forwarding rule associated with the querying VPC is then applied before Floci resolves
* the name from a record source, because a Resolver rule takes precedence over a private
* hosted zone that matches the same name.
* hosted zone that matches the same name. An address query under an emulator suffix that the
* stored zone refuses, such as an alias to a target Floci does not serve, is then answered as
* the emulator's own name, unless the packet has a shape the zone refuses on its own: more
* than one question, a class other than IN, or a non-standard opcode or flag.
*/
QueryPlan planQuery(String name, String clientAddress, String myIp, int type) {
QueryPlan planQuery(String name, String clientAddress, String myIp, int type, boolean standardQuery) {
Optional<DnsAnswer> stored = resolveFromRecordSources(name, type, true, myIp);
Optional<DnsAnswer> emulatorName = resolveEmulatorName(name, myIp, type);
if (emulatorName.isPresent() && stored.isEmpty()) {
@@ -450,6 +457,10 @@ public class EmbeddedDnsServer {
if (rule.isPresent() && rule.orElseThrow().forwards()) {
return QueryPlan.forwardingTo(rule.orElseThrow().targets());
}
if (standardQuery && matchesSuffix(name) && (type == 1 || type == 28)
&& stored.filter(answer -> answer.responseCode() == 5).isPresent()) {
return QueryPlan.answering(emulatorName.orElseThrow());
}
return stored.or(() -> resolveFromRecordSources(name, type))
.map(QueryPlan::answering).orElse(QueryPlan.UPSTREAM);
}