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
Check an Electron app that updates from storage at the address it writes
Țugui Dragoș5667599b9a9b
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/ElectronUpdater.swift b/Packages/PeelCore/Sources/PeelCore/Updates/ElectronUpdater.swiftindex 55855eb1..6e920fd6 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/ElectronUpdater.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/ElectronUpdater.swift@@ -39,9 +39,36 @@ enum ElectronUpdater {guard fields["host"] == nil || fields["host"] == "github.com" else { return nil }guard let owner = fields["owner"], let repository = fields["repo"] else { return nil }return URL(string: "https://github.com/\(owner)/\(repository)/releases/latest/download/\(file)")+ case "s3", "r2":+ guard let base = storageAddress(in: fields), let url = URL(string: base), url.scheme == "https",+ url.host() != nil+ else { return nil }+ return url.appending(path: file)+ default:+ return nil+ }+ }++ /// The address electron-updater asks a storage service at (`getS3LikeProviderBaseUrl`), only when the app writes it+ /// whole: an S3 `endpoint`, or an R2 bucket's `publicUrl`. Any other address is one electron-updater builds itself,+ /// and R2's S3 endpoint always asks for credentials, so no app can update from it.+ private static func storageAddress(in fields: [String: String]) -> String? {+ let base: String+ switch fields["provider"] {+ case "s3":+ guard fields["accelerate"] != "true", let endpoint = fields["endpoint"], let bucket = fields["bucket"],+ URL(string: endpoint)?.host()?.lowercased().hasSuffix(".r2.cloudflarestorage.com") == false+ else { return nil }+ base = "\(endpoint)/\(bucket)"+ case "r2":+ guard fields["bucket"] != nil, fields["accountId"] != nil, let publicURL = fields["publicUrl"]+ else { return nil }+ base = publicURL.hasSuffix("/") ? String(publicURL.dropLast()) : publicURLdefault:return nil}+ guard let path = fields["path"] else { return base }+ return base + (path.hasPrefix("/") ? "" : "/") + path}static func version(fromFeed text: String) -> String? {diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swiftindex 13373997..b0bf7024 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift@@ -4,7 +4,7 @@ import Synchronizationpublic struct UpdateChecker: Sendable {/// Raised whenever the checker answers some apps differently: an app an earlier revision couldn't check is asked/// again rather than waited out, and so is one this revision asks nobody about (`UpdateMemory.recalled`).- public static let revision = 4+ public static let revision = 5/// The largest reply read. An update feed is a small XML, YAML, or JSON file, and its address comes from/// the app's own bundle, so the server is not trusted to keep its reply small.diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swiftindex 7b0f5d6e..306134fc 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift@@ -284,7 +284,6 @@ struct ElectronUpdaterTests {#expect(ElectronUpdater.feedURL(fromConfiguration: github)?.absoluteString == "https://github.com/example/tool/releases/latest/download/beta-mac.yml")#expect(ElectronUpdater.feedURL(fromConfiguration: "provider: generic\nurl: http://insecure.example.com/\n") == nil)- #expect(ElectronUpdater.feedURL(fromConfiguration: "provider: s3\nbucket: example\n") == nil)// An app that updates from a company's own GitHub server names it with `host`. Asking github.com// instead would send its owner and repository to a server they were never meant for.@@ -292,6 +291,28 @@ struct ElectronUpdaterTests {#expect(ElectronUpdater.feedURL(fromConfiguration: "provider: github\nhost: github.com\nowner: example\nrepo: tool\n") != nil)}+ @Test func asksAStorageServiceOnlyAtAnAddressTheAppWritesWhole() {+ func feed(_ configuration: String) -> String? {+ ElectronUpdater.feedURL(fromConfiguration: configuration)?.absoluteString+ }+ let endpoint = "provider: s3\nbucket: marxist-updates\nendpoint: https://s3.nl-ams.scw.cloud\nregion: nl-ams\n"+ #expect(feed(endpoint) == "https://s3.nl-ams.scw.cloud/marxist-updates/latest-mac.yml")+ let withPath = "provider: s3\nbucket: example\nendpoint: https://storage.example.com\npath: /releases\nchannel: beta\n"+ #expect(feed(withPath) == "https://storage.example.com/example/releases/beta-mac.yml")+ let r2 = "provider: r2\nbucket: example\naccountId: 0123abcd\npublicUrl: https://pub-0123abcd.r2.dev/\npath: updates\n"+ #expect(feed(r2) == "https://pub-0123abcd.r2.dev/updates/latest-mac.yml")++ #expect(feed("provider: s3\nbucket: example\n") == nil)+ #expect(feed("provider: s3\nbucket: example\nendpoint: https://storage.example.com\naccelerate: true\n") == nil)+ #expect(feed("provider: spaces\nname: example\nregion: nyc3\n") == nil)+ #expect(feed("provider: r2\nbucket: example\naccountId: 0123abcd\n") == nil)+ #expect(feed("provider: r2\naccountId: 0123abcd\npublicUrl: https://pub-0123abcd.r2.dev\n") == nil)+ #expect(feed("provider: s3\nbucket: chatbox\nendpoint: https://0123abcd.r2.cloudflarestorage.com\npath: /releases\n") == nil)+ #expect(feed("provider: s3\nbucket: example\nendpoint: https://0123abcd.eu.r2.cloudflarestorage.com\n") == nil)+ #expect(feed("provider: s3\nbucket: example\nendpoint: http://storage.example.com\n") == nil)+ #expect(feed("provider: r2\nbucket: example\naccountId: 0123abcd\npublicUrl: http://pub.example.com\n") == nil)+ }+@Test func offersOnlyWhatElectronUpdaterWouldOfferThisMac() throws {let darwin = "25.6.0"func offered(_ fields: String, id: String? = nil) -> Bool {