Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Update checks tell a feed server only that Peel is asking

Țugui Dragoșb86c38f2277d
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
index 41a2acc0..38c18702 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
@@ -5,9 +5,10 @@ public struct UpdateChecker: Sendable {
/// the app's own bundle, so the server is not trusted to keep its reply small.
private static let maximumFeedBytes = 4 * 1_024 * 1_024
- /// Settings for Peel's own session, used instead of the shared one: no cookies, no cache, and time limits.
- /// A feed server should not set a cookie, read one left by another app's check, get back a validator it could
- /// make unique to this Mac, or hold a connection open.
+ /// Settings for Peel's own session, used instead of the shared one: no cookies, no cache, time limits, and
+ /// headers of its own. A feed server should not set a cookie, read one left by another app's check, get back a
+ /// validator it could make unique to this Mac, hold a connection open, or learn more than that Peel asks: the
+ /// system's own headers would tell it Peel's build, the macOS build and the person's languages.
static var configuration: URLSessionConfiguration {
let configuration = URLSessionConfiguration.ephemeral
configuration.timeoutIntervalForRequest = 15
@@ -17,6 +18,7 @@ public struct UpdateChecker: Sendable {
configuration.httpCookieAcceptPolicy = .never
configuration.urlCache = nil
configuration.requestCachePolicy = .reloadIgnoringLocalCacheData
+ configuration.httpAdditionalHeaders = ["User-Agent": "Peel", "Accept-Language": "*"]
return configuration
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdatePrivacyTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdatePrivacyTests.swift
index 12c13f9a..dfac3fc6 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdatePrivacyTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdatePrivacyTests.swift
@@ -1,3 +1,4 @@
+import Darwin
import Foundation
@testable import PeelCore
import Synchronization
@@ -17,6 +18,59 @@ 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.
+private final class OneRequestServer: Sendable {
+ let port: UInt16
+ private let headers = Mutex<[String: String]?>(nil)
+ private let answered = DispatchSemaphore(value: 0)
+
+ init() throws {
+ let listening = socket(AF_INET, SOCK_STREAM, 0)
+ var address = sockaddr_in()
+ address.sin_family = sa_family_t(AF_INET)
+ address.sin_addr.s_addr = inet_addr("127.0.0.1")
+ var length = socklen_t(MemoryLayout<sockaddr_in>.size)
+ let bound = withUnsafeMutablePointer(to: &address) {
+ $0.withMemoryRebound(to: sockaddr.self, capacity: 1) { bind(listening, $0, length) == 0 && getsockname(listening, $0, &length) == 0 }
+ }
+ guard bound, listen(listening, 1) == 0 else {
+ close(listening)
+ throw POSIXError(.EADDRNOTAVAIL)
+ }
+ port = UInt16(bigEndian: address.sin_port)
+ Thread { [self] in serve(listening) }.start()
+ }
+
+ func receivedHeaders() -> [String: String]? {
+ guard answered.wait(timeout: .now() + 10) == .success else { return nil }
+ return headers.withLock { $0 }
+ }
+
+ private func serve(_ listening: Int32) {
+ defer { close(listening) }
+ let connection = accept(listening, nil, nil)
+ guard connection >= 0 else { return }
+ defer { close(connection) }
+ var request = [UInt8]()
+ var buffer = [UInt8](repeating: 0, count: 4_096)
+ while !request.suffix(4).elementsEqual(Array("\r\n\r\n".utf8)) {
+ let count = read(connection, &buffer, buffer.count)
+ guard count > 0 else { return }
+ request += buffer[..<count]
+ }
+ let lines = String(decoding: request, as: UTF8.self).components(separatedBy: "\r\n").dropFirst()
+ headers.withLock { found in
+ found = Dictionary(lines.compactMap { line in
+ 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()
+ }
+}
+
/// Peel says it never sends the list of installed apps. Asking Apple about every app, one identifier at a time,
/// would send that list.
@Suite(.serialized) struct UpdatePrivacyTests {
@@ -38,6 +92,21 @@ private final class RecordingProtocol: URLProtocol, @unchecked Sendable {
#expect(RecordingProtocol.hosts.withLock { $0 } == ["itunes.apple.com"])
}
+ @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)
+ )
+
+ #expect(await UpdateChecker().status(for: app, preference: .developer) != .failed)
+
+ let headers = try #require(server.receivedHeaders())
+ #expect(headers["User-Agent"] == "Peel")
+ #expect(headers["Accept-Language"] == "*")
+ }
+
/// 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.md
index 6b4683a6..e080a728 100644
--- a/README.md
+++ b/README.md
@@ -237,13 +237,14 @@ it.
## Privacy
-Peel sends no analytics and has no account. On its own, it goes online only to check your apps for updates, and
-you can 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. 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.
+Peel sends no analytics and has no account. On its own, it goes online only to check your apps for updates, and you
+can 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.
<details>
<summary>Every address Peel or Homebrew may contact</summary>