opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Desktop (macOS): main executable uses Electron's stock LC_UUID, causing Local Network permission collisions with other Electron apps

Open eric1932 opened this issue 1 week ago • 2 comments

Summary

OpenCode Desktop 2.3.2 (ai.opencode.desktop, arm64 build) ships Electron 44.9.1's main executable unchanged. Its LC_UUID (the Mach-O load command that gives a binary its build UUID) is 4C4C447A-5555-3144-A121-6E56C3462D63—identical to every other arm64 app built on Electron 44.9.1.

macOS Local Network privacy identifies apps by this UUID. As Apple's TN3179 warns, a main executable sharing its UUID with other programs causes Local Network privacy to "behave weirdly".

This collision cuts both ways:

  • OpenCode can break other Electron 44.9.1 apps, preventing them from being prompted for Local Network access or appearing in System Settings.
  • Other Electron 44.9.1 apps can break OpenCode Desktop's own LAN access (such as "Add SSH server", which spawns ssh), leaving it tied to a decision made for another vendor's app. This may explain #63815 ("Add SSH server" fails when OpenCode is launched from the Dock, the spawned ssh is blocked with "Local network prohibited", and OpenCode is missing from Local Network settings).

Observed behavior

On my Mac, OpenCode collided with Antigravity 2.34.0 (com.google.antigravity, Google's Electron-based IDE, also on Electron 44.9.1). In chronological order:

  1. Blocked without a prompt: OpenCode's rule in /Library/Preferences/com.apple.networkextension.plist was "allowed", while Antigravity's rule was undetermined (which macOS treats as denied). Antigravity never got a Local Network prompt, and all of its LAN connections failed with EHOSTUNREACH.

    Checking UserEventAgent logs:

    log show --predicate 'process == "UserEventAgent" AND eventMessage BEGINSWITH "LocalNetwork:"'
    

    On every blocked connection, UserEventAgent first resolved the right app by PID and then the wrong one by UUID:

    • found bundle id com.google.antigravity by PID
    • found bundle id ai.opencode.desktop by UUID 4C4C447A-…

    OpenCode's "allowed" decision did not carry over to Antigravity, yet its existing decision prevented Antigravity from ever being prompted.

  2. Workaround: Moving OpenCode out of /Applications and unregistering it from LaunchServices caused the UUID to resolve to Antigravity. Antigravity then received its Local Network prompt, and allowing it fixed Antigravity.

  3. Mismatched rule after re-registering OpenCode: When I put OpenCode back and re-registered it, macOS rebuilt its UUID mapping. Ten seconds later, a LAN connection from Antigravity triggered a Local Network prompt labelled "OpenCode". Accepting it created a second rule in /Library/Preferences/com.apple.networkextension.plist with:

    • SigningIdentifier = ai.opencode.desktop
    • Path = /Applications/Antigravity.app/Contents/MacOS/Antigravity

    (At that point both OpenCode and Antigravity already had "allowed" rules; I don't know why macOS prompted again.)

  4. Missing from System Settings: Throughout, System Settings → Privacy & Security → Local Network showed only a single "OpenCode" row for the shared UUID. Antigravity was never listed, even after its own rule became "allowed".

Steps to reproduce

  1. Install OpenCode Desktop 2.3.2 (arm64) and any other arm64 app built on Electron 44.9.1.
  2. Verify that both main executables share the stock Electron UUID:
    dwarfdump --uuid /Applications/OpenCode.app/Contents/MacOS/OpenCode
    
    This prints 4C4C447A-5555-3144-A121-6E56C3462D63 (arm64), the same as the other app's main executable.
  3. Allow Local Network access for OpenCode (accept its prompt the first time it connects to a LAN host, e.g. via "Add SSH server" with a LAN address), then have the other app connect to a LAN host. It receives no prompt and fails with EHOSTUNREACH.

(Note: For step 3, this was the state I encountered on my Mac rather than a reproduction from a clean install.)

Suggested fix

OpenCode Desktop is packaged with electron-builder (packages/desktop/electron-builder.config.ts). In an afterPack hook, before code signing, rewrite the 16-byte LC_UUID payload of Contents/MacOS/OpenCode with a unique value—for example, derived from the bundle ID as proposed in electron/electron#55101.

The author of electron/electron#55101 verified this on a copy of Electron.app where only the main executable's LC_UUID was patched and then signed ad hoc: macOS prompted for that copy separately, and codesign --verify --deep --strict passed.

Additional note: OpenCode's Info.plist currently does not set NSLocalNetworkUsageDescription. Adding it won't fix the UUID collision, but it lets the Local Network prompt explain to users why OpenCode needs LAN access.

Upstream: electron/electron#55101, electron-userland/electron-builder#10297

Environment

  • OS: macOS 26.7.3 (25G342), Apple Silicon
  • App: OpenCode Desktop 2.3.2 (Electron 44.9.1, arm64)

eric1932 avatar Nov 23 '26 08:11 eric1932

Thanks for the detailed write-up. I confirmed the root cause on the released 2.3.2 build. I took the main executable from the official opencode-desktop-mac-arm64.app.tar.gz and Electron's stock electron-v44.9.1-darwin-arm64.zip, then read each one's Mach-O LC_UUID. Both are 4C4C447A-5555-3144-A121-6E56C3462D63 (arm64). The bundle's Info.plist (ai.opencode.desktop) also has no NSLocalNetworkUsageDescription. The script below does the comparison and runs on any OS.

My test environment is Linux, so I couldn't observe the Local Network permission mix-up on macOS itself, only the shared UUID that causes it.

I did not build the latest dev (1906056), but its source still pins Electron 44.9.1. The packaging step (afterPack in packages/desktop/electron-builder.config.ts) only copies the app icon on macOS and doesn't change the main executable's UUID, so it most likely still happens there.

Related: #63815 (Add SSH server blocked with "Local network prohibited", OpenCode missing from Local Network settings), which this may partly explain.

Reproduction script (lc_uuid.py)
#!/usr/bin/env python3
"""Compare the Mach-O LC_UUID of OpenCode Desktop's macOS main executable with
the stock Electron main executable of the same Electron version.

Usage: python3 lc_uuid.py [opencode_version] [electron_version]
Downloads:
  https://github.com/anomalyco/opencode/releases/download/v<ver>/opencode-desktop-mac-arm64.app.tar.gz
  https://github.com/electron/electron/releases/download/v<ever>/electron-v<ever>-darwin-arm64.zip
"""
import io, os, struct, sys, tarfile, urllib.request, uuid, zipfile, plistlib

OC = sys.argv[1] if len(sys.argv) > 1 else "2.3.2"
EL = sys.argv[2] if len(sys.argv) > 2 else "44.9.1"
WORK = os.path.join(os.path.dirname(os.path.abspath(__file__)), "dl")
os.makedirs(WORK, exist_ok=True)

def fetch(url, name):
    p = os.path.join(WORK, name)
    if not os.path.exists(p):
        print("downloading", url)
        urllib.request.urlretrieve(url, p)
    return p

def lc_uuids(data):
    """Return [(cputype, uuid)] for a thin or fat Mach-O."""
    magic = struct.unpack(">I", data[:4])[0]
    if magic in (0xCAFEBABE, 0xCAFEBABF):
        n = struct.unpack(">I", data[4:8])[0]
        out, off = [], 8
        for _ in range(n):
            if magic == 0xCAFEBABE:
                cpu, _, o, sz, _ = struct.unpack(">iiIII", data[off:off+20]); off += 20
            else:
                cpu, _, o, sz, _, _ = struct.unpack(">iiQQII", data[off:off+32]); off += 32
            out += lc_uuids(data[o:o+sz])
        return out
    m = struct.unpack("<I", data[:4])[0]
    assert m == 0xFEEDFACF, hex(m)
    cpu, _, _, ncmds, _, _, _ = struct.unpack("<iiIIIII", data[4:32])
    off = 32
    for _ in range(ncmds):
        cmd, size = struct.unpack("<II", data[off:off+8])
        if cmd == 0x1B:  # LC_UUID
            return [(cpu, str(uuid.UUID(bytes=data[off+8:off+24])).upper())]
        off += size
    return [(cpu, None)]

oc = fetch(f"https://github.com/anomalyco/opencode/releases/download/v{OC}/opencode-desktop-mac-arm64.app.tar.gz", f"oc-{OC}.tar.gz")
el = fetch(f"https://github.com/electron/electron/releases/download/v{EL}/electron-v{EL}-darwin-arm64.zip", f"el-{EL}.zip")

with tarfile.open(oc) as t:
    oc_bin = t.extractfile("OpenCode.app/Contents/MacOS/OpenCode").read()
    info = plistlib.loads(t.extractfile("OpenCode.app/Contents/Info.plist").read())
with zipfile.ZipFile(el) as z:
    el_bin = z.read("Electron.app/Contents/MacOS/Electron")

a, b = lc_uuids(oc_bin), lc_uuids(el_bin)
print(f"OpenCode {OC} Contents/MacOS/OpenCode LC_UUID: {a}")
print(f"Electron {EL} Contents/MacOS/Electron LC_UUID: {b}")
print("CFBundleIdentifier:", info.get("CFBundleIdentifier"))
print("NSLocalNetworkUsageDescription:", info.get("NSLocalNetworkUsageDescription"))
print("SAME UUID (bug)" if [u for _, u in a] == [u for _, u in b] else "different UUIDs")

Run it: python3 lc_uuid.py

opencodejr[bot] avatar Nov 23 '26 08:11 opencodejr[bot]

Hi! I'm already working on #66537 (PR #66545), and I would like to help here too. I opened PR #66546: in afterPack the build now changes the LC_UUID of the main executable, so OpenCode does not share it with other Electron apps. I tested it with the real Electron 44.9.1 arm64 binary and the signature still works. I did not run a full signed build, so please tell me if something is missing.

Mats2208 avatar Nov 26 '26 15:11 Mats2208