Skip to content

Commit 68cf8b7

Browse files
trop[bot]codebytereMarshallOfSoundjkleinsc
authored
fix: respect iframe sandbox flags on the OpenURL navigation path (#51438)
* fix: respect iframe sandbox flags on the OpenURL navigation path Navigations routed through OpenURLFromTab with a non-CURRENT_TAB disposition were emitted as `-new-window` without consulting the initiating frame's sandbox flags. We need to check `WebSandboxFlags::kPopups` on the initiating FrameTreeNode before emitting, surfacing a console error when the navigation is rejected. Co-authored-by: Shelley Vohr <[email protected]> * chore: backport Chromium change --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <[email protected]> Co-authored-by: Sam Attard <[email protected]> Co-authored-by: John Kleinschmidt <[email protected]> Co-authored-by: Samuel Attard <[email protected]>
1 parent 0dd1486 commit 68cf8b7

4 files changed

Lines changed: 132 additions & 0 deletions

File tree

‎patches/chromium/.patches‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ cherry-pick-cve-2026-6920.patch
173173
fix_make_macos_text_replacement_work_on_contenteditable.patch
174174
fix-dcheck-failure-when-starting-heap-profiler-for-renderer.patch
175175
fix_use_bundled_devtools_frontend_url_for_remote_debugging.patch
176+
frameloader_startnavigation_should_not_allow_emulated_ctrl_click.patch
176177
fix_constrain_allowuniversalaccessfromfileurls_to_file_origins_in.patch
177178
cherry-pick-7695218.patch
178179
cherry-pick-7695435.patch
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Nate Chapin <[email protected]>
3+
Date: Fri, 20 Feb 2026 11:02:15 -0800
4+
Subject: FrameLoader::StartNavigation should not allow emulated Ctrl+click
5+
from sandboxed iframes
6+
7+
Fixed: 483771899
8+
Change-Id: I1e134f0c9dcfbb4760d339d909a7d7339a5e3077
9+
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7572487
10+
Commit-Queue: Nate Chapin <[email protected]>
11+
Reviewed-by: Daniel Cheng <[email protected]>
12+
Cr-Commit-Position: refs/heads/main@{#1587969}
13+
14+
diff --git a/third_party/blink/renderer/core/loader/frame_loader.cc b/third_party/blink/renderer/core/loader/frame_loader.cc
15+
index 64e74d094fb7166290e770560cfe135a49dbfda7..f413c08dca9aa6eb0f6aa1a92d6d21331f64dbac 100644
16+
--- a/third_party/blink/renderer/core/loader/frame_loader.cc
17+
+++ b/third_party/blink/renderer/core/loader/frame_loader.cc
18+
@@ -868,6 +868,17 @@ void FrameLoader::StartNavigation(FrameLoadRequest& request,
19+
return;
20+
}
21+
22+
+ // A sandboxed iframe without `allow-popups` should not be able to
23+
+ // open a new browsing context by emulating a user gesture in JS.
24+
+ // (e.g. Ctrl+click).
25+
+ if (request.GetNavigationPolicy() != kNavigationPolicyCurrentTab &&
26+
+ request.GetTriggeringEventInfo() ==
27+
+ mojom::blink::TriggeringEventInfo::kFromUntrustedEvent &&
28+
+ frame_->GetSecurityContext()->IsSandboxed(
29+
+ network::mojom::blink::WebSandboxFlags::kPopups)) {
30+
+ return;
31+
+ }
32+
+
33+
if (request.GetNavigationPolicy() == kNavigationPolicyCurrentTab &&
34+
(!origin_window || origin_window->GetSecurityOrigin()->CanAccess(
35+
frame_->DomWindow()->GetSecurityOrigin()))) {

‎shell/browser/api/electron_api_web_contents.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
#include "mojo/public/cpp/bindings/remote.h"
8686
#include "mojo/public/cpp/system/platform_handle.h"
8787
#include "printing/buildflags/buildflags.h"
88+
#include "services/network/public/cpp/web_sandbox_flags.h"
89+
#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
8890
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
8991
#include "services/service_manager/public/cpp/interface_provider.h"
9092
#include "shell/browser/api/electron_api_browser_window.h"
@@ -151,6 +153,7 @@
151153
#include "third_party/blink/public/common/page/page_zoom.h"
152154
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
153155
#include "third_party/blink/public/common/tokens/tokens.h"
156+
#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
154157
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
155158
#include "third_party/blink/public/mojom/frame/fullscreen.mojom.h"
156159
#include "third_party/blink/public/mojom/messaging/transferable_message.mojom.h"
@@ -1391,6 +1394,26 @@ content::WebContents* WebContents::OpenURLFromTab(
13911394
navigation_handle_callback) {
13921395
auto weak_this = GetWeakPtr();
13931396
if (params.disposition != WindowOpenDisposition::CURRENT_TAB) {
1397+
content::FrameTreeNode* initiator =
1398+
params.frame_tree_node_id ? content::FrameTreeNode::GloballyFindByID(
1399+
params.frame_tree_node_id)
1400+
: nullptr;
1401+
if (initiator && !initiator->IsMainFrame()) {
1402+
using SandboxFlags = network::mojom::WebSandboxFlags;
1403+
const SandboxFlags flags = initiator->active_sandbox_flags();
1404+
auto allow = [flags](SandboxFlags flag) {
1405+
return (flags & flag) == SandboxFlags::kNone;
1406+
};
1407+
if (!allow(SandboxFlags::kPopups)) {
1408+
if (auto* rfh = initiator->current_frame_host()) {
1409+
rfh->AddMessageToConsole(
1410+
blink::mojom::ConsoleMessageLevel::kError,
1411+
"Blocked opening a new window because the iframe is sandboxed "
1412+
"and the 'allow-popups' keyword is not set.");
1413+
}
1414+
return nullptr;
1415+
}
1416+
}
13941417
Emit("-new-window", params.url, "", params.disposition, "", params.referrer,
13951418
params.post_data);
13961419
return nullptr;

‎spec/chromium-spec.ts‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5058,3 +5058,76 @@ describe('iframe sandbox external protocols', () => {
50585058
expect(openExternalRequests).to.deep.equal(['magnet:sandbox-test']);
50595059
});
50605060
});
5061+
5062+
describe('iframe sandbox popups', () => {
5063+
let server: http.Server;
5064+
let serverUrl: string;
5065+
let w: BrowserWindow;
5066+
5067+
const childHtml = `
5068+
<script>
5069+
addEventListener('DOMContentLoaded', () => {
5070+
const a = document.createElement('a');
5071+
a.href = 'https://example.com/sandbox-bypassed';
5072+
document.body.appendChild(a);
5073+
a.dispatchEvent(new MouseEvent('click', {
5074+
ctrlKey: true, metaKey: true, bubbles: true, cancelable: true, view: window
5075+
}));
5076+
});
5077+
</script>`;
5078+
5079+
before(async () => {
5080+
server = http.createServer((req, res) => {
5081+
res.setHeader('Content-Type', 'text/html');
5082+
if (req.url === '/child') {
5083+
res.end(childHtml);
5084+
} else {
5085+
const sandbox = new URL(req.url!, serverUrl).searchParams.get('sandbox') ?? '';
5086+
res.end(`<iframe sandbox="${sandbox}" src="/child"></iframe>`);
5087+
}
5088+
});
5089+
serverUrl = (await listen(server)).url;
5090+
});
5091+
5092+
after(() => {
5093+
server.close();
5094+
});
5095+
5096+
beforeEach(() => {
5097+
w = new BrowserWindow({ show: false });
5098+
});
5099+
5100+
afterEach(() => closeAllWindows());
5101+
5102+
it('does not invoke setWindowOpenHandler from a sandboxed iframe without allow-popups', async () => {
5103+
let handlerCalls = 0;
5104+
w.webContents.setWindowOpenHandler(() => {
5105+
handlerCalls++;
5106+
return { action: 'deny' };
5107+
});
5108+
await w.loadURL(`${serverUrl}/?sandbox=${encodeURIComponent('allow-scripts')}`);
5109+
await setTimeout(200);
5110+
expect(handlerCalls).to.equal(0);
5111+
});
5112+
5113+
it('does not create a BrowserWindow from a sandboxed iframe without allow-popups (no handler installed)', async () => {
5114+
let created = false;
5115+
w.webContents.on('did-create-window', () => {
5116+
created = true;
5117+
});
5118+
await w.loadURL(`${serverUrl}/?sandbox=${encodeURIComponent('allow-scripts')}`);
5119+
await setTimeout(200);
5120+
expect(created).to.be.false();
5121+
});
5122+
5123+
it('invokes setWindowOpenHandler when allow-popups is set', async () => {
5124+
let handlerCalls = 0;
5125+
w.webContents.setWindowOpenHandler(() => {
5126+
handlerCalls++;
5127+
return { action: 'deny' };
5128+
});
5129+
await w.loadURL(`${serverUrl}/?sandbox=${encodeURIComponent('allow-scripts allow-popups')}`);
5130+
await setTimeout(200);
5131+
expect(handlerCalls).to.equal(1);
5132+
});
5133+
});

0 commit comments

Comments
 (0)