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.

Say what the helper's administrator check really covers

Țugui Dragoș19183f39d073
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 5b89b073..bda854e3 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -20,7 +20,7 @@ flowchart LR
Finder["Finder extension<br>sandboxed"] -- "peel://open" --> App["Peel.app<br>runs as you"]
CLI["peel command<br>runs as you"] --> Core["PeelCore<br>scans, matches, moves"]
App --> Core
- App -- "XPC, checked on every message" --> Helper["Helper<br>runs as root"]
+ App -- "XPC, administrators only" --> Helper["Helper<br>runs as root"]
Core --> Privileged["PeelPrivileged<br>what may be touched"]
Helper --> Privileged
```
@@ -128,8 +128,8 @@ A handful of ideas carry most of the weight. Each is enforced in one place and t
The helper (`com.tuguidragos.Peel.Helper`) is registered with `SMAppService` when the user asks for it, and
macOS asks the user to approve it once. It talks to the app over XPC.
-- On every message it checks that the caller is an administrator, and it accepts only a copy of Peel signed by
- the same team. A released helper refuses a build that can be debugged.
+- 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.
- 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 074de8bb..b5aabb46 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -163,8 +163,9 @@ Tests enforce these. If your change makes one of them fail, the rule is right an
disk that somebody may have replaced.
- It has no shell, accepts no path outside the folders it serves, and refuses whenever it is unsure.
-- It answers administrators only, and checks that on **every message**, not once per connection:
- `xpc_connection_create(3)` explains why a check made when the connection opens can be worked around.
+- 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 never uses a path again after checking it. It holds the folder open and works through that descriptor, so
diff --git a/PeelHelper/HelperListenerDelegate.swift b/PeelHelper/HelperListenerDelegate.swift
index 2fc409a2..814dc8f1 100644
--- a/PeelHelper/HelperListenerDelegate.swift
+++ b/PeelHelper/HelperListenerDelegate.swift
@@ -9,8 +9,6 @@ final class HelperListenerDelegate: NSObject, NSXPCListenerDelegate {
}
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection connection: NSXPCConnection) -> Bool {
- // An early refusal only. The check that matters runs on every message, in `HelperService.caller()`,
- // because a client can hand its connection's Mach port to a process with other credentials.
guard UserAuthorization.isAdministrator(connection.effectiveUserIdentifier) else { return false }
connection.exportedInterface = Self.interface()
diff --git a/PeelHelper/HelperService.swift b/PeelHelper/HelperService.swift
index 85b20bc4..43c50719 100644
--- a/PeelHelper/HelperService.swift
+++ b/PeelHelper/HelperService.swift
@@ -20,10 +20,10 @@ final class HelperService: NSObject, PeelHelperProtocol {
let homeDirectory: String
}
- /// The account that sent the message being handled, and its home folder. Nil when that account is not an
- /// administrator or its home folder cannot be found. It is read for every message, not once per
- /// connection, because `xpc_connection_create(3)` warns that a client of a launchd Mach service like this
- /// one can hand its connection's Mach port to a process with other credentials.
+ /// The account behind the connection the message came on, and its home folder. Nil when that account is not
+ /// an administrator or its home folder cannot be found. It is asked for each message, so an account that stops
+ /// being an administrator is refused from its next request. It says whose connection it is, not which process
+ /// sent the message: `xpc_connection_create(3)` warns that a client can hand its connection to another process.
private static func caller() -> Caller? {
guard
let user = NSXPCConnection.current()?.effectiveUserIdentifier,
diff --git a/SAFETY.md b/SAFETY.md
index fd8576c7..50741eb6 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -260,8 +260,9 @@ Peel installs a helper for the few things that need administrator rights: moving
to the Trash, putting them back, and starting, stopping, enabling, or disabling another vendor's launch daemon. It
is deliberately small: no shell, no arbitrary paths, and it fails closed.
-- It answers administrators only, and it checks that on **every message**, because a check made once when
- the connection opens can be walked around by handing the connection's port to another process.
+- 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.
- 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