-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set Electron Fuses flags for better security
- Loading branch information
1 parent
6bf9cc4
commit e89c275
Showing
8 changed files
with
458 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// https://github.com/electron-userland/electron-builder/issues/6365 | ||
const path = require('path'); | ||
const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses'); | ||
const builder = require('electron-builder'); | ||
|
||
async function addElectronFuses(context) | ||
{ | ||
const { appOutDir, packager: { appInfo: { productFilename } }, electronPlatformName, arch } = context; | ||
|
||
const ext = { | ||
darwin: '.app', | ||
win32: '.exe', | ||
linux: [''], | ||
}[electronPlatformName]; | ||
|
||
const IS_LINUX = electronPlatformName === 'linux'; | ||
const executableName = IS_LINUX | ||
? productFilename.replace('.', '') // Remove . from "draw.io" | ||
: productFilename; | ||
|
||
const electronBinaryPath = path.join(appOutDir, `${executableName}${ext}`); | ||
console.log('Flipping fuses for: ', electronBinaryPath); | ||
|
||
await flipFuses(electronBinaryPath, | ||
{ | ||
version: FuseVersion.V1, | ||
[FuseV1Options.RunAsNode]: false, // Disables ELECTRON_RUN_AS_NODE | ||
[FuseV1Options.EnableCookieEncryption]: true, // Enables cookie encryption | ||
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false, // Disables the NODE_OPTIONS environment variable | ||
[FuseV1Options.EnableNodeCliInspectArguments]: false, // Disables the --inspect and --inspect-brk family of CLI options | ||
[FuseV1Options.OnlyLoadAppFromAsar]: true, // Enforces that Electron will only load your app from "app.asar" instead of its normal search paths | ||
// https://github.com/electron-userland/electron-builder/issues/6930 (electron-builder uses its own asar packaging) | ||
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: false, // TODO Enables validation of the app.asar archive on macOS | ||
// Some reports it crashes when enabled on arm64 | ||
[FuseV1Options.LoadBrowserProcessSpecificV8Snapshot]: false, // TODO Loads V8 Snapshot from `browser_v8_context_snapshot.bin` for the browser process | ||
// TODO Disables when moving to a custom protocol | ||
[FuseV1Options.GrantFileProtocolExtraPrivileges]: true, // Grants the file protocol extra privileges | ||
// Based on docs, this should be enabled for macOS on arm64 | ||
resetAdHocDarwinSignature: electronPlatformName === 'darwin' && (targetArch === builder.Arch.arm64 || arch === builder.Arch.universal), | ||
}); | ||
} | ||
|
||
module.exports = async (context) => | ||
{ | ||
await addElectronFuses(context); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
] | ||
}, | ||
"afterSign": "build/notarize.js", | ||
"afterPack": "build/fuses.js", | ||
"dmg": { | ||
}, | ||
"linux": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
"removable-media" | ||
] | ||
}, | ||
"afterPack": "build/fuses.js", | ||
"fileAssociations": [ | ||
{ | ||
"ext": "drawio", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
e89c275
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed. Security improvements. https://www.electronjs.org/docs/latest/tutorial/fuses