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
Never move what macOS keeps under Apple's name in the Mac's Library
Țugui Dragoș0b486195f542
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift b/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swiftindex c0af3c44..e2749b3d 100644--- a/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift+++ b/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift@@ -7,7 +7,7 @@ public enum HelperIdentity {public static let launchdPlistName = "com.tuguidragos.Peel.Helper.plist"/// Raise it whenever the helper changes, so Peel never works with a helper of another version. The helper/// refuses requests that carry any other version.- public static let protocolVersion = 21+ public static let protocolVersion = 22}/// The complete set of privileged operations. The helper validates every argument itself.diff --git a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swiftindex f4cf5028..543aedcf 100644--- a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift+++ b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift@@ -227,10 +227,17 @@ public enum ProtectedData: Sendable {".gitconfig", ".gitignore_global", ".netrc", ".npmrc",]- /// Folders outside any home that hold work nothing can bring back, for every account on the Mac.- public static let systemFolders = ["/Library/Keychains"]+ /// Folders outside any home that hold what nothing can bring back, for every account on the Mac: the system+ /// keychains, and the Mac's network settings, which the System Configuration framework keeps there.+ public static let systemFolders = ["/Library/Keychains", "/Library/Preferences/SystemConfiguration"]private static let systemFolderNames = systemFolders.map { PathComponents.of($0.lowercased()) }+ /// The folders of the Mac's own `/Library` where macOS keeps its settings and jobs under Apple's name, beside+ /// every vendor's. Lowercase.+ private static let macOSsOwnLibraryFolders: Set<String> = [+ "preferences", "launchdaemons", "launchagents", "privilegedhelpertools", "application support",+ ]+/// True for a name Apple writes for its own things: `com.apple.` after an optional team and an optional/// `group.`, `groups.`, or `systemgroup.`.public static func isApplesName(_ name: String) -> Bool {@@ -245,6 +252,13 @@ public enum ProtectedData: Sendable {return name.hasPrefix("com.apple.")}+ /// True at or inside an item named as Apple names its own, directly in one of `macOSsOwnLibraryFolders`: a+ /// setting or a job of macOS itself, which nothing but macOS makes again. Not an account's own Library, where such+ /// a file holds the account's settings for an Apple app, which a reset clears. Expects the names lower-cased.+ private static func isMacOSsOwnInLibrary(_ names: [String]) -> Bool {+ names.count > 2 && names[0] == "library" && macOSsOwnLibraryFolders.contains(names[1]) && isApplesName(names[2])+ }+/// True at or inside one of Apple's own group containers, where the system's apps keep the user's data,/// such as notes, reminders, recordings, and calendars. Apple moves them between releases, so they are/// recognized by the shape of their name, not by a list. Expects the path in lowercase.@@ -556,7 +570,8 @@ public enum ProtectedData: Sendable {}/// True for a path at or inside anything protected here: the home and system folders, the keys, a wallet- /// extension's storage, a media library, a global preferences file, or one of Apple's group containers.+ /// extension's storage, a media library, a global preferences file, one of Apple's group containers, or what+ /// macOS keeps under Apple's name in `/Library`./// Running as root, the helper can see every account on the Mac, so a home folder is any folder directly/// inside `/Users`, as well as the one given.public static func refuses(_ path: String, home: String) -> Bool {@@ -568,7 +583,9 @@ public enum ProtectedData: Sendable {spellings.contains { spelling inlet names = PathComponents.of(spelling)if names.contains(where: isALibrary) || isInADisksTrash(names) { return true }- if isGlobalPreferences(spelling) || isInAnApplesGroupContainer(names) { return true }+ if isGlobalPreferences(spelling) || isInAnApplesGroupContainer(names) || isMacOSsOwnInLibrary(names) {+ return true+ }if isInsideAWalletExtension(names) { return true }for home in homes(of: names, given: home) where trees(under: home).contain(names) {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackHelperPolicyTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackHelperPolicyTests.swiftindex e3abffd8..c04cf4ba 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackHelperPolicyTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackHelperPolicyTests.swift@@ -158,6 +158,28 @@ struct AttackHelperPolicyTests {let resolved = try #require(try? policy(directory).open(disguised).get())#expect(resolved.path.hasSuffix("/Library/Caches/thing.db"), "realpath did not canonicalize the case")}++ /// macOS keeps the Mac's own settings and jobs under Apple's name in `/Library`, beside every vendor's, and+ /// nothing but macOS makes them again, so the helper refuses them by name, before anything is opened.+ @Test func theHelperRefusesWhatMacOSKeepsUnderApplesNameInTheMacsLibrary() {+ let policy = PrivilegedPathPolicy(homeDirectory: NSHomeDirectory())+ let macOSs = [+ "/Library/Preferences/com.apple.example.plist",+ "/Library/Preferences/SystemConfiguration",+ "/Library/Preferences/SystemConfiguration/preferences.plist",+ "/Library/LaunchDaemons/com.apple.example.plist",+ "/Library/LaunchAgents/com.apple.example.plist",+ "/Library/PrivilegedHelperTools/com.apple.example",+ "/Library/Application Support/com.apple.example/Settings.plist",+ ]+ for path in macOSs {+ #expect(policy.refusal(of: path) == .irreplaceable, "ATTACK SUCCEEDED: the helper would move \(path)")+ }+ let vendors = ["/Library/Preferences/org.example.vendor.plist", "/Library/LaunchDaemons/org.example.vendor.plist"]+ for path in vendors {+ #expect(policy.refusal(of: path) == nil, "\(path) refused")+ }+ }}extension AttackHelperPolicyTests {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swiftindex b8565242..b640140f 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift@@ -968,4 +968,36 @@ struct AttackRemovalGuardTests {#expect(excluding.refusal(of: url) == .couldNotLookInside)#expect(RemovalGuard(environment: environment).refusal(of: url) == nil, "with no app excluded, the helper looks")}++ /// The Mac's own settings and jobs, which nothing but macOS makes again; the account's own settings for Apple's+ /// apps, which a reset clears, and macOS's caches, which come back on their own, are another matter.+ @Test func whatMacOSKeepsUnderApplesNameInTheMacsLibraryStays() throws {+ let directory = try TemporaryDirectory()+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let guardian = RemovalGuard(+ environment: SearchEnvironment(homeDirectory: home, rootDirectory: directory.url.appending(path: "root"))+ )+ let homePath = home.path(percentEncoded: false)++ let macOSs = [+ "/Library/Preferences/com.apple.example.plist",+ "/Library/Preferences/SystemConfiguration/preferences.plist",+ "/Library/LaunchDaemons/com.apple.example.plist",+ "/Library/LaunchAgents/com.apple.example.plist",+ "/Library/PrivilegedHelperTools/com.apple.example",+ "/Library/Application Support/com.apple.example/Settings.plist",+ ]+ for path in macOSs {+ #expect(guardian.refusal(of: URL(filePath: path)) == .protectedLocation, "\(path) would move")+ #expect(ProtectedData.refuses(path, home: homePath), "\(path) not refused")+ }+ let others = [+ URL(filePath: "/Library/Preferences/org.example.vendor.plist"),+ URL(filePath: "/Library/Caches/com.apple.example"),+ home.appending(path: "Library/Preferences/com.apple.example.plist"),+ ]+ for url in others {+ #expect(guardian.allowsRemoval(of: url), "\(url.path(percentEncoded: false)) refused")+ }+ }}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swiftindex 6ff749d9..ec4c9889 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift@@ -1310,4 +1310,11 @@ struct PackageReceiptsTests {#expect(names == ["org.example.word", "org.example.excel", "Tool", "org.example.plain"])}++ @Test func neverOffersWhatMacOSKeepsUnderApplesName() {+ let files = ["Library/Preferences/com.apple.example.plist", "Library/Preferences/org.example.vendor.plist"]+ let found = PackageReceipts.topLevel(files: files, installLocation: "/", exists: { _ in true })+ #expect(found.onDisk == files.map { "/" + $0 })+ #expect(found.offered == ["/Library/Preferences/org.example.vendor.plist"])+ }}diff --git a/SAFETY.md b/SAFETY.mdindex 090cb31a..3350f690 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -73,13 +73,18 @@ Integrity Protection guards, which macOS marks as restricted, is refused as wellso is anything macOS marks so that nothing can remove or rename it, such as the private folders it makes in yourtemporary folder for the processes it runs in a sandbox; Peel doesn't list those.-Everywhere on the Mac: `/Library/Keychains`, the Trash macOS keeps at the top of every disk (`/.Trashes` and-`/Volumes/<disk>/.Trashes`), whose contents are already on their way out, as your own `.Trash`'s are, and any-`.photoslibrary`, `.photolibrary`, `.migratedphotolibrary`, `.musiclibrary`, `.tvlibrary`, `.imovielibrary`,-`.fcpbundle`, or `.aplibrary`: somebody's whole photo, music, or video collection. A folder with one of them a level or-two inside stays too, since moving the folder would take the library along, and the row says so instead of failing when-you press the button. A browser profile with a wallet in it stays the same way, and so does a folder that holds one a-level or two down: see [Crypto wallets](#crypto-wallets).+Everywhere on the Mac: `/Library/Keychains`, the Mac's network settings in `/Library/Preferences/SystemConfiguration`,+the Trash macOS keeps at the top of every disk (`/.Trashes` and `/Volumes/<disk>/.Trashes`), whose contents are already+on their way out, as your own `.Trash`'s are, and any `.photoslibrary`, `.photolibrary`, `.migratedphotolibrary`,+`.musiclibrary`, `.tvlibrary`, `.imovielibrary`, `.fcpbundle`, or `.aplibrary`: somebody's whole photo, music, or video+collection. A folder with one of them a level or two inside stays too, since moving the folder would take the library+along, and the row says so instead of failing when you press the button. A browser profile with a wallet in it stays+the same way, and so does a folder that holds one a level or two down: see [Crypto wallets](#crypto-wallets). What+macOS keeps under Apple's own name (`com.apple.`) directly in `/Library/Preferences`, `/Library/LaunchDaemons`,+`/Library/LaunchAgents`, `/Library/PrivilegedHelperTools`, or `/Library/Application Support`, such as+`com.apple.loginwindow.plist`, stays as well: the Mac's own settings and jobs, which nothing but macOS makes again. Your+account's own settings for Apple's apps, in `~/Library/Preferences`, are yours: resetting an app clears them, after+saving a copy.Anything that syncs to your other devices stays too, wherever it is: what iCloud or another cloud service keeps, such aswhat is on your Desktop and in Documents when they are in iCloud Drive, and what is in a folder Syncthing, Resilio Sync,