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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: illegal access errors with nodeIntegrationInSubFrames #29093

Merged
merged 4 commits into from May 14, 2021

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented May 10, 2021

Description of Change

Closes #27995.

Fixes an issue where illegal access error would be thrown by the V8 isolate in some circumstances where an iframe was loaded and its source set later when Node.js integration is enabled in subframes. This was happening because if an iframe is created and a source is not set, the iframe loads about:blank and creates a script context for the same. We don't want to create a Node.js environment here because if the src is later set, the JS necessary to do that triggers illegal access errors when the initial about:blank Node.js environment is cleaned up.

See this comment: https://source.chromium.org/chromium/chromium/src/+/main:content/renderer/render_frame_impl.h;l=870-892;drc=4b6001440a18740b76a1c63fa2a002cc941db394

cc @MarshallOfSound

Checklist

Release Notes

Notes: Fixed an issue where illegal access error could be thrown when nodeIntegrationInSubFrames is enabled.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/12-x-y labels May 10, 2021
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label May 10, 2021
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

This is a unique case, ideally I wouldn't worry about setup and tear down of the node environment in a frame as it shouldn't affect the execution in other node environment. In this particular case the iframe being in the same process as the parent frame performing sync navigation shares the v8 isolate and hence the disallow execution scope impacts each other. I am fine with the current solution.

NB: looks like the new test fixtures are not tested, LGTM otherwise.

shell/renderer/electron_renderer_client.cc Outdated Show resolved Hide resolved
@codebytere
Copy link
Member Author

codebytere commented May 11, 2021

@deepak1556 they're part of crash-cases - can you clarify what you mean by

looks like the new test fixtures are not tested

?

From macOS tests

Screen Shot 2021-05-11 at 3 38 28 PM

@deepak1556
Copy link
Member

they're part of crash-cases

Missed that, ignore my comment.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label May 11, 2021
@codebytere codebytere force-pushed the fix-illegal-access-bug branch 3 times, most recently from 359eb06 to dd01731 Compare May 12, 2021 09:01
@miniak
Copy link
Contributor

miniak commented May 13, 2021

node ./script/lint.js && npm run lint:clang-format && npm run lint:docs
--- a/shell/renderer/electron_render_frame_observer.cc
+++ b/shell/renderer/electron_render_frame_observer.cc
@@ -162,7 +162,8 @@
   // https://source.chromium.org/chromium/chromium/src/+/main:content/renderer/render_frame_impl.h;l=870-892;drc=4b6001440a18740b76a1c63fa2a002cc941db394
   GURL url = render_frame_->GetWebFrame()->GetDocument().Url();
   bool allow_node_in_sub_frames = prefs.node_integration_in_sub_frames;
-  if (allow_node_in_sub_frames && url.IsAboutBlank() && !render_frame_->IsMainFrame())
+  if (allow_node_in_sub_frames && url.IsAboutBlank() &&
+      !render_frame_->IsMainFrame())
     return false;
 
   if (prefs.context_isolation &&

Co-authored-by: Robo <hop2deep@gmail.com>
@codebytere
Copy link
Member Author

Test failures are unrelated.

@codebytere codebytere merged commit b7a2345 into master May 14, 2021
@release-clerk
Copy link

release-clerk bot commented May 14, 2021

Release Notes Persisted

Fixed an issue where illegal access error could be thrown when nodeIntegrationInSubFrames is enabled.

@trop
Copy link
Contributor

trop bot commented May 14, 2021

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

@trop
Copy link
Contributor

trop bot commented May 14, 2021

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

@y489436672
Copy link

@deepak1556 This problem still exists. electron@13.1.9 win7 or win10 This problem occurs when I open iframe when I download a file.

@y489436672
Copy link

webPreferences: {
webSecurity: false,
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
allowRunningInsecureContent: true,
nodeIntegrationInSubFrames: true,
preload: path.resolve(global.__preloadPath, './preload.js'),
devTools: true
}

@mckravchyk
Copy link
Contributor

mckravchyk commented Dec 16, 2021

@codebytere

The issue is with loading Node.js environment. Could this PR be improved to allow a pass for sandboxed renderers? Or would it also cause problems?

A sandboxed renderer won't have a Node.js environment initialized.

So we could use preload in about:blank iframes with webPreferences like this:

{
  nodeIntegration: false,
  sandbox: true,
  nodeIntegrationInSubFrames: true,
} 

This would partially fix #31313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncaught Illegal access error in circumstances of #27457
5 participants