Closed Bug 1694993 Opened 3 years ago Closed 2 years ago

noopener window.open() shouldn't inherit principal

Categories

(Core :: DOM: Navigation, defect, P2)

defect

Tracking

()

RESOLVED FIXED
107 Branch
Tracking Status
firefox107 --- fixed

People

(Reporter: smaug, Assigned: nika)

References

(Regressed 1 open bug)

Details

Attachments

(7 files)

Per specs (HTML + URL) noopener window open uses opaque origin.

https://searchfox.org/mozilla-central/rev/df23c6e58c6be1eb8399e475878f73d4867bef87/toolkit/components/windowwatcher/nsWindowWatcher.cpp#1248 should probably use LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL when noopener is passed to window.open.

This is low priority, since it is very hard to detect this.

Severity: -- → N/A
Priority: -- → P3
Fission Milestone: --- → M8

This is not Fission specific.

Fission Milestone: M8 → ---
No longer blocks: fission
Priority: P3 → P2

Changing severity to S4 because N/A results in autonag emails.

Severity: N/A → S4

Previously we would pull this information frequently from the subject
principal, which is unreliable. With this new approach, we more explicitly pass
the principals around as-needed into where they're going to be used.

Some assertions about the subject principal were introduced to ensure that
assumptions made about chrome windows and the system principal are not
incorrect.

Assignee: nobody → nika
Status: NEW → ASSIGNED

When opening a window with noopener, we will no longer inherit the
subject principal into the newly created window's initial about:blank
document, instead creating a new null principal.

This patch also makes the system/expanded principal -> null principal
translation happen earlier (it previously happened in
SetInitialPrincipalToSubject), so that it can be followed more easily
when reading the code.

Finally, the load started by nsWindowWatcher in new windows is updated
to specify LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL when noopener is
specified such that the explicit about:blank load also cannot inherit
the subject principal.

This change does make it so that the global is not re-used between the
initial and loaded about:blank document, however this shouldn't be
visible due to noopener being specified, preventing any references to
the initial document from existing.

Noopener loads with javascript: URIs will be rejected early during the
load due to the mismatch between the triggering principal and the
initial about:blank document's principal.

Depends on D154563

The newBC and newDocShell variables were potentially confusing, as they
could also be existing windows selected by named targeting or the window
provider, so they have been renamed. Some other variables were also renamed for
consistency and clarity.

Depends on D154564

Previously we would copy session storage even if we were not opening a new
window, meaning that a targeted load could re-trigger a copy. This was not
specified in the standard so is being changed to only copy when a new window is
created. In addition, the copy was moved before navigaton starts, again for
more consistency with ordering for the standard, such that things like
javascript: URI loads will oberve the up-to-date session storage.

Depends on D154565

Pushed by nlayzell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/3821545ab46b
Part 1: Be more explicit about principals used when creating pop-up windows, r=smaug
https://hg.mozilla.org/integration/autoland/rev/05d7cbbfe9e2
Part 2: Explicitly select the principal for newly created windows in nsWindowWatcher, r=smaug
https://hg.mozilla.org/integration/autoland/rev/c9585ce37fe5
Part 3: Rename some variables in nsWindowWatcher for clarity, r=smaug
https://hg.mozilla.org/integration/autoland/rev/3b412d5fbdcf
Part 4: Copy session storage before loading, and only for newly created windows, r=smaug
https://hg.mozilla.org/integration/autoland/rev/1d21d911b3e7
Part 5: Add a simple test for javascript URIs with noopener, r=smaug
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/35553 for changes under testing/web-platform/tests
Upstream PR was closed without merging
Regressed by: 1786376

If we don't preserve the precursor principal in this case, we'll end up
doing an unnecessary process switch in some cases, which lead to a
test failure.

This patch also cleans up some logic around the first party origin
attribute with null principals, as the logic was only used in one place
and generally added some unnecessary complexity to NullPrincipal
itself.

Depends on D154567

Pushed by nlayzell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/d5c6608a07e9
Part 1: Be more explicit about principals used when creating pop-up windows, r=smaug
https://hg.mozilla.org/integration/autoland/rev/be9c1ebd0413
Part 2: Explicitly select the principal for newly created windows in nsWindowWatcher, r=smaug
https://hg.mozilla.org/integration/autoland/rev/84cf4510639e
Part 3: Rename some variables in nsWindowWatcher for clarity, r=smaug
https://hg.mozilla.org/integration/autoland/rev/54e339586d26
Part 4: Copy session storage before loading, and only for newly created windows, r=smaug
https://hg.mozilla.org/integration/autoland/rev/93b6f01e9320
Part 5: Add a simple test for javascript URIs with noopener, r=smaug
https://hg.mozilla.org/integration/autoland/rev/4d404c79681a
Part 6: Preserve precursor principal through LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL, r=ckerschb,smaug

