Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Update checks follow a redirect only to another https address
Țugui Dragoșe0a0068bdc2a
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swiftindex 38c18702..e5bc6ed1 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift@@ -167,7 +167,8 @@ public struct UpdateChecker: Sendable {private func fetchReply(_ url: URL) async -> (data: Data?, status: Int?) {let request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 15)- guard let (stream, response) = try? await session.bytes(for: request) else { return (nil, nil) }+ let reply = try? await session.bytes(for: request, delegate: SecureRedirects())+ guard let (stream, response) = reply else { return (nil, nil) }let status = (response as? HTTPURLResponse)?.statusCodeguard status == 200, response.expectedContentLength <= Self.maximumFeedBytes else { return (nil, status) }@@ -188,6 +189,18 @@ public struct UpdateChecker: Sendable {}}+/// Follows a redirect only to another https address. Every address an update check asks is https, while App+/// Transport Security still lets plain http reach this Mac and its local network, so a feed server could otherwise+/// send the check to a service there.+private final class SecureRedirects: NSObject, URLSessionTaskDelegate {+ func urlSession(+ _ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse,+ newRequest request: URLRequest, completionHandler: @escaping @Sendable (URLRequest?) -> Void+ ) {+ completionHandler(request.url?.scheme == "https" ? request : nil)+ }+}+/// The result of one update check. `developer` is set only when the App Store answered.public struct UpdateAnswer: Sendable, Hashable {public let status: UpdateStatusdiff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdatePrivacyTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdatePrivacyTests.swiftindex dfac3fc6..0e850610 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdatePrivacyTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdatePrivacyTests.swift@@ -18,13 +18,29 @@ private final class RecordingProtocol: URLProtocol, @unchecked Sendable {}}-/// A server on this Mac's loopback that answers one request with a feed and keeps the request's headers.+/// A server on this Mac's loopback that answers one request and keeps the request's headers. One never asked stops+/// listening after ten seconds.private final class OneRequestServer: Sendable {+ enum Answer {+ case feed+ case redirect(to: URL)++ var reply: String {+ switch self {+ case .feed:+ let body = #"<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel><item><sparkle:version>2</sparkle:version></item></channel></rss>"#+ return "HTTP/1.1 200 OK\r\nContent-Type: application/xml\r\nContent-Length: \(body.utf8.count)\r\nConnection: close\r\n\r\n\(body)"+ case .redirect(let url):+ return "HTTP/1.1 302 Found\r\nLocation: \(url.absoluteString)\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"+ }+ }+ }+let port: UInt16private let headers = Mutex<[String: String]?>(nil)private let answered = DispatchSemaphore(value: 0)- init() throws {+ init(answering answer: Answer = .feed) throws {let listening = socket(AF_INET, SOCK_STREAM, 0)var address = sockaddr_in()address.sin_family = sa_family_t(AF_INET)@@ -38,16 +54,23 @@ private final class OneRequestServer: Sendable {throw POSIXError(.EADDRNOTAVAIL)}port = UInt16(bigEndian: address.sin_port)- Thread { [self] in serve(listening) }.start()+ let reply = answer.reply+ Thread { [self] in serve(listening, reply: reply) }.start()}+ var url: URL { URL(string: "http://127.0.0.1:\(port)/appcast.xml")! }++ var wasAsked: Bool { headers.withLock { $0 != nil } }+func receivedHeaders() -> [String: String]? {guard answered.wait(timeout: .now() + 10) == .success else { return nil }return headers.withLock { $0 }}- private func serve(_ listening: Int32) {+ private func serve(_ listening: Int32, reply: String) {defer { close(listening) }+ var waiting = pollfd(fd: listening, events: Int16(POLLIN), revents: 0)+ guard poll(&waiting, 1, 10_000) == 1 else { return }let connection = accept(listening, nil, nil)guard connection >= 0 else { return }defer { close(connection) }@@ -64,8 +87,6 @@ private final class OneRequestServer: Sendable {line.firstIndex(of: ":").map { (String(line[..<$0]), line[line.index(after: $0)...].trimmingCharacters(in: .whitespaces)) }}, uniquingKeysWith: { first, _ in first })}- let body = #"<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel><item><sparkle:version>2</sparkle:version></item></channel></rss>"#- let reply = "HTTP/1.1 200 OK\r\nContent-Type: application/xml\r\nContent-Length: \(body.utf8.count)\r\nConnection: close\r\n\r\n\(body)"_ = Array(reply.utf8).withUnsafeBytes { write(connection, $0.baseAddress, $0.count) }answered.signal()}@@ -94,10 +115,9 @@ private final class OneRequestServer: Sendable {@Test func tellsAFeedServerNothingButPeelsName() async throws {let server = try OneRequestServer()- let feed = try #require(URL(string: "http://127.0.0.1:\(server.port)/appcast.xml"))let app = InstalledApp(url: URL(filePath: "/Applications/Editor.app"), bundleIdentifier: "org.example.editor", name: "Editor",- version: "1", updateFeed: .sparkle(feed)+ version: "1", updateFeed: .sparkle(server.url))#expect(await UpdateChecker().status(for: app, preference: .developer) != .failed)@@ -107,6 +127,19 @@ private final class OneRequestServer: Sendable {#expect(headers["Accept-Language"] == "*")}+ @Test func followsARedirectOnlyToHTTPS() async throws {+ let elsewhere = try OneRequestServer()+ let server = try OneRequestServer(answering: .redirect(to: elsewhere.url))+ let app = InstalledApp(+ url: URL(filePath: "/Applications/Editor.app"), bundleIdentifier: "org.example.editor", name: "Editor",+ version: "1", updateFeed: .sparkle(server.url)+ )++ #expect(await UpdateChecker().status(for: app, preference: .developer) == .failed)+ #expect(server.wasAsked)+ #expect(!elsewhere.wasAsked)+ }+/// A feed server can make an `ETag` or a date unique to one Mac and read it back in the next request (RFC 9110,/// section 17.14), so the session keeps no cache that would send one back.@Test func keepsNothingAFeedServerCouldReadBack() {diff --git a/README.md b/README.mdindex e080a728..b9c1de13 100644--- a/README.md+++ b/README.md@@ -239,12 +239,13 @@ it.Peel sends no analytics and has no account. On its own, it goes online only to check your apps for updates, and youcan turn that off. Each check asks one app's own update feed about that app alone, or the App Store about an app-bought there, and says only that Peel is asking: not which version, not your macOS, and not your languages. Homebrew-goes online only when you ask it to update, upgrade, or scan for vulnerabilities, and that scan is the one time a list-of what is installed leaves your Mac: for each Homebrew formula it checks, where its code comes from (the address of-its source repository and the release tag, or a package's name) and its version, sent to `api.osv.dev`. Your own-Homebrew settings (a `brew.env` file) can change that, and the Homebrew page then says what they change. Turn off-Check for app updates in Settings, and Peel contacts nothing on its own.+bought there, and says only that Peel is asking: not which version, not your macOS, and not your languages. Every+check uses https, and a feed that sends it elsewhere is followed only to another https address. Homebrew goes online+only when you ask it to update, upgrade, or scan for vulnerabilities, and that scan is the one time a list of what is+installed leaves your Mac: for each Homebrew formula it checks, where its code comes from (the address of its source+repository and the release tag, or a package's name) and its version, sent to `api.osv.dev`. Your own Homebrew+settings (a `brew.env` file) can change that, and the Homebrew page then says what they change. Turn off Check for app+updates in Settings, and Peel contacts nothing on its own.<details><summary>Every address Peel or Homebrew may contact</summary>