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.

The helper checks who sends every message, not only who connects

Țugui Dragoșabab08b3d197
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index cb67566b..28a55a7d 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -137,7 +137,8 @@ The helper (`com.tuguidragos.Peel.Helper`) is registered with `SMAppService` whe
macOS asks the user to approve it once. It talks to the app over XPC.
- It answers administrators only, asked when a connection opens and again with each message, and it accepts
- only a copy of Peel signed by the same team. A released helper refuses a build that can be debugged.
+ only a copy of Peel signed by the same team, checked when a connection opens and for every message after it.
+ A released helper refuses a build that can be debugged.
- It does three things: moves items to the Trash, puts them back, and starts, stops, enables, or disables another
vendor's launch daemon, never one macOS ships and never itself.
- It serves a fixed list of folders (`PrivilegedPathPolicy`), refuses everything else, and refuses whatever
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8a66bfea..79e662b7 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -171,8 +171,9 @@ disk that somebody may have replaced.
- It answers administrators only, asked when a connection opens and again with each message. The account is the
connection's and says nothing about which process sent a message (`xpc_connection_create(3)`), so no rule may
rest on it for that.
-- It accepts only a copy of Peel signed by the same team, and a released helper refuses a build that can be
- debugged.
+- It accepts only a copy of Peel signed by the same team, checked when a connection opens and for every message
+ after it (`setCodeSigningRequirement` on each accepted connection), and a released helper refuses a build that
+ can be debugged.
- It never uses a path again after checking it. It holds the folder open and works through that descriptor, so
a folder swapped after the check leads nowhere.
- A new operation needs `PrivilegedPathPolicyTests`, and any change to the helper a protocol version bump,
diff --git a/PeelHelper/HelperListenerDelegate.swift b/PeelHelper/HelperListenerDelegate.swift
index 7772a7d2..7ab50135 100644
--- a/PeelHelper/HelperListenerDelegate.swift
+++ b/PeelHelper/HelperListenerDelegate.swift
@@ -3,15 +3,20 @@ import PeelPrivileged
final class HelperListenerDelegate: NSObject, NSXPCListenerDelegate {
private let lifetime: HelperLifetime
+ private let codeSigningRequirement: String
- init(lifetime: HelperLifetime) {
+ init(lifetime: HelperLifetime, codeSigningRequirement: String) {
self.lifetime = lifetime
+ self.codeSigningRequirement = codeSigningRequirement
}
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection connection: NSXPCConnection) -> Bool {
let isAdministrator = { UserAuthorization.isAdministrator(connection.effectiveUserIdentifier) }
guard lifetime.accept(isAdministrator) else { return false }
+ // The listener checks the code only when it connects; with this, a message from any other code closes the
+ // connection (`NSXPCConnection.h`), so a connection handed to another process is never served.
+ connection.setCodeSigningRequirement(codeSigningRequirement)
connection.exportedInterface = Self.interface()
connection.exportedObject = HelperService(lifetime: lifetime)
connection.invalidationHandler = { [lifetime] in
diff --git a/PeelHelper/main.swift b/PeelHelper/main.swift
index 9193b2e9..bd979353 100644
--- a/PeelHelper/main.swift
+++ b/PeelHelper/main.swift
@@ -6,12 +6,11 @@ guard let teamIdentifier = CodeSigning.currentTeamIdentifier() else {
exit(EXIT_FAILURE)
}
+let requirement = CodeSigning.requirement(identifier: HelperIdentity.appIdentifier, teamIdentifier: teamIdentifier)
let listener = NSXPCListener(machServiceName: HelperIdentity.machServiceName)
-listener.setConnectionCodeSigningRequirement(
- CodeSigning.requirement(identifier: HelperIdentity.appIdentifier, teamIdentifier: teamIdentifier)
-)
+listener.setConnectionCodeSigningRequirement(requirement)
let lifetime = HelperLifetime()
-let delegate = HelperListenerDelegate(lifetime: lifetime)
+let delegate = HelperListenerDelegate(lifetime: lifetime, codeSigningRequirement: requirement)
listener.delegate = delegate
listener.resume()
lifetime.start()
diff --git a/SAFETY.md b/SAFETY.md
index 04b3c884..5672fa38 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -273,8 +273,8 @@ to the Trash, putting them back, and starting, stopping, enabling, or disabling
is deliberately small: no shell, no arbitrary paths, and it fails closed.
- It answers administrators only, and only a copy of Peel signed by the same team. Both are checked when the
- app connects, and the account is asked again with each request, so an account that stops being an
- administrator is refused from then on.
+ app connects and again with each request, so an account that stops being an administrator is refused from
+ then on, and a message from any other program closes the connection.
- It refuses the list above on its own, without asking the app, and asks it both ways: a folder that holds
something on the list is refused like the thing itself.
- A path with a control character in it is refused. The rules read the whole name and the system stops at