mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(route53): reject record sets outside the hosted zone (#6412)
* fix(route53): reject record sets outside the hosted zone ChangeResourceRecordSets fails with InvalidChangeBatch when a record set's name is neither the zone's name nor a name under it, comparing names without regard to case or a trailing dot. Wildcard names under the zone still pass. * fix(route53): match zone names with ASCII folding and accept any name in the root zone The hosted-zone check uses normalizeRecordName, the same ASCII-only folding as record identity, so the Kelvin sign in a label stays distinct from the letter k. The root zone, named with a single dot, contains every record name.
This commit is contained in:
1 parent
1bf019f89a
commit
1b7bb80f36
2 files changed
+57
No files matched your search
@@ -972,6 +972,13 @@ public class Route53Service implements Resettable {
|
||||
|
||||
private void validateChange(String action, ResourceRecordSet rrs,
|
||||
List<ResourceRecordSet> current, String zoneName) {
|
||||
String recordName = normalizeRecordName(rrs.getName());
|
||||
String zone = normalizeRecordName(zoneName);
|
||||
if (!".".equals(zone) && !recordName.equals(zone) && !recordName.endsWith("." + zone)) {
|
||||
throw new AwsException("InvalidChangeBatch",
|
||||
"RRSet with DNS name " + normalizeName(rrs.getName()) + " is not permitted in zone "
|
||||
+ normalizeName(zoneName), 400);
|
||||
}
|
||||
if ("DELETE".equals(action) && isApexSoaOrNs(rrs, zoneName)) {
|
||||
throw new AwsException("InvalidChangeBatch",
|
||||
"Invalid resource record set: Deleting the SOA or NS record at the zone apex is not permitted.", 400);
|
||||
|
||||
@@ -268,6 +268,56 @@ class Route53ServiceTest {
|
||||
return rrs;
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordOutsideTheHostedZoneIsRejected() {
|
||||
Route53Service service = newService();
|
||||
String zoneId = service.createHostedZone("datacite.org.", "ref-outside", null, null).zone().getId();
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.changeResourceRecordSets(zoneId,
|
||||
List.of(change("CREATE", aRecord("_lovable.strategy", 300, "1.2.3.4"))), null));
|
||||
assertEquals("InvalidChangeBatch", e.getErrorCode());
|
||||
assertEquals("RRSet with DNS name _lovable.strategy. is not permitted in zone datacite.org.", e.getMessage());
|
||||
AwsException suffixOnly = assertThrows(AwsException.class, () -> service.changeResourceRecordSets(zoneId,
|
||||
List.of(change("CREATE", aRecord("notdatacite.org", 300, "1.2.3.4"))), null));
|
||||
assertEquals("InvalidChangeBatch", suffixOnly.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordInsideTheHostedZoneIsAcceptedRegardlessOfCaseDotOrWildcard() {
|
||||
Route53Service service = newService();
|
||||
String zoneId = service.createHostedZone("datacite.org.", "ref-inside", null, null).zone().getId();
|
||||
|
||||
service.changeResourceRecordSets(zoneId, List.of(
|
||||
change("CREATE", aRecord("WWW.DataCite.org", 300, "1.2.3.4")),
|
||||
change("CREATE", aRecord("*.blog.datacite.org.", 300, "1.2.3.5")),
|
||||
change("CREATE", aRecord("datacite.org", 300, "1.2.3.6"))), null);
|
||||
|
||||
assertEquals(5, service.listResourceRecordSets(zoneId, null, null, 0).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rootHostedZoneAcceptsAnyRecordName() {
|
||||
Route53Service service = newService();
|
||||
String zoneId = service.createHostedZone(".", "ref-root", null, null).zone().getId();
|
||||
|
||||
service.changeResourceRecordSets(zoneId,
|
||||
List.of(change("CREATE", aRecord("www.example.", 300, "1.2.3.4"))), null);
|
||||
|
||||
assertEquals(3, service.listResourceRecordSets(zoneId, null, null, 0).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void zoneCheckFoldsOnlyAsciiLettersLikeRecordIdentity() {
|
||||
Route53Service service = newService();
|
||||
String zoneId = service.createHostedZone("k.example.", "ref-kelvin", null, null).zone().getId();
|
||||
|
||||
service.changeResourceRecordSets(zoneId,
|
||||
List.of(change("CREATE", aRecord("www.K.example.", 300, "1.2.3.4"))), null);
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.changeResourceRecordSets(zoneId,
|
||||
List.of(change("CREATE", aRecord("www.\u212A.example.", 300, "1.2.3.5"))), null));
|
||||
assertEquals("InvalidChangeBatch", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteFailsWithNotFoundMessageWhenNoRecordWithMatchingNameAndTypeExists() {
|
||||
Route53Service service = newService();
|
||||
|
||||
Reference in new issue
Block a user