Skip to content
New issue

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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add worldSafe flag for executeJS results #24114

Merged
merged 11 commits into from Jul 23, 2020

Conversation

MarshallOfSound
Copy link
Member

Previously the return values of webFrame.executeJavaScript crossed the world boundary when context isolation was enabled. This allows apps to makes themselves insecure by accidentally sending objects from the isolated world back to the main world. To help devs avoid this we're adding this new flag, and this flag will be turned on by default in Electron 12 (and removed) ensuring that this kind of issue can't become a thing again.

This PR is also requesting new minors of 8 and 9 馃槃

Notes: Added new worldSafeExecuteJavaScript webPreference to ensure that the return values from webFrame.executeJavaScript are world safe when context isolation is enabled

@electron-cation electron-cation bot added the new-pr 馃尡 PR opened in the last 24 hours label Jun 12, 2020
@electron-cation electron-cation bot removed the new-pr 馃尡 PR opened in the last 24 hours label Jun 13, 2020
docs/api/browser-window.md Outdated Show resolved Hide resolved
lib/renderer/api/web-frame.ts Show resolved Hide resolved
lib/renderer/api/web-frame.ts Outdated Show resolved Hide resolved
lib/renderer/api/web-frame.ts Show resolved Hide resolved
shell/renderer/api/electron_api_web_frame.cc Outdated Show resolved Hide resolved
shell/renderer/api/electron_api_web_frame.cc Outdated Show resolved Hide resolved
spec-main/api-web-frame-spec.ts Outdated Show resolved Hide resolved
shell/renderer/api/electron_api_web_frame.cc Outdated Show resolved Hide resolved
shell/renderer/api/electron_api_web_frame.cc Outdated Show resolved Hide resolved
shell/renderer/api/electron_api_web_frame.cc Outdated Show resolved Hide resolved
shell/renderer/api/electron_api_web_frame.cc Outdated Show resolved Hide resolved
lib/renderer/api/web-frame.ts Show resolved Hide resolved
lib/renderer/web-frame-init.ts Show resolved Hide resolved
shell/renderer/api/electron_api_web_frame.cc Show resolved Hide resolved
shell/renderer/api/electron_api_web_frame.cc Outdated Show resolved Hide resolved
Comment on lines +351 to +353
* `worldSafeExecuteJavaScript` Boolean (optional) - If true, values returned from `webFrame.executeJavaScript` will be sanitized to ensure JS values
can't unsafely cross between worlds when using `contextIsolation`. The default
is `false`. In Electron 12, the default will be changed to `true`. _Deprecated_
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this might be a good test case for the base::Feature-based stuff we've been talking about in api-wg?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe, but I don't super want to figure out that system / pioneer it in this PR

Copy link
Member

Choose a reason for hiding this comment

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

Someone's gotta be the first :\

@MarshallOfSound MarshallOfSound merged commit b500294 into master Jul 23, 2020
@release-clerk
Copy link

release-clerk bot commented Jul 23, 2020

Release Notes Persisted

Added new worldSafeExecuteJavaScript webPreference to ensure that the return values from webFrame.executeJavaScript are world safe when context isolation is enabled

@MarshallOfSound MarshallOfSound deleted the world-safe-execute-js branch July 23, 2020 21:32
@trop
Copy link
Contributor

trop bot commented Jul 23, 2020

I was unable to backport this PR to "8-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Jul 23, 2020

I have automatically backported this PR to "10-x-y", please check out #24711

@trop trop bot removed the target/10-x-y label Jul 23, 2020
@trop
Copy link
Contributor

trop bot commented Jul 23, 2020

I have automatically backported this PR to "9-x-y", please check out #24712

delhanty pushed a commit to delhanty/electron-quick-start-typescript that referenced this pull request Aug 14, 2020
<electron/electron#24114>
"Previously the return values of webFrame.executeJavaScript crossed the world boundary when context isolation was enabled. This allows apps to makes themselves insecure by accidentally sending objects from the isolated world back to the main world. To help devs avoid this we're adding this new flag, and this flag will be turned on by default in Electron 12 (and removed) ensuring that this kind of issue can't become a thing again.

This PR is also requesting new minors of 8 and 9 馃槃

Notes: Added new worldSafeExecuteJavaScript webPreference to ensure that the return values from webFrame.executeJavaScript are world safe when context isolation is enabled"
delhanty pushed a commit to delhanty/svelte-template-electron that referenced this pull request Aug 14, 2020
<electron/electron#24114>
"Previously the return values of webFrame.executeJavaScript crossed the world boundary when context isolation was enabled. This allows apps to makes themselves insecure by accidentally sending objects from the isolated world back to the main world. To help devs avoid this we're adding this new flag, and this flag will be turned on by default in Electron 12 (and removed) ensuring that this kind of issue can't become a thing again.

This PR is also requesting new minors of 8 and 9 馃槃

Notes: Added new worldSafeExecuteJavaScript webPreference to ensure that the return values from webFrame.executeJavaScript are world safe when context isolation is enabled"
acrosman added a commit to acrosman/ElectronSimpleStarter that referenced this pull request Aug 19, 2020
@bughit
Copy link
Contributor

bughit commented Oct 1, 2020

@MarshallOfSound

Please don't remove the option. I have code the defines (and returns) anon functions in the main world. That's not even hypothetically unsafe. Also code that returns other main world objects (e.g. window). The 'window' property is unwritable and unconfigurable, so that's also not unsafe, you're always get the expected window even in untrusted content. It's reasonable for this raw access be restricted by default, but the EIC should retain it optionally, it can be safe, especially if the content is trusted.

If contextIsolation can be disabled and nodeIntegration enabled, security is clearly ultimately up to the dev, it can't be forced like this.

@bughit
Copy link
Contributor

bughit commented Oct 5, 2020

@nornagon

Could we please have some discussion about the planned removal of worldSafeExecuteJavaScript. I have code that depends on it. Retrieves the main world window. Defines anon functions for later execution.

const contentWin = webFrame.executeJavaScript('window')
const contentFn = webFrame.executeJavaScript('() => {...}')

I have no issue with maximally secure defaults, but there shouldn't be a need to completely block this, breaking working code, forcing redesigns. . This can be used safely, judiciously. Considering security can be disabled completely, it's not unreasonable to optionally allow EIC to retrieve content world objects. Please don't remove the choice.

@@ -348,6 +348,9 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
You can access this context in the dev tools by selecting the
'Electron Isolated Context' entry in the combo box at the top of the
Console tab.
* `worldSafeExecuteJavaScript` Boolean (optional) - If true, values returned from `webFrame.executeJavaScript` will be sanitized to ensure JS values
can't unsafely cross between worlds when using `contextIsolation`. The default
is `false`. In Electron 12, the default will be changed to `true`. _Deprecated_
Copy link
Contributor

Choose a reason for hiding this comment

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

@MarshallOfSound Why is this marked Deprecated? I turned this on to prepare for Electron 12, but my code reviewer was confused why I'm using a deprecated option. Presumably false is deprecated, but I think we should be explicit about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@poiru This option is a migration feature, it's kinda weird and you're right we should probably document it better. The flow here will be

  • Add this option
  • Change default of this option
  • Deprecate this option in code
  • Remove this option

We aren't going to leave this flag around forever / for long at all

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.

None yet

4 participants