Backed out for failures on test_alwaysOnTop_windows.html

[task 2022-08-27T00:12:57.135Z] 00:12:57     INFO - TEST-START | toolkit/components/windowwatcher/test/test_alwaysOnTop_windows.html
[task 2022-08-27T00:17:57.204Z] 00:17:57     INFO - TEST-INFO | started process screenshot
[task 2022-08-27T00:17:57.272Z] 00:17:57     INFO - TEST-INFO | screenshot: exit 0
[task 2022-08-27T00:17:57.279Z] 00:17:57     INFO - Buffered messages logged at 00:12:58
[task 2022-08-27T00:17:57.279Z] 00:17:57     INFO - add_task | Entering 
[task 2022-08-27T00:17:57.280Z] 00:17:57     INFO - Buffered messages finished
[task 2022-08-27T00:17:57.280Z] 00:17:57     INFO - TEST-UNEXPECTED-FAIL | toolkit/components/windowwatcher/test/test_alwaysOnTop_windows.html | Test timed out. - 
[task 2022-08-27T00:17:58.213Z] 00:17:58     INFO - Not taking screenshot here: see the one that was previously logged
[task 2022-08-27T00:17:58.217Z] 00:17:58     INFO - TEST-UNEXPECTED-FAIL | toolkit/components/windowwatcher/test/test_alwaysOnTop_windows.html | [SimpleTest.finish()] No checks actually run. (You need to call ok(), is(), or similar functions at least once.  Make sure you use SimpleTest.waitForExplicitFinish() if you need it.) 
[task 2022-08-27T00:17:58.217Z] 00:17:58     INFO - SimpleTest.ok@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:414:16
[task 2022-08-27T00:17:58.217Z] 00:17:58     INFO - afterCleanup@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1413:18
[task 2022-08-27T00:17:58.218Z] 00:17:58     INFO - executeCleanupFunction@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1489:7
[task 2022-08-27T00:17:58.218Z] 00:17:58     INFO - SimpleTest.finish@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1509:3
[task 2022-08-27T00:17:58.218Z] 00:17:58     INFO - killTest@chrome://mochikit/content/tests/SimpleTest/TestRunner.js:195:22
[task 2022-08-27T00:17:58.233Z] 00:17:58     INFO - GECKO(864) | MEMORY STAT | vsize 2104390MB | vsizeMaxContiguous 65864728MB | residentFast 291MB | heapAllocated 156MB
[task 2022-08-27T00:17:58.239Z] 00:17:58     INFO - TEST-OK | toolkit/components/windowwatcher/test/test_alwaysOnTop_windows.html | took 301104ms
Flags: needinfo?(nika)
Flags: needinfo?(nika)
Upstream PR was closed without merging

There are some r+ patches which didn't land and no activity in this bug for 2 weeks.
:nika, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit auto_nag documentation.

Flags: needinfo?(smaug)
Flags: needinfo?(nika)
Flags: needinfo?(smaug)
Pushed by nlayzell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/62cc9e155d56
Part 1: Be more explicit about principals used when creating pop-up windows, r=smaug
https://hg.mozilla.org/integration/autoland/rev/221e28fc994d
Part 2: Explicitly select the principal for newly created windows in nsWindowWatcher, r=smaug
https://hg.mozilla.org/integration/autoland/rev/2b181e351637
Part 3: Rename some variables in nsWindowWatcher for clarity, r=smaug
https://hg.mozilla.org/integration/autoland/rev/f2b6ca0547cb
Part 4: Copy session storage before loading, and only for newly created windows, r=smaug
https://hg.mozilla.org/integration/autoland/rev/adc9146d8329
Part 5: Add a simple test for javascript URIs with noopener, r=smaug
https://hg.mozilla.org/integration/autoland/rev/484fd2c68e87
Part 6: Preserve precursor principal through LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL, r=ckerschb,smaug
https://hg.mozilla.org/integration/autoland/rev/4ec21c88e8c9
Part 7: Don't set LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL for chrome windows, r=smaug
Regressions: 1791696

Bug 1786376 was assigned to the wrong field. I shouldn't be in the Regressed By field. It's reversed. Then the regression keyword can be removed from this bug.

Flags: needinfo?(smaug)
Upstream PR merged by moz-wptsync-bot
Flags: needinfo?(smaug)
No longer regressed by: 1786376
Flags: needinfo?(nika)
Keywords: regression
Regressions: 1814490
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: