Skip to content

feat: validate integrity of ASAR Integrity dictionary on macOS - #48587

Merged
MarshallOfSound merged 7 commits into
electron:mainfrom
nmggithub:main
Nov 14, 2025
Merged

MarshallOfSound merged 7 commits into
electron:mainfrom
nmggithub:main

Conversation

@nmggithub

@nmggithub nmggithub commented Oct 18, 2025 •

Copy link
Copy Markdown
Contributor

Description of Change

cc @MarshallOfSound

This closes up a potential risk where an attacker with access to the App Management or Full Disk Access TCC services tampers with both the app.asar archive and the Info.plist for an app. I have found, through practice, that doing so does not always render the app un-launchable and can essentially bypass ASAR Integrity (however upon reboot, the app will fail to launch). All signs point to Gatekeeper (or some related functionality) caching validation results in a cache that is invalidated upon reboot.

Due to this risk, I believe it is important to do our own validation on launch right before we check the hashes. An alternative mitigation, storing the hashes inside the main executable so they inherit the protections of the executable's code signature, was deemed infeasible due to the flimsiness of injecting new content into an already-built Mach-O binary (the state in which Electron is delivered to end developers in most cases).

UPDATE: The executable is now used as part of this additional layer of security. The above and below stricken text is no longer relevant.

The validation is performed with the flags: kSecCSBasicValidateOnly | kSecCSNoNetworkAccess. These were chosen in order to minimize the validation overhead. Even under a basic validation, any tampering of Info.plist will be caught and an errSecCSInfoPlistFailed error code will be returned. As the hypothetical compromise above requires the tampering of Info.plist, a basic validation is a sufficient mitigation. The kSecCSNoNetworkAccess flag is used to ensure the validation does not perform any network I/O (unneeded for the validation we're performing).

Overall, when testing this validation code in isolation on my machine, I find it takes around 20 milliseconds. I personally believe this will have a negligible-to-nonexistent impact on user experience.

Checklist

  • PR description included and stakeholders cc'd

Release Notes

Notes: Added additional defence against privileged user modifications to ASAR Integrity protected applications on macOS

@welcome

welcome Bot commented Oct 18, 2025

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

Semantic PR titles

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Commit signing

This repo enforces commit signatures for all incoming PRs.
To sign your commits, see GitHub's documentation on Telling Git about your signing key.

PR tips

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Oct 18, 2025
Comment thread shell/common/mac/codesign_util.cc Resolved
Comment thread shell/common/mac/codesign_util.cc Resolved

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the idea of embedded the integrity dict in the data section of the binary?

@nmggithub

Copy link
Copy Markdown
Contributor Author

What happened to the idea of embedded the integrity dict in the data section of the binary?

To restate what I wrote in my original post:

An alternative mitigation, storing the hashes inside the main executable so they inherit the protections of the executable's code signature, was deemed infeasible due to the flimsiness of injecting new content into an already-built Mach-O binary (the state in which Electron is delivered to end developers in most cases).

Since end app developers aren't building Electron from source each time, I would have to write code to parse through the Electron executable, copy out the data, allocate some space in the middle for the hashes, parse through the header and add the correct load commands (and also fix up the existing load commands). That feels extremely flimsy to me, and, form past experience, I've found macOS's code-signing infrastructure tends not to be happy with such edits.

@MarshallOfSound

Copy link
Copy Markdown
Member

was deemed infeasible due to the flimsiness of injecting new content into an already-built Mach-O binary (the state in which Electron is delivered to end developers in most cases).

We already kinda do this with Electron Fuses.

The 20ms hit isn't awful but I'd love to avoid it if possible. Is that 20ms on every launch (even with theoretically cached gatekeeper results) and on what hardware?

@nmggithub

nmggithub commented Oct 18, 2025 •

Copy link
Copy Markdown
Contributor Author

We already kinda do this with Electron Fuses.

Can you point me where, in the source code, that is done? It might help me craft something akin to the original idea embedded hash idea.

The 20ms hit isn't awful but I'd love to avoid it if possible. Is that 20ms on every launch (even with theoretically cached gatekeeper results) and on what hardware?

That's fair. And, for clarification, the cached Gatekeeper results are the source of this issue (and I don't think they're involved in this performance of this check). As for my hardware, I am running a MacBook Pro with an Apple M3 Max chip while plugged into AC power.

@MarshallOfSound

Copy link
Copy Markdown
Member

Fuses reference:
https://github.com/electron/electron/blob/main/build/fuses/build.py

And the fuse module that modifies the binary:
https://github.com/electron/fuses

TLDR is there is a magic byte sequence that is compiled as volatile char so that the compiler doesn't optimize any accesses to it. Then we do straight up byte manipulation of the built binary during package time to modify those values.

We could do a similar thing here with for instance a SHA256 of the integrity dictionary. That would allow us to read the dictionary from Info.plist, validate it with a SHA256 from the binary (which will get auto validated by the kernel as the code page is loaded) and we can avoid calling Sec apis ourselves.

This can all be transparent to developers because we can just do it magically during packaging 🤷

@nmggithub

nmggithub commented Oct 18, 2025 •

Copy link
Copy Markdown
Contributor Author

TLDR is there is a magic byte sequence that is compiled as volatile char so that the compiler doesn't optimize any accesses to it. Then we do straight up byte manipulation of the built binary during package time to modify those values.

Is this byte-sequence fixed-size, though? Some Electron apps may have multiple ASAR archives they want to protect. Even just a single archive can have a different-length name, depending on configuration. I'm not sure if we can use the same trick for variable-length data.

@MarshallOfSound

Copy link
Copy Markdown
Member

Is this byte-sequence fixed-size, though? Some Electron apps may have multiple ASAR archives they want to protect. Even just a single archive can have a different-length name, depending on configuration. I'm not sure if we can use the same trick for variable-length data.

Yeah that's why I suggested We could do a similar thing here with for instance a SHA256 of the integrity dictionary. i.e. computing a deterministic SHA256 for a given integrity dictionary of arbitrary length/size/content (multiple ASARs, single ASAR, etc.) and validating that SHA when we read the integrity dictionary from the Info.plist

@nmggithub

Copy link
Copy Markdown
Contributor Author

Is this byte-sequence fixed-size, though? Some Electron apps may have multiple ASAR archives they want to protect. Even just a single archive can have a different-length name, depending on configuration. I'm not sure if we can use the same trick for variable-length data.

Yeah that's why I suggested We could do a similar thing here with for instance a SHA256 of the integrity dictionary. i.e. computing a deterministic SHA256 for a given integrity dictionary of arbitrary length/size/content (multiple ASARs, single ASAR, etc.) and validating that SHA when we read the integrity dictionary from the Info.plist

Ok, so instead of storing another copy of the integrity dictionary, we hash the integrity dictionary just store that hash?

Sounds like it could work! Although now, it makes me wonder, will that take more than 20 ms?

@MarshallOfSound

MarshallOfSound commented Oct 18, 2025 •

Copy link
Copy Markdown
Member

Ok, so instead of storing another copy of the integrity dictionary, we hash the integrity dictionary just store that hash?

That's what I'm thinking 🤔

Sounds like it could work! Although now, it makes me wonder, will that take more than 20 ms?

I believe not, modern CPUs can run a single SHA256 operation substantially faster than 20ms on that size of payload

@nmggithub

Copy link
Copy Markdown
Contributor Author

Ok, so instead of storing another copy of the integrity dictionary, we hash the integrity dictionary just store that hash?

That's what I'm thinking 🤔

Sounds like it could work! Although now, it makes me wonder, will that take more than 20 ms?

I believe not, modern CPUs can run a single SHA256 operation substantially faster than 20ms on that size of payload

I'll look into it! Honestly, now that I think about it, I think a lot of the 20ms I'm seeing for the current implementation may be due to IPC overhead (the Security framework does a lot of its operations in daemons). Doing everything in a single process sounds like it would definitely help.

@nmggithub

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound If we're going to be hashing the integrity dictionary, both the checking end and the generating end will need to use the same serialization format. I think JSON is probably the best. NSJSONSerialization seems pretty performant at the moment. I'm consistently able to go from an NSDictionary to a JSON string in under 10ms (and usually at or under 5ms).

@MarshallOfSound

Copy link
Copy Markdown
Member

Given we need to serialize this across platforms (as packaging doesn't always happen on macOS and we don't have easy NS API access in the packaging tooling) we should probably serialize this ourselves using a non-json format.

E.g. "for each asar integrity entry sorted alphabetically by key, add the key to the hash, then the integrity algo, then the integrity hash"

And treat that as the serialization format. That's easily implementable in any language and isn't dependent on JSON semantics

@nmggithub

Copy link
Copy Markdown
Contributor Author

Given we need to serialize this across platforms (as packaging doesn't always happen on macOS and we don't have easy NS API access in the packaging tooling) we should probably serialize this ourselves using a non-json format.

E.g. "for each asar integrity entry sorted alphabetically by key, add the key to the hash, then the integrity algo, then the integrity hash"

And treat that as the serialization format. That's easily implementable in any language and isn't dependent on JSON semantics

Oh, interesting! I was thinking this implementation would be macOS-specific, since we are serializing the integrity dictionary from Info.plist (which is, by definition, macOS-specific). I'm not entirely familiar with the Windows implementation, but given you said it embeds the hashes into the main executable already, maybe we don't have to touch it?

@MarshallOfSound

MarshallOfSound commented Oct 18, 2025 •

Copy link
Copy Markdown
Member

This is macOS specific, but packaging a macOS electron app does not have to occur on a macOS host. Therefore we might not have NS apis even if we wanted them when we get to generating this hash at packaging time

@nmggithub

Copy link
Copy Markdown
Contributor Author

This is macOS specific, but packaging a macOS electron app does not have to occur on a macOS host. Therefore we might not have NS apis even if we wanted them when we get to generating this hash at packaging time

Oh yeah, sorry. For clarification, I was talking about using the NS API's within the app itself (checking time), not at package time. Packagers like electron-packager are already written in JavaScript, so they can use the built-in JSON.stingify.

@MarshallOfSound

Copy link
Copy Markdown
Member

Ah sorry I thought you'd pointed this out, but different JSON serialization implementations aren't by spec guaranteed to output the same result. In particular key ordering of objects is not strictly specified and so using two JSON impls and comparing them is not guaranteed to be safe (even if it appears to be in a few tests)

@nmggithub

nmggithub commented Oct 18, 2025 •

Copy link
Copy Markdown
Contributor Author

Ah sorry I thought you'd pointed this out, but different JSON serialization implementations aren't by spec guaranteed to output the same result. In particular key ordering of objects is not strictly specified and so using two JSON impls and comparing them is not guaranteed to be safe (even if it appears to be in a few tests)

Yeah, this was something at the back of my mind. I'm just wondering about the complication (however minor) of creating our own custom serialization format for this. Are there any other existing ones out there that have better guarantees for their byte/char-string serializations?

EDIT: Re-reading your suggestion, I think I'm parsing out what you're saying (adding stuff to the hash one piece at a time compared to doing any sort of serialization). I'll look into that as well.

@MarshallOfSound

Copy link
Copy Markdown
Member

adding stuff to the hash one piece at a time compared to doing any sort of serialization

Yeah this is what I was angling for

@nmggithub nmggithub changed the title feat: implement bundle validation for macOS to ensure integrity feat: validate integrity of ASAR Integrity dictionary on macOS Oct 19, 2025
@nmggithub

nmggithub commented Oct 19, 2025 •

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound After wrestling with GN, macOS codesigning, and the like, I think I finally have something in place. Unfortunately, I had to commit with --no-verify because the precommit hook was choking on the gn-format step (despite me being able to call the gn format command manually). I may have something up with my config. I don't think any of the steps in the hook after that gn-format step are relevant though, so it should be ok. Please let me know if there's anything I missed.

@nmggithub

nmggithub commented Oct 19, 2025 •

Copy link
Copy Markdown
Contributor Author

An additional note: I was incorrect about the IPC overhead of my original approach that used the Security framework (or at least my reasoning for it, I thought a daemon did the validation). It turns out there's an unskippable ticket registering IPC call that happens on the first validation. The actual validation check is trivially fast. Too bad we can't really skip that IPC call, though.

Comment thread shell/common/asar/integrity_digest.mm Resolved
@jkleinsc

Copy link
Copy Markdown
Member

@nmggithub CI builds testing builds not release builds, but you could be running into errors on GN check that only show up on release builds. You can verify locally if GN check is good by running npm run gn-check.

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@erickzhao erickzhao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@nmggithub

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound is there anything more you need from me? I'd like to see this get merged soon.

@MarshallOfSound
MarshallOfSound merged commit 2d5597b into electron:main Nov 14, 2025
@welcome

welcome Bot commented Nov 14, 2025

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk

release-clerk Bot commented Nov 14, 2025

Copy link
Copy Markdown

Release Notes Persisted

Added additional defence against privileged user modifications to ASAR Integrity protected applications on macOS

@nmggithub

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound thank you very much for your help in this! Really happy to see this merged.

@TheKing-OfTime

TheKing-OfTime commented Jan 27, 2026 •

Copy link
Copy Markdown

Honestly, i dont see any sense in this change.

...can essentially bypass ASAR Integrity (however upon reboot, the app will fail to launch). All signs point to Gatekeeper (or some related functionality) caching validation results in a cache that is invalidated upon reboot.

An attacker with access to the App Management or Full Disk Access (or if user disabled SIP. When no additional permissions needed) can just resign app locally. So Gatekeeper will not prevent app launch after reboot. Also it will allow modify hash of Asar Integrity dictionary in the executable.

Asar Integrity can be bypassed like this:

import crypto from "crypto";
import * as fs from 'fs';
import { execSync } from "child_process";
import { getRawHeader } from '@electron/asar';
import plist from 'plist';

function calcASARHeaderHash(archivePath) {
    const headerString = getRawHeader(archivePath).headerString;
    const hash = crypto.createHash('sha256').update(headerString).digest('hex');
    return { algorithm: 'SHA256', hash };
}

function replaceSignDarwin(appPath) {
    execSync(`codesign -d --entitlements :- '${appPath}' > '${EXTRACTED_ENTITLEMENTS_PATH}'`);
    execSync(`codesign --force --entitlements '${EXTRACTED_ENTITLEMENTS_PATH}' --sign - '${appPath}'`);
}

function bypassAsarIntegrityDarwin(appPath, oldHash) {
    const newHash = calcASARHeaderHash(ASAR_PATH).hash;

    const plistContent = fs.readFileSync(INFO_PLIST_PATH, 'utf8');
    const plistData = plist.parse(plistContent);
    plistData.ElectronAsarIntegrity["Resources/app.asar"].hash = newHash;
    fs.writeFileSync(INFO_PLIST_PATH, plist.build(plistData));
    
    findAndReplaceHashInExecutable(appPath, oldHash, newHash); // Step required only after Electron 41.0.0
    
    replaceSignDarwin(appPath);
}

// Based on https://github.com/TheKing-OfTime/YandexMusicModPatcher/blob/master/src/main/modules/patcher.js

@nmggithub

Copy link
Copy Markdown
Contributor Author

Honestly, i dont see any sense in this change.

...can essentially bypass ASAR Integrity (however upon reboot, the app will fail to launch). All signs point to Gatekeeper (or some related functionality) caching validation results in a cache that is invalidated upon reboot.

An attacker with access to the App Management or Full Disk Access (or if user disabled SIP. When no additional permissions needed) can just resign app locally. So Gatekeeper will not prevent app launch after reboot. Also it will allow modify hash of Asar Integrity dictionary in the executable.

Asar Integrity can be bypassed like this:

import crypto from "crypto";
import * as fs from 'fs';
import { execSync } from "child_process";
import { getRawHeader } from '@electron/asar';
import plist from 'plist';

function calcASARHeaderHash(archivePath) {
    const headerString = getRawHeader(archivePath).headerString;
    const hash = crypto.createHash('sha256').update(headerString).digest('hex');
    return { algorithm: 'SHA256', hash };
}

function replaceSignDarwin(appPath) {
    execSync(`codesign -d --entitlements :- '${appPath}' > '${EXTRACTED_ENTITLEMENTS_PATH}'`);
    execSync(`codesign --force --entitlements '${EXTRACTED_ENTITLEMENTS_PATH}' --sign - '${appPath}'`);
}

function bypassAsarIntegrityDarwin(appPath, oldHash) {
    const newHash = calcASARHeaderHash(ASAR_PATH).hash;

    const plistContent = fs.readFileSync(INFO_PLIST_PATH, 'utf8');
    const plistData = plist.parse(plistContent);
    plistData.ElectronAsarIntegrity["Resources/app.asar"].hash = newHash;
    fs.writeFileSync(INFO_PLIST_PATH, plist.build(plistData));
    
    findAndReplaceHashInExecutable(appPath, oldHash, newHash); // Step required only after Electron 41.0.0
    
    replaceSignDarwin(appPath);
}

// Based on https://github.com/TheKing-OfTime/YandexMusicModPatcher/blob/master/src/main/modules/patcher.js

While you are correct here that it is possible to bypass this change with additional effort, that does not mean this security layer lacks any value. It's meant to be an additional deterrent for attackers. Having to re-sign an app is a meaningfully higher bar to clear (requiring additional steps and tooling as opposed to simply editing files), and can result in the app losing things like TCC privileges, access to Safe Storage, and can potentially break other features of the app.

Finally, this change has been discussed thoroughly with the Electron team and has been accepted and merged. If you believe there is more that can be done or changed, I'd encourage you to file an issue or PR with your suggestions.

@xgiovio

xgiovio commented Jul 22, 2026

Copy link
Copy Markdown

npx asar integrity-digest on "${appBundlePath}" , when this will be ready to replace the asar command? and how is it related to electron/packager#1890?
I'm bit confused right now

Jhacarreiro added a commit to Jhacarreiro/Claude-WebExtension-Launcher that referenced this pull request Nov 2, 2026
… again

Since Electron 41, Electron Framework holds a SHA-256 of Info.plist's
ElectronAsarIntegrity dictionary, and Electron aborts on launch when the
dictionary doesn't match it (electron/electron#48587). Claude 4.4212.0
ships Electron 44 with the digest set for both architectures, so after
we update the app.asar hash in Info.plist, Claude dies on every launch
with "Failed to get integrity for validatable asar archive" (SIGTRAP).

After updating the hash, recompute the digest and write it into each
architecture's slot in Electron Framework, before re-signing. Bump
PatchVersion so existing installs get re-patched.

Fixes lugia19#68.
lugia19 pushed a commit to lugia19/Claude-WebExtension-Launcher that referenced this pull request Nov 4, 2026
… again (#73)

Since Electron 41, Electron Framework holds a SHA-256 of Info.plist's
ElectronAsarIntegrity dictionary, and Electron aborts on launch when the
dictionary doesn't match it (electron/electron#48587). Claude 4.4212.0
ships Electron 44 with the digest set for both architectures, so after
we update the app.asar hash in Info.plist, Claude dies on every launch
with "Failed to get integrity for validatable asar archive" (SIGTRAP).

After updating the hash, recompute the digest and write it into each
architecture's slot in Electron Framework, before re-signing. Bump
PatchVersion so existing installs get re-patched.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants