From e6c108194888d4b0c63e0e4277d31796c0732067 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Thu, 29 Oct 2026 17:46:09 +1100 Subject: [PATCH 1/2] fix: verify helper code signature before bootstrapping dev daemon The dev helper upsert script blindly bootstrapped whatever binary sat in the installed bundle. A stale or ad-hoc-signed helper (left behind when Xcode skips the CodeSignOnCopy embed phase, or when a build with code signing disabled writes into the installed bundle) would be installed silently, and only surface later as cryptic errSecCSReqFailed (-67050) XPC connection failures. Now the script verifies the helper against the app's XPC peer code signing requirement before installing it, failing the build loudly with remediation steps on mismatch. --- scripts/upsert-dev-helper.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/upsert-dev-helper.sh b/scripts/upsert-dev-helper.sh index c7f42828..b33aa71c 100755 --- a/scripts/upsert-dev-helper.sh +++ b/scripts/upsert-dev-helper.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash # This script operates like postinstall + preinstall, but for local development # builds, where the helper is necessary. Instead of looking for # /Applications/Coder Desktop.app, it looks for @@ -12,6 +13,31 @@ LAUNCH_DAEMON_NAME="com.coder.Coder-Desktop.Helper" LAUNCH_DAEMON_PLIST_NAME="$LAUNCH_DAEMON_NAME.plist" LAUNCH_DAEMON_BINARY_PATH="/Applications/Coder/Coder Desktop.app/Contents/MacOS/com.coder.Coder-Desktop.Helper" +# Must match `Validator.xpcPeerRequirement` in Coder-Desktop/VPNLib/Validate.swift. +XPC_PEER_REQUIREMENT='anchor apple generic and certificate leaf[subject.OU] = "4399GN35BJ"' + +if [ ! -f "$LAUNCH_DAEMON_BINARY_PATH" ]; then + echo "error: helper binary not found at '$LAUNCH_DAEMON_BINARY_PATH'." >&2 + echo "Build the 'Coder Desktop' app target first so it installs to /Applications/Coder." >&2 + exit 1 +fi + +# Refuse to install a helper the app will reject over XPC. The app validates +# XPC peers against this requirement; bootstrapping a helper that fails it +# only surfaces later as cryptic 'errSecCSReqFailed' (-67050) connection +# errors. A stale or ad-hoc-signed helper can end up in the installed bundle +# when Xcode skips the "Embed Dependencies" (CodeSignOnCopy) phase, or when a +# build with code signing disabled (e.g. `make test`) writes into it. +if ! codesign --verify --strict -R="$XPC_PEER_REQUIREMENT" "$LAUNCH_DAEMON_BINARY_PATH"; then + echo "error: '$LAUNCH_DAEMON_BINARY_PATH' does not satisfy the app's XPC peer code signing requirement:" >&2 + echo " $XPC_PEER_REQUIREMENT" >&2 + codesign --display --verbose=2 "$LAUNCH_DAEMON_BINARY_PATH" >&2 || true + echo "The installed helper is likely stale or ad-hoc signed. To fix, delete it and rebuild:" >&2 + echo " rm '$LAUNCH_DAEMON_BINARY_PATH'" >&2 + echo "then rebuild the 'Coder Desktop' target so the embed phase re-copies and re-signs the helper." >&2 + exit 1 +fi + # Stop an existing launch daemon, if it exists sudo launchctl bootout "system/$LAUNCH_DAEMON_NAME" 2>/dev/null || true From a9a6a082818bce57cee66143568553df9b37c6d3 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Mon, 9 Nov 2026 17:11:20 +1100 Subject: [PATCH 2/2] fix: skip dev helper install for signing-free builds A signing-free build (e.g. `make test`, which passes CODE_SIGNING_ALLOWED=NO) can't produce a helper the app will accept over XPC, so there's no point bootstrapping one as a root daemon (and prompting for an admin password). Previously this silently replaced the installed helper with an ad-hoc signed one, breaking app<->helper XPC. --- Coder-Desktop/project.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Coder-Desktop/project.yml b/Coder-Desktop/project.yml index 7833a810..a821a112 100644 --- a/Coder-Desktop/project.yml +++ b/Coder-Desktop/project.yml @@ -236,6 +236,11 @@ targets: # Skip in CI exit 0 fi + if [ "${CODE_SIGNING_ALLOWED}" = "NO" ]; then + # Signing-free builds (e.g. `make test`) can't produce a helper + # the app will accept over XPC, so don't install one. + exit 0 + fi /usr/bin/osascript <<'APPLESCRIPT' do shell script "/bin/bash -c " & quoted form of ((system attribute "SRCROOT") & "/../scripts/upsert-dev-helper.sh") with administrator privileges APPLESCRIPT