The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.
Settings ▸ Privacy: a Secure DNS menu beside "Always use secure connections" (#133) (#142)
Victor Kildahled9c154bf6e4
diff --git a/Packages/CraCore/Sources/CraCore/SecureDNS.swift b/Packages/CraCore/Sources/CraCore/SecureDNS.swiftindex 6019665..8634651 100644--- a/Packages/CraCore/Sources/CraCore/SecureDNS.swift+++ b/Packages/CraCore/Sources/CraCore/SecureDNS.swift@@ -35,3 +35,116 @@ public struct SecureDNS: Equatable, Sendable {}}}++extension SecureDNS {+ /// The footnote under Settings ▸ Privacy ▸ Secure DNS: what is in effect, from the same+ /// value as `line`, so the pane and cra.log agree.+ public var summary: String {+ let to = servers.joined(separator: ", ")+ switch mode {+ case "": return ""+ case "off": return "Hostnames are looked up in plain text by the network’s own resolver."+ case "secure":+ if servers.isEmpty { return "No provider is set, so hostnames can’t be looked up. Choose one above." }+ return "Hostnames are looked up over an encrypted connection to \(to). If it can’t be reached, pages don’t load."+ default:+ if servers.isEmpty {+ return "Automatic uses the network’s own resolver, encrypted when it supports it. Names only a work network knows keep working."+ }+ return "Hostnames are looked up over an encrypted connection to \(to) when it answers, else by the network’s own resolver."+ }+ }+}++/// A DoH provider in Settings ▸ Privacy ▸ Secure DNS, named and templated as Chromium's+/// net/dns/public/doh_provider_entry.cc has it (chrome://settings/security writes the same+/// template, so a provider picked there shows by name here).+public struct SecureDNSProvider: Hashable, Sendable, Identifiable {+ public let name: String+ public let template: String+ public var id: String { template }++ /// Chrome's providers shown everywhere, plus DNS4EU, which it shows in the EU (named shorter+ /// than Chrome's "DNS4EU Public Service (Protective)", which set the menu's width). NextDNS+ /// needs the user's own profile id in the path, so it goes through Custom.+ public static let all: [SecureDNSProvider] = [+ SecureDNSProvider(name: "Google (Public DNS)", template: "https://dns.google/dns-query{?dns}"),+ SecureDNSProvider(name: "Cloudflare (1.1.1.1)", template: "https://chrome.cloudflare-dns.com/dns-query"),+ SecureDNSProvider(name: "Quad9 (9.9.9.9)", template: "https://dns.quad9.net/dns-query"),+ SecureDNSProvider(name: "OpenDNS", template: "https://doh.opendns.com/dns-query{?dns}"),+ SecureDNSProvider(name: "CleanBrowsing (Family Filter)", template: "https://doh.cleanbrowsing.org/doh/family-filter{?dns}"),+ SecureDNSProvider(name: "DNS4EU (Protective)", template: "https://protective.joindns4.eu/dns-query{?dns}"),+ ]+}++/// The Secure DNS menu's rows.+public enum SecureDNSChoice: Hashable, Sendable {+ /// Chromium's default: the network's own resolver, encrypted when it is a known DoH server.+ case automatic+ case off+ case provider(SecureDNSProvider)+ case custom+}++/// `dns_over_https.mode` and `dns_over_https.templates` as Settings reads and writes them.+/// Local State is the only copy: Cra keeps none, so a fresh install has no key and a choice+/// made in chrome://settings/security shows here too.+public struct SecureDNSPrefs: Equatable, Sendable {+ public var mode: String+ public var templates: String++ public init(mode: String, templates: String) {+ self.mode = mode+ self.templates = templates+ }++ /// What to write for a menu row. Custom takes the typed templates and is nil while they+ /// aren't valid.+ public init?(_ choice: SecureDNSChoice, custom: String = "") {+ switch choice {+ case .automatic: self.init(mode: "automatic", templates: "")+ case .off: self.init(mode: "off", templates: "")+ case .provider(let p): self.init(mode: "secure", templates: p.template)+ case .custom:+ guard let templates = Self.validTemplates(custom) else { return nil }+ self.init(mode: "secure", templates: templates)+ }+ }++ /// The menu row for what Chromium holds. Automatic with a provider (an old Chrome default+ /// or a policy) is still Automatic: the footnote names the provider.+ public var choice: SecureDNSChoice {+ switch mode {+ case "off": return .off+ case "secure":+ let t = templates.trimmingCharacters(in: .whitespacesAndNewlines)+ return SecureDNSProvider.all.first { $0.template == t }.map { .provider($0) } ?? .custom+ default: return .automatic+ }+ }++ /// A custom entry as Chromium takes it: one or more RFC 8484 URI templates separated by+ /// whitespace, each https:// with a host. The path is kept exactly as typed (NextDNS puts+ /// the user's profile id there). nil when any of them isn't one.+ public static func validTemplates(_ text: String) -> String? {+ let parts = text.split(whereSeparator: \.isWhitespace).map(String.init)+ guard !parts.isEmpty else { return nil }+ for template in parts {+ guard template.lowercased().hasPrefix("https://"), isBalanced(template) else { return nil }+ // RFC 6570 expressions ("{?dns}") aren't valid in a URL: check what's before them.+ let base = String(template.prefix { $0 != "{" })+ guard let url = URLComponents(string: base), url.scheme?.lowercased() == "https",+ let host = url.host, !host.isEmpty, url.user == nil, url.password == nil else { return nil }+ }+ return parts.joined(separator: " ")+ }++ private static func isBalanced(_ template: String) -> Bool {+ var open = false+ for c in template {+ if c == "{" { if open { return false }; open = true }+ if c == "}" { if !open { return false }; open = false }+ }+ return !open+ }+}diff --git a/Packages/CraCore/Tests/CraCoreTests/SecureDNSTests.swift b/Packages/CraCore/Tests/CraCoreTests/SecureDNSTests.swiftindex f906327..4c320bf 100644--- a/Packages/CraCore/Tests/CraCoreTests/SecureDNSTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/SecureDNSTests.swift@@ -31,4 +31,64 @@ struct SecureDNSTests {@Test func aTemplateWithoutAHostIsNamedButNotShown() {#expect(SecureDNS(mode: "secure", templates: "not a url/secret").line == "secure via a custom server")}++ // Settings ▸ Privacy ▸ Secure DNS (#133).++ @Test func eachRowWritesWhatChromeWrites() {+ #expect(SecureDNSPrefs(.automatic) == SecureDNSPrefs(mode: "automatic", templates: ""))+ #expect(SecureDNSPrefs(.off) == SecureDNSPrefs(mode: "off", templates: ""))+ let google = SecureDNSProvider.all[0]+ #expect(SecureDNSPrefs(.provider(google)) == SecureDNSPrefs(mode: "secure", templates: "https://dns.google/dns-query{?dns}"))+ #expect(SecureDNSPrefs(.custom, custom: " https://dns.nextdns.io/a1b2c3/MacBook ")+ == SecureDNSPrefs(mode: "secure", templates: "https://dns.nextdns.io/a1b2c3/MacBook"))+ #expect(SecureDNSPrefs(.custom, custom: "http://dns.example/dns-query") == nil)+ }++ @Test func whatChromiumHoldsShowsAsItsRow() {+ #expect(SecureDNSPrefs(mode: "", templates: "").choice == .automatic)+ #expect(SecureDNSPrefs(mode: "automatic", templates: "").choice == .automatic)+ #expect(SecureDNSPrefs(mode: "automatic", templates: "https://dns.google/dns-query{?dns}").choice == .automatic)+ #expect(SecureDNSPrefs(mode: "off", templates: "https://dns.google/dns-query{?dns}").choice == .off)+ guard case .provider(let quad9) = SecureDNSPrefs(mode: "secure", templates: "https://dns.quad9.net/dns-query\n").choice else {+ Issue.record("Quad9 not recognised"); return+ }+ #expect(quad9.name == "Quad9 (9.9.9.9)")+ #expect(SecureDNSPrefs(mode: "secure", templates: "https://dns.nextdns.io/a1b2c3").choice == .custom)+ #expect(SecureDNSPrefs(mode: "secure", templates: "").choice == .custom)+ }++ @Test func everyProviderRoundTrips() {+ for p in SecureDNSProvider.all {+ #expect(SecureDNSPrefs(.provider(p))?.choice == .provider(p))+ #expect(SecureDNSPrefs.validTemplates(p.template) == p.template)+ }+ }++ @Test(arguments: [+ ("https://dns.google/dns-query{?dns}", "https://dns.google/dns-query{?dns}"),+ ("https://dns.nextdns.io/a1b2c3/My%20Mac", "https://dns.nextdns.io/a1b2c3/My%20Mac"),+ ("HTTPS://dns.example:8443/q", "HTTPS://dns.example:8443/q"),+ ("https://a.example/dns-query\n https://b.example/dns-query{?dns}", "https://a.example/dns-query https://b.example/dns-query{?dns}"),+ ])+ func customTemplatesKeepTheirPath(text: String, templates: String) {+ #expect(SecureDNSPrefs.validTemplates(text) == templates)+ }++ @Test(arguments: [+ "", " ", "dns.google", "http://dns.google/dns-query", "tls://dns.google", "https://",+ "https:///dns-query", "https://user:[email protected]/q", "https://dns.example/q{?dns",+ "https://dns.example/q}", "https://dns.google/dns-query http://plain.example/q",+ ])+ func customTemplatesMustBeHTTPS(text: String) {+ #expect(SecureDNSPrefs.validTemplates(text) == nil)+ }++ @Test func summaryNamesTheServerInEffect() {+ #expect(SecureDNS(mode: "secure", templates: "https://dns.google/dns-query{?dns}").summary.contains("dns.google"))+ #expect(SecureDNS(mode: "automatic", templates: "").summary.hasPrefix("Automatic uses the network’s own resolver"))+ #expect(SecureDNS(mode: "off", templates: "").summary.contains("plain text"))+ #expect(SecureDNS(mode: "secure", templates: "").summary.contains("No provider"))+ #expect(!SecureDNS(mode: "secure", templates: "https://dns.nextdns.io/a1b2c3").summary.contains("a1b2c3"))+ #expect(SecureDNS(mode: "", templates: "").summary.isEmpty)+ }}diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swiftindex dda2c8d..93ddd7c 100644--- a/Sources/Cra/App/AppDelegate.swift+++ b/Sources/Cra/App/AppDelegate.swift@@ -183,13 +183,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {observeChanges(of: { [store] in store.settings.httpsOnly }, apply: CraCEFRuntime.setHttpsOnlyModeEnabled)}- /// Chromium's secure DNS setting (chrome://settings/security), left on Chromium's default- /// like Arc: the log says what is in effect at launch and after each change (#110).+ /// Chromium's secure DNS setting (Settings > Privacy, chrome://settings/security), left on+ /// Chromium's default like Arc: the log says what is in effect at launch and after each+ /// change (#110), and the Settings row follows it (#133).private func logSecureDNS() {var last: String?CraCEFRuntime.setSecureDNSChangeHandler {- guard let mode = CraCEFRuntime.secureDNSMode() else { return }- let line = SecureDNS(mode: mode, templates: CraCEFRuntime.secureDNSTemplates() ?? "").line+ let setting = SecureDNSSetting.shared+ setting.refresh()+ guard let line = setting.inEffect?.line else { return }if line != last { last = line; CraLog.note("secure dns: " + line) }}}diff --git a/Sources/Cra/Services/SecureDNSSetting.swift b/Sources/Cra/Services/SecureDNSSetting.swiftnew file mode 100644index 0000000..9ba3245--- /dev/null+++ b/Sources/Cra/Services/SecureDNSSetting.swift@@ -0,0 +1,33 @@+import CraCEF+import Observation++/// Settings ▸ Privacy ▸ Secure DNS (#133): Chromium's own setting in Local State, read live and+/// written back, with no copy in settings.json. AppDelegate refreshes it when Chromium reports+/// a change, wherever it was made (chrome://settings/security too).+@MainActor+@Observable+final class SecureDNSSetting {+ static let shared = SecureDNSSetting()++ /// What Chromium holds now; nil until Chromium is ready.+ private(set) var prefs: SecureDNSPrefs?+ /// A policy sets it, so the menu is read-only.+ private(set) var isManaged = false++ var inEffect: SecureDNS? { prefs.map { SecureDNS(mode: $0.mode, templates: $0.templates) } }++ private init() {}++ func refresh() {+ prefs = CraCEFRuntime.secureDNSMode().map { SecureDNSPrefs(mode: $0, templates: CraCEFRuntime.secureDNSTemplates() ?? "") }+ isManaged = CraCEFRuntime.secureDNSIsManaged()+ }++ /// False when Chromium refused it (not ready, managed, write failed).+ @discardableResult+ func apply(_ new: SecureDNSPrefs) -> Bool {+ let ok = CraCEFRuntime.setSecureDNSMode(new.mode, templates: new.templates)+ refresh()+ return ok+ }+}diff --git a/Sources/Cra/UI/Settings/PrivacyPane.swift b/Sources/Cra/UI/Settings/PrivacyPane.swiftindex 9242f00..8987f4e 100644--- a/Sources/Cra/UI/Settings/PrivacyPane.swift+++ b/Sources/Cra/UI/Settings/PrivacyPane.swift@@ -5,7 +5,8 @@ import SwiftUI/// ad-and-tracker domain list, so it has one switch and no usage-data row; "Connections"/// is Chrome's "Always use secure connections". "Data" holds Arc's Clear Browsing Data (Arc keeps/// it in Settings ▸ Profiles and opens Chrome's Privacy and security page; Cra opens Chrome's-/// Delete browsing data dialog itself, the step after).+/// Delete browsing data dialog itself, the step after). "Connections" also holds Chromium's+/// secure DNS setting, which Arc and Dia leave to chrome://settings/security (#133).struct PrivacyPane: View {@Environment(SidebarStore.self) private var storelet actions: SettingsActions@@ -38,8 +39,12 @@ struct PrivacyPane: View {Toggle("Always use secure connections", isOn: $store.settings.httpsOnly).toggleStyle(.switch).labelsHidden()}+ SettingsCardDivider()+ SecureDNSRows(error: $dnsError)}SettingsFootnote("Pages load over HTTPS. Before opening a site that doesn’t support it, Cra warns you first.")+ if let line = dnsFootnote { SettingsFootnote(line) }+ if let dnsError { SettingsFootnote(dnsError).foregroundStyle(.red) }SettingsHeader("Data").padding(.top, 20)SettingsCard {@@ -55,4 +60,88 @@ struct PrivacyPane: View {SettingsFootnote("Delete history, cookies and cached files for the current space’s profile. History you delete also leaves the command bar.")}}++ @State private var dnsError: String?++ private var dnsFootnote: String? {+ let dns = SecureDNSSetting.shared+ guard let summary = dns.inEffect?.summary, !summary.isEmpty else { return nil }+ return dns.isManaged ? "Your organization sets secure DNS. " + summary : summary+ }+}++/// Chromium's secure DNS setting (chrome://settings/security) as a menu, under "Always use+/// secure connections": the lookup before the page (#133). Custom adds a row for the template.+private struct SecureDNSRows: View {+ @Binding var error: String?+ private let dns = SecureDNSSetting.shared+ @State private var editingCustom = false+ @State private var customText = ""++ var body: some View {+ SettingsCardRow {+ HStack(spacing: 5.5) {+ SettingsGlyph(symbol: "network.badge.shield.half.filled", color: Color(nsColor: .systemBlue))+ Text("Secure DNS").font(.system(size: 13))+ }+ } trailing: {+ Picker("Secure DNS", selection: choice) {+ Text("Automatic").tag(SecureDNSChoice.automatic)+ Text("Off").tag(SecureDNSChoice.off)+ Divider()+ ForEach(SecureDNSProvider.all) { Text($0.name).tag(SecureDNSChoice.provider($0)) }+ Divider()+ Text("Custom…").tag(SecureDNSChoice.custom)+ }+ .labelsHidden()+ .fixedSize()+ .disabled(dns.prefs == nil || dns.isManaged)+ .onAppear { dns.refresh() }+ .onChange(of: liveCustom, initial: true) { if let liveCustom { customText = liveCustom } }+ }+ if showsCustom {+ SettingsCardDivider()+ SettingsCardRow {+ TextField("Custom provider", text: $customText, prompt: Text("https://dns.example/dns-query{?dns}"))+ .textFieldStyle(.roundedBorder)+ .font(.system(size: 12))+ .onSubmit(saveCustom)+ .disabled(dns.isManaged)+ } trailing: {+ Button("Use", action: saveCustom)+ .disabled(dns.isManaged || customText.trimmingCharacters(in: .whitespacesAndNewlines) == liveCustom)+ }+ }+ }++ private var current: SecureDNSChoice { dns.prefs?.choice ?? .automatic }+ private var liveCustom: String? { current == .custom ? dns.prefs?.templates : nil }+ private var showsCustom: Bool { editingCustom || current == .custom }++ private var choice: Binding<SecureDNSChoice> {+ Binding(get: { editingCustom ? .custom : current }, set: { new in+ error = nil+ if new == .custom {+ if !showsCustom { customText = "" }+ editingCustom = true+ return+ }+ editingCustom = false+ if let prefs = SecureDNSPrefs(new), !dns.apply(prefs) { error = "Cra couldn’t change secure DNS." }+ })+ }++ private func saveCustom() {+ guard let prefs = SecureDNSPrefs(.custom, custom: customText) else {+ error = "Enter one or more https:// templates, like https://dns.example/dns-query{?dns}."+ return+ }+ error = nil+ if dns.apply(prefs) {+ editingCustom = false+ customText = prefs.templates+ } else {+ error = "Cra couldn’t change secure DNS."+ }+ }}diff --git a/Sources/Cra/UI/Settings/SettingsKit.swift b/Sources/Cra/UI/Settings/SettingsKit.swiftindex 5ef30dc..5fdae44 100644--- a/Sources/Cra/UI/Settings/SettingsKit.swift+++ b/Sources/Cra/UI/Settings/SettingsKit.swift@@ -82,7 +82,8 @@ struct SettingsFootnote: View {}}-/// Dia's coloured 20 pt rounded-square glyph in front of a Privacy row.+/// Dia's coloured 20 pt rounded-square glyph in front of a Privacy row. Decoration: the row's+/// text names it, so VoiceOver skips it.struct SettingsGlyph: View {let symbol: Stringlet color: Color@@ -91,6 +92,7 @@ struct SettingsGlyph: View {.fill(color).frame(width: 20, height: 20).overlay(Image(systemName: symbol).font(.system(size: 11, weight: .semibold)).foregroundStyle(.white))+ .accessibilityHidden(true)}}diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mmindex 79df87f..28dec43 100644--- a/Sources/CraCEF/CraCEF.mm+++ b/Sources/CraCEF/CraCEF.mm@@ -2573,6 +2573,30 @@ static void MarkProfileExitedCleanly(NSString* profileDir) {}+ (NSString*)secureDNSMode { return SecureDNSPreference("dns_over_https.mode"); }+ (NSString*)secureDNSTemplates { return SecureDNSPreference("dns_over_https.templates"); }++ (BOOL)setSecureDNSMode:(NSString*)mode templates:(NSString*)templates {+ if (!g_contextInitialized || g_quitting || [self secureDNSIsManaged]) return NO;+ CefRefPtr<CefPreferenceManager> local = CefPreferenceManager::GetGlobalPreferenceManager();+ if (!local) return NO;+ // Provider first when turning secure on, mode first otherwise, so the network service+ // never sees "secure" without a server in between.+ std::vector<std::pair<const char*, NSString*>> writes = {{"dns_over_https.mode", mode}, {"dns_over_https.templates", templates}};+ if ([mode isEqualToString:@"secure"]) std::swap(writes[0], writes[1]);+ for (const auto& [name, string] : writes) {+ CefRefPtr<CefValue> value = CefValue::Create();+ value->SetString(CefStringFromNS(string));+ CefString error;+ if (!local->SetPreference(name, value, error)) {+ NSLog(@"CraCEF: %s: %s", name, error.ToString().c_str());+ return NO;+ }+ }+ return YES;+}++ (BOOL)secureDNSIsManaged {+ if (!g_contextInitialized || g_quitting) return NO;+ CefRefPtr<CefPreferenceManager> local = CefPreferenceManager::GetGlobalPreferenceManager();+ return local && !(local->CanSetPreference("dns_over_https.mode") && local->CanSetPreference("dns_over_https.templates"));+}+ (void)setSecureDNSChangeHandler:(void (^)(void))handler {g_secureDNSHandler = [handler copy];if (g_contextInitialized) NotifySecureDNS();diff --git a/Sources/CraCEF/include/CraCEF.h b/Sources/CraCEF/include/CraCEF.hindex 0f25a79..8734daa 100644--- a/Sources/CraCEF/include/CraCEF.h+++ b/Sources/CraCEF/include/CraCEF.h@@ -244,6 +244,11 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {/// before Chromium is ready and once quitting starts.+ (nullable NSString *)secureDNSMode;+ (nullable NSString *)secureDNSTemplates;+/// Writes both, as chrome://settings/security does; Chromium's network service picks the+/// change up at once. NO when Chromium isn't ready, a policy sets them, or a write fails.++ (BOOL)setSecureDNSMode:(NSString *)mode templates:(NSString *)templates;+/// A policy (DnsOverHttpsMode, DnsOverHttpsTemplates) sets secure DNS, so Settings can't.++ (BOOL)secureDNSIsManaged;/// Called on the main queue once Chromium is ready (at once if it already is) and after the/// secure DNS setting changes.+ (void)setSecureDNSChangeHandler:(nullable void (^)(void))handler;diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex aac7e19..cd59036 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -2287,6 +2287,15 @@ was frontmost, 1x region captures and 100 fps recordings; test tabs archived aftwhat is in effect at launch and after each change (`secure dns: automatic, no provider (system resolver)`, `securevia dns.google`, `off`), and Export Diagnostics' summary has a `Secure DNS:` line (`SecureDNS` in CraCore, hostsonly).+- Cra (3 Nov 2026, issue #133, a deviation: Arc and Dia have no such row): Settings ▸ Privacy ▸ Connections has a Secure+ DNS menu under "Always use secure connections": Automatic (the default), Off, Google, Cloudflare, Quad9, OpenDNS,+ CleanBrowsing (Family Filter), DNS4EU (Protective), Custom…. It reads and writes the same two Local State prefs as+ chrome://settings/security (`SecureDNSPrefs`, `SecureDNSProvider` in CraCore; `setSecureDNSMode:templates:` in+ CraCEF), so settings.json keeps no copy, a fresh install still has no `dns_over_https` key, and a choice made on+ either page shows on the other at once. The write is live: a net log shows `secure_dns_mode` 1 → 2 and DoH queries+ to dns.google with no relaunch. Custom takes whitespace-separated `https://` templates with a host, path kept as+ typed (NextDNS ids). The footnote is `SecureDNS.summary`, built from the same value as the log line. A+ DnsOverHttps* policy makes the menu read-only.## Shift + wheel switches spaces (Arc 1.171, 2 Nov 2026, issue #93, live Arc, HID wheel events)