8000 feat: Electron Fuses, package time feature toggles by MarshallOfSound · Pull Request #24241 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Electron Fuses, package time feature toggles #24241

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 27, 2020
Merged

Conversation

MarshallOfSound
Copy link
Member
@MarshallOfSound MarshallOfSound commented Jun 22, 2020

Problem Statement

Certain features or Electron are undesirable for specific deployments / environments and although they can be disabled / not-utilized at the app level certain security models take account for user-level code execution. E.g. Being able to run electron apps with ELECTRON_RUN_AS_NODE and just get a node binary is not-ideal. We want a way to toggle certain features in a way that both doesn't require app developers to build Electron in-house and ensures that OS level app integrity / code-signing protection (gatekeeper / app-locker) correctly prevent modification of these toggles.

Solution: Electron Fuses

Utilizing a known address / section of the app binary we can create a series of "fuses" (toggles) that can be overwritten after Electron has been built into a .app / .exe. These can be overwritten by writing raw data to the correct address in the binary. In order to locate this known address we use a fixed sentinel string that is guaranteed to directly prefix the fuses.

The format of this string is {sentinel}{fuse_version}{...fuses}.

This allows packaging tools to find the sentinel, and then know that the next byte is the fuse version and each sequential byte is a fuse. The fuse_version should be used to determine what each fuse is and how many there are. A handy tool @electron/fuses will be built to abstract away most of this complexity for developers.

Example use cases

This PR implements one use case (disabling ELECTRON_RUN_AS_NODE), other potential use cases which could be implemented in the future using this system.

  • Disabling bad flags (--disable-sandbox, --remote-debugging-port, etc.)
  • Disabling the node debugger
  • Disable the app, app.asar, default_app.asar load path search and enforce only one of those is ever searched
  • Enforce certain webPrefs (E.g. all webContents must have sandbox, contextIsolation, etc.)
  • Other wild stuff that depends on other crazy ideas

Implementation Details

Adding a new fuse is as easy as adding a new key to the fuses.json file, the fuse implementation is automatically generated as part of the build step so if you add a new foo_thing_enabled fuse a new method electron::fuses::IsFooThingEnabled() will automatically exist.

To Do

  • Documentation
  • Build @electron/fuses for controlling the fuses at the packaging phase
  • Tests

Notes: Implemented Electron Fuses for customizing certain Electron features at package time.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jun 22, 2020
@MarshallOfSound MarshallOfSound changed the title feat: Electron Fuses, package time feature toggles [WIP] feat: Electron Fuses, package time feature toggles Jun 22, 2020

dir_path = os.path.dirname(os.path.realpath(__file__))

SENTINEL = "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX"
Copy link
Contributor

Choose a reason for hiding this comment

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

. o O ( instead of using this sentinel, could we export this as a symbol and then parse ELF/PE/mach-o to directly find the location? )

@MarshallOfSound MarshallOfSound changed the title [WIP] feat: Electron Fuses, package time feature toggles feat: Electron Fuses, package time feature toggles Oct 2, 2020
MarshallOfSound and others added 2 commits October 5, 2020 14:12
Co-authored-by: Jeremy Rose <jeremya@chromium.org>
Co-authored-by: Jeremy Rose <jeremya@chromium.org>
@MarshallOfSound MarshallOfSound merged commit dbf2931 into master Oct 27, 2020
@release-clerk
Copy link
release-clerk bot commented Oct 27, 2020

Release Notes Persisted

Implemented Electron Fuses for customizing certain Electron features at package time.

@MarshallOfSound MarshallOfSound deleted the fuses branch October 27, 2020 17:49
@phamminhvu
Copy link

Hi Team,

We tried to follow the instruction for installing the library "fuses" to our electron project?
We used electron version 12.x.x
But looks like It is not ready to use yet.

Thank you very much for feedback!

Best regards,
Jason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0