Commit e38ea79776

e38ea79776995336cb4a4daf656bb9f50452b51c

parent: be788ce778

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-24 02:16 UTC

Report a domain as available when the registry says so

Availability could only ever come back Registered or Unknown.
RDAPService.registrationStatus mapped a 404 to nil, and
DomainAvailabilityService rewrote a DNS-derived Registered to Unknown, so
no path produced .available. Every consumer of it — the status badge, the
suggestions list, the insight engine, the diff service, the exporters,
the audit views — rendered a case that never arrived.

rdap.org answers 404 both for a domain its registry does not hold and for
a TLD it knows no RDAP server for, so the 404 alone is not evidence.
URLSession follows the bootstrap redirect, so the response URL's host
says which server answered: off rdap.org, the registry answered and the
domain is unregistered.

The DNS fallback now keeps its Registered result. It still cannot report
available, because the DoH layer drops the response code and NXDOMAIN
arrives indistinguishable from a resolver failure.

Layout: unified · split

DomainDig.xcodeproj/project.pbxproj +4
@@ -26,6 +26,7 @@
2626 A5AF921BC1C2E6E940CC05DC /* SnapshotFixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CA789D3607B55E3612E6FFA /* SnapshotFixture.swift */; };
2727 C7CA9E02B0DC2708DE7A8563 /* DomainDataPortabilityServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */; };
2828 E959C4D24DAAB3CB80D854B2 /* DiffServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A25DF2B8BB52589D49986B /* DiffServiceTests.swift */; };
29 A1B2C3D40000000000000202 /* InspectionInputTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D40000000000000201 /* InspectionInputTests.swift */; };
2930 EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D85A44C5F315A1644AC9073 /* LocalAPIContractTests.swift */; };
3031/* End PBXBuildFile section */
3132
@@ -96,6 +97,7 @@
9697 8BDC00010000000000000001 /* DomainDigUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9798 8BF9DA842F9B13FB00EF41D5 /* DomainDataPortabilityService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityService.swift; sourceTree = "<group>"; };
9899 A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = HistoryEntryCodableTests.swift; sourceTree = "<group>"; };
100 A1B2C3D40000000000000201 /* InspectionInputTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = InspectionInputTests.swift; sourceTree = "<group>"; };
99101 A77F7ED29E7C6669F5E61C04 /* DomainDigTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
100102 CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityServiceTests.swift; sourceTree = "<group>"; };
101103 DE8B269A01CC5E593DA3DFC2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS26.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
@@ -233,6 +235,7 @@
233235 435AFB3F99D579D3D7B58279 /* DataMigrationServiceTests.swift */,
234236 499B99A1866999A38AC475F5 /* AppInfoTests.swift */,
235237 A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */,
238 A1B2C3D40000000000000201 /* InspectionInputTests.swift */,
236239 );
237240 path = DomainDigTests;
238241 sourceTree = "<group>";
@@ -493,6 +496,7 @@
493496 EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */,
494497 4F96CEB875EC3501E784CE39 /* DataMigrationServiceTests.swift in Sources */,
495498 99024E91EED2275FD80E83A9 /* AppInfoTests.swift in Sources */,
499 A1B2C3D40000000000000202 /* InspectionInputTests.swift in Sources */,
496500 );
497501 runOnlyForDeploymentPostprocessing = 0;
498502 };
DomainDig/DomainAvailabilityService.swift +7 −6
@@ -9,15 +9,16 @@ struct DomainAvailabilityService {
99 return DomainAvailabilityResult(domain: domain, status: .unknown)
1010 }
1111
12 if await checkViaRDAP(domain: normalizedDomain) == .registered {
13 return DomainAvailabilityResult(domain: normalizedDomain, status: .registered)
12 // RDAP is the registry's own record, so it settles both directions.
13 if let registryStatus = await checkViaRDAP(domain: normalizedDomain) {
14 return DomainAvailabilityResult(domain: normalizedDomain, status: registryStatus)
1415 }
1516
17 // Without a registry answer only "registered" is decidable: a name that
18 // resolves is registered. Absence of records is not evidence of
19 // availability, because the DoH layer drops the response code, so
20 // NXDOMAIN and a resolver failure arrive here identically.
1621 let fallbackStatus = await checkViaDNSFallback(domain: normalizedDomain)
17 if fallbackStatus == .registered {
18 return DomainAvailabilityResult(domain: normalizedDomain, status: .unknown)
19 }
20
2122 return DomainAvailabilityResult(domain: normalizedDomain, status: fallbackStatus)
2223 }
2324
DomainDig/RDAPService.swift +47 −16
@@ -1,20 +1,34 @@
11import Foundation
22
33enum RDAPService {
4 /// The registry's answer about `domain`, or nil when the registry did not
5 /// give one.
46 static func registrationStatus(for domain: String) async -> DomainAvailabilityStatus? {
57 let normalizedDomain = normalize(domain)
68 guard !normalizedDomain.isEmpty else { return nil }
79
810 switch await fetchRDAPResponse(for: normalizedDomain) {
9 case let .success(response):
10 return response.isDomainRecord ? .registered : nil
11 case .empty:
12 return nil
13 case .error:
11 case .found:
12 return .registered
13 case .notRegistered:
14 return .available
15 case .empty, .failed:
1416 return nil
1517 }
1618 }
1719
20 /// Whether an RDAP response came from a registry's own server rather than
21 /// from the `rdap.org` bootstrap redirector.
22 ///
23 /// `rdap.org` answers 404 both for a domain its registry does not hold and
24 /// for a TLD it knows no RDAP server for; only the first says anything about
25 /// registration. `URLSession` follows the bootstrap redirect, so a response
26 /// URL on another host is the registry's own answer.
27 static func answeredByRegistry(responseURL: URL?) -> Bool {
28 guard let host = responseURL?.host?.lowercased() else { return false }
29 return host != bootstrapHost && !host.hasSuffix(".\(bootstrapHost)")
30 }
31
1832 static func ownership(for domain: String) async -> ServiceResult<DomainOwnership> {
1933 let normalizedDomain = normalize(domain)
2034 guard !normalizedDomain.isEmpty else {
@@ -22,7 +36,7 @@ enum RDAPService {
2236 }
2337
2438 switch await fetchRDAPResponse(for: normalizedDomain) {
25 case let .success(response):
39 case let .found(response):
2640 let ownership = DomainOwnership(
2741 registrar: response.registrarName,
2842 registrant: response.registrantName,
@@ -33,9 +47,11 @@ enum RDAPService {
3347 abuseEmail: response.abuseEmail
3448 )
3549 return .success(ownership)
50 case .notRegistered:
51 return .empty("Unavailable")
3652 case let .empty(message):
3753 return .empty(message)
38 case let .error(message):
54 case let .failed(message):
3955 return .error(message)
4056 }
4157 }
@@ -47,10 +63,24 @@ enum RDAPService {
4763 }
4864}
4965
50private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDomainResponse> {
66private let bootstrapHost = "rdap.org"
67
68/// What a single RDAP fetch established.
69private enum RDAPFetchOutcome {
70 /// A domain record, from whichever server answered.
71 case found(RDAPDomainResponse)
72 /// The registry's own RDAP server reported no such domain.
73 case notRegistered
74 /// An answer that settles nothing: a non-domain record, or a 404 from the
75 /// bootstrap redirector rather than from a registry.
76 case empty(String)
77 case failed(String)
78}
79
80private func fetchRDAPResponse(for domain: String) async -> RDAPFetchOutcome {
5181 let startedAt = DomainDebugLog.signpostStart("RDAP.fetch", domain: domain)
52 guard let url = URL(string: "https://rdap.org/domain/\(domain)") else {
53 return .error("Unavailable")
82 guard let url = URL(string: "https://\(bootstrapHost)/domain/\(domain)") else {
83 return .failed("Unavailable")
5484 }
5585
5686 do {
@@ -61,7 +91,7 @@ private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDo
6191 let (data, response) = try await URLSession.shared.data(for: request)
6292 guard let httpResponse = response as? HTTPURLResponse else {
6393 DomainDebugLog.error("RDAP.badResponse domain=\(domain) response=nil")
64 return .error(URLError(.badServerResponse).localizedDescription)
94 return .failed(URLError(.badServerResponse).localizedDescription)
6595 }
6696
6797 switch httpResponse.statusCode {
@@ -73,19 +103,20 @@ private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDo
73103 return .empty("Unavailable")
74104 }
75105 DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=200 bytes=\(data.count)")
76 return .success(rdapResponse)
106 return .found(rdapResponse)
77107 case 404:
78 DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=404")
79 return .empty("Unavailable")
108 let fromRegistry = RDAPService.answeredByRegistry(responseURL: httpResponse.url)
109 DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=404 registry=\(fromRegistry)")
110 return fromRegistry ? .notRegistered : .empty("Unavailable")
80111 default:
81112 DomainDebugLog.error("RDAP.httpError domain=\(domain) status=\(httpResponse.statusCode)")
82113 DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=\(httpResponse.statusCode)")
83 return .error("Unavailable")
114 return .failed("Unavailable")
84115 }
85116 } catch {
86117 DomainDebugLog.error("RDAP.error domain=\(domain) error=\(error.localizedDescription)")
87118 DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "error")
88 return .error(error.localizedDescription)
119 return .failed(error.localizedDescription)
89120 }
90121}
91122
DomainDigTests/InspectionInputTests.swift added +38
@@ -0,0 +1,38 @@
1import XCTest
2@testable import DomainDig
3
4/// `rdap.org` answers 404 both for a domain its registry does not hold and for a
5/// TLD it knows no RDAP server for. Only the first means "available", so the
6/// availability check turns on which server answered.
7final class RDAPRegistryOriginTests: XCTestCase {
8
9 func testRegistryResponseCountsAsAnAnswer() {
10 let url = URL(string: "https://rdap.verisign.com/com/v1/domain/example.com")
11 XCTAssertTrue(RDAPService.answeredByRegistry(responseURL: url))
12 }
13
14 func testBootstrapResponseDoesNotCountAsAnAnswer() {
15 let url = URL(string: "https://rdap.org/domain/example.invalidtld")
16 XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url))
17 }
18
19 func testBootstrapSubdomainDoesNotCountAsAnAnswer() {
20 let url = URL(string: "https://www.rdap.org/domain/example.invalidtld")
21 XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url))
22 }
23
24 func testHostMatchIsCaseInsensitive() {
25 let url = URL(string: "https://RDAP.ORG/domain/example.com")
26 XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url))
27 }
28
29 func testMissingResponseURLDoesNotCountAsAnAnswer() {
30 XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: nil))
31 }
32
33 /// A host that merely ends in the bootstrap name is a different domain.
34 func testLookalikeHostCountsAsAnAnswer() {
35 let url = URL(string: "https://notrdap.org/domain/example.com")
36 XCTAssertTrue(RDAPService.answeredByRegistry(responseURL: url))
37 }
38}