Skip to content

Explore Aperitif helpers on macOS #54663

In review
In review

Description

@deepak1556

Refs ba1a24d

New set of minimal C helper and dylib that is used to early init sandbox before any system library could run.

Activity

  1. added
    upgrade-follow-up
    on Oct 6, 2026
  2. added theissue type on Oct 8, 2026
  3. jkleinsc commented on Nov 19, 2026

    @jkleinsc
    Member

    Proposed plan: move macOS helpers to Aperitif

    Chromium finished moving to Aperitif in CL 8620834 (crbug.com/40794783). It removed the kAperitifHelpers feature and the Helper (Aperitif*) bundles. Electron was already turning that feature off, so the roll needed only a compile fix (removing features::kAperitifHelpers from shell/browser/feature_list_mac.mm). Electron's helpers work exactly as before, but they still start the sandbox in main(). By then, Electron Framework's startup code and every system library's startup code have already run unsandboxed. Chromium's libaperitif.dylib starts the sandbox earlier, from its own startup code, which runs before the framework loads.

    Goal: start the sandbox in Electron's helper processes before any code from Electron Framework or system libraries runs. Helper names and child-process launch paths stay the same.

    Not in scope at first: MAS builds and the main Electron executable (see Phase 4).

    Phase 0: check that it can work (prototype, nothing lands)

    • Library validation. This is what stopped Chromium in 2022: macOS refused @-path library loading when library validation was off (crbug.com/40794783#comment19). Build one prototype helper linked to libaperitif and run it twice: signed with hardened runtime, and signed with com.apple.security.cs.disable-library-validation (common in apps that load native modules). Confirm both start and run sandboxed on the oldest and newest supported macOS versions.
    • Load order. Run otool -L on the prototype helper. libaperitif.dylib must be listed before Electron Framework. Electron currently links the framework with -framework (electron_framework_link_config in BUILD.gn). Chromium's comment says the Apple link rule puts -framework entries before all shared libraries, so the order will come out wrong.

    Phase 1: build changes (BUILD.gn)

    • Add the dependency. Add //content/public/app:aperitif to the electron_helper_app template (non-MAS only).
    • Fix the load order. Preferred: link the framework binary as an explicit input placed after libaperitif, keeping the fix that stops every framework relink from rebuilding the helpers' objects (electron_framework_link). Fallback: switch the helpers to :electron_framework+link_nested, as Chrome does, and accept the extra rebuilds.
    • Fix the library's install path. Chromium hard-codes @executable_path/../Frameworks/<Chromium> Framework.framework/Versions/<version>/Libraries/libaperitif.dylib. That doesn't match Electron's layout: Electron's helpers live in Electron.app/Contents/Frameworks/, and the framework version folder is A. Add an installnametool,-change rewrite in the helper's link flags (as is already done for libffmpeg.dylib) so the helper loads @rpath/Electron Framework.framework/Libraries/libaperitif.dylib. Check component builds, which already use @rpath/libaperitif.dylib.
    • Bundle the library. Add libaperitif.dylib to bundle_data("electron_framework_libraries") so it ships in Electron Framework.framework/Versions/A/Libraries/.
    • Remove the old dependency. Drop //sandbox/mac:seatbelt from the helper's direct dependencies; libaperitif brings it in.

    Phase 2: helper entry point (shell/app/electron_main_mac.cc)

    • Remove the code that moves into libaperitif. Delete the _NSGetExecutablePath / SeatbeltExecServer block from main(). Add a __attribute__((constructor)) that calls AperitifCheckInitialized(), as chrome/app/chrome_exe_main_mac.c does.
    • Recheck what now runs after the sandbox is on:
      • FixStdioStreams() may open /dev/null inside an already-sandboxed process. Confirm the sandbox rules allow it, or that the browser always passes valid stdio so it isn't needed.
      • ELECTRON_RUN_AS_NODE and the --type check: the sandbox only starts when seatbelt arguments are present, so both should behave as today. Add tests to prove it.
    • Optional: convert the helper to plain C to make it smaller. Low priority, since Electron's helpers are already small next to the framework.

    Phase 3: packaging, signing, release

    • Zip manifests. Add Versions/A/Libraries/libaperitif.dylib to script/zip_manifests/dist_zip.mac.{arm64,x64}.manifest.
    • Signing: confirm @electron/osx-sign signs the new dylib and that notarization passes.
    • Universal builds: confirm @electron/universal merges the arm64 and x64 copies.
    • Downstream packagers: test with Electron Forge and electron-builder.

    Phase 4: follow-ups (each a separate PR)

    • MAS builds: decide whether they adopt libaperitif. They skip seatbelt today.
    • Main executable: Chrome also switched its main executable (CL 8519057). For Electron the only gain would be early EarlyMallocZoneRegistration(), since the browser process isn't sandboxed. Measure before deciding.

    Testing

    • Build check: like Chromium's verify_dynamic_libraries, a script that asserts each helper's otool -L lists exactly libaperitif, then Electron Framework, then libSystem, in that order.
    • Specs:
      • Sandboxed renderers and the utility and GPU processes start.
      • child_process.fork() with the runAsNode fuse on and off still works.
      • An app signed without library validation can load a native module.
    • Manual: compare memory per renderer and renderer startup time before and after. Chromium reported about 10 MB less per process and roughly 10% faster renderer startup. Electron already links its framework directly, so expect a smaller gain. The main goal is the sandbox ordering.

    Risks

    Risk Mitigation
    Apps that disable library validation can't load libaperitif (the 2022 blocker) Phase 0 test; stop if it fails
    -framework link order puts the framework before libaperitif Phase 1 load-order fix, plus the otool -L build check
    Code that now runs after the sandbox starts (stdio fix) hits sandbox denials Phase 2 tests
    Third-party signing tools miss the new dylib Phase 3 checks; mention in release notes
  4. deepak1556 commented on Nov 20, 2026

    @deepak1556
    MemberAuthor

    On the right path but would like to see some improvements before landing #55962

    • Replace the C++ launcher with a thin C entry point for the browser and helpers. That removes duplicated libc++ code. Keep run-as-node fuse handling etc in the framework.
    • Keep +link_nested, but give the dylib an electron native install name instead of rewriting Chrome’s. Reuse chromium’s seatbelt code and repair stdio before applying the sandbox.
    • MAS doesn’t need Seatbelt, but EarlyMallocZoneRegistration must run once, before the framework’s allocator constructor.

    Also, keep the Mach-O link order check but locally or CI, launch a build with DYLD_PRINT_INITIALIZERS=1 open a sandboxed window, in both browser and renderer, confirm apertif dylib initializes before framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    upgrade-follow-up

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions