Skip to content

Commit 35c0174

Browse files
author
Kate McKinley
committed
Bug 1410364 - Don't consider opener when calculating IsSecureContext. r=bz, r=dveditz
Per w3c/webappsec-secure-contexts#42, the section considering the window opener when calculating secure context is to be dropped. Firefox already uses "isSecureContextIfOpenerIgnored" in most places as this is the actual behavior we want. This patch aligns with the upcoming spec changes by ignoring the window opener. We also no longer have to keep information about whether our opener was secure as that no longer factors in our calculations. --HG-- extra : rebase_source : 3d7fa73976571f357e84e369093aecfc10c5872e extra : amend_source : ca86714f357b653577f3186b6312bfa00f1f45b9
1 parent fb96ead commit 35c0174

11 files changed

+7
-68
lines changed

dom/base/nsGlobalWindowInner.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,6 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow)
584584
mInClose(false),
585585
mHavePendingClose(false),
586586
mHadOriginalOpener(false),
587-
mOriginalOpenerWasSecureContext(false),
588587
mIsPopupSpam(false),
589588
mBlockScriptedClosingFlag(false),
590589
mWasOffline(false),
@@ -2055,12 +2054,6 @@ nsPIDOMWindowInner::IsSecureContext() const
20552054
return nsGlobalWindowInner::Cast(this)->IsSecureContext();
20562055
}
20572056

2058-
bool
2059-
nsPIDOMWindowInner::IsSecureContextIfOpenerIgnored() const
2060-
{
2061-
return nsGlobalWindowInner::Cast(this)->IsSecureContextIfOpenerIgnored();
2062-
}
2063-
20642057
void
20652058
nsPIDOMWindowInner::Suspend()
20662059
{
@@ -7407,14 +7400,6 @@ nsGlobalWindowInner::IsSecureContext() const
74077400
return JS_GetIsSecureContext(js::GetObjectCompartment(GetWrapperPreserveColor()));
74087401
}
74097402

7410-
bool
7411-
nsGlobalWindowInner::IsSecureContextIfOpenerIgnored() const
7412-
{
7413-
MOZ_RELEASE_ASSERT(IsInnerWindow());
7414-
7415-
return mIsSecureContextIfOpenerIgnored;
7416-
}
7417-
74187403
already_AddRefed<External>
74197404
nsGlobalWindowInner::GetExternal(ErrorResult& aRv)
74207405
{

dom/base/nsGlobalWindowInner.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,6 @@ class nsGlobalWindowInner : public mozilla::dom::EventTarget,
760760

761761
// https://w3c.github.io/webappsec-secure-contexts/#dom-window-issecurecontext
762762
bool IsSecureContext() const;
763-
bool IsSecureContextIfOpenerIgnored() const;
764763

765764
void GetSidebar(mozilla::dom::OwningExternalOrWindowProxy& aResult,
766765
mozilla::ErrorResult& aRv);
@@ -1371,8 +1370,6 @@ class nsGlobalWindowInner : public mozilla::dom::EventTarget,
13711370
// event posted. If this is set, just ignore window.close() calls.
13721371
bool mHavePendingClose : 1;
13731372
bool mHadOriginalOpener : 1;
1374-
bool mOriginalOpenerWasSecureContext : 1;
1375-
bool mIsSecureContextIfOpenerIgnored : 1;
13761373
bool mIsPopupSpam : 1;
13771374

13781375
// Indicates whether scripts are allowed to close this window.

dom/base/nsGlobalWindowOuter.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ nsGlobalWindowOuter::nsGlobalWindowOuter()
628628
mInClose(false),
629629
mHavePendingClose(false),
630630
mHadOriginalOpener(false),
631-
mOriginalOpenerWasSecureContext(false),
632631
mIsPopupSpam(false),
633632
mBlockScriptedClosingFlag(false),
634633
mWasOffline(false),
@@ -1561,15 +1560,7 @@ nsGlobalWindowOuter::ComputeIsSecureContext(nsIDocument* aDocument, SecureContex
15611560
MOZ_ASSERT(parentWin ==
15621561
nsGlobalWindowInner::Cast(parentOuterWin->GetCurrentInnerWindow()),
15631562
"Creator window mismatch while setting Secure Context state");
1564-
if (aFlags != SecureContextFlags::eIgnoreOpener) {
1565-
hadNonSecureContextCreator = !parentWin->IsSecureContext();
1566-
} else {
1567-
hadNonSecureContextCreator = !parentWin->IsSecureContextIfOpenerIgnored();
1568-
}
1569-
} else if (mHadOriginalOpener) {
1570-
if (aFlags != SecureContextFlags::eIgnoreOpener) {
1571-
hadNonSecureContextCreator = !mOriginalOpenerWasSecureContext;
1572-
}
1563+
hadNonSecureContextCreator = !parentWin->IsSecureContext();
15731564
}
15741565

15751566
if (hadNonSecureContextCreator) {
@@ -1781,8 +1772,6 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument,
17811772
NS_ASSERTION(NS_SUCCEEDED(rv) && newInnerGlobal &&
17821773
newInnerWindow->GetWrapperPreserveColor() == newInnerGlobal,
17831774
"Failed to get script global");
1784-
newInnerWindow->mIsSecureContextIfOpenerIgnored =
1785-
ComputeIsSecureContext(aDocument, SecureContextFlags::eIgnoreOpener);
17861775

17871776
mCreatingInnerWindow = false;
17881777
createdInnerWindow = true;
@@ -2243,8 +2232,6 @@ nsGlobalWindowOuter::SetOpenerWindow(nsPIDOMWindowOuter* aOpener,
22432232
MOZ_ASSERT(!mHadOriginalOpener,
22442233
"Probably too late to call ComputeIsSecureContext again");
22452234
mHadOriginalOpener = true;
2246-
mOriginalOpenerWasSecureContext =
2247-
aOpener->GetCurrentInnerWindow()->IsSecureContext();
22482235
}
22492236

22502237
#ifdef DEBUG

dom/base/nsGlobalWindowOuter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,6 @@ class nsGlobalWindowOuter : public mozilla::dom::EventTarget,
11911191
// event posted. If this is set, just ignore window.close() calls.
11921192
bool mHavePendingClose : 1;
11931193
bool mHadOriginalOpener : 1;
1194-
bool mOriginalOpenerWasSecureContext : 1;
1195-
bool mIsSecureContextIfOpenerIgnored : 1;
11961194
bool mIsPopupSpam : 1;
11971195

11981196
// Indicates whether scripts are allowed to close this window.

dom/base/nsPIDOMWindow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,6 @@ class nsPIDOMWindowInner : public nsPIDOMWindow<mozIDOMWindow>
863863
* Check whether this window is a secure context.
864864
*/
865865
bool IsSecureContext() const;
866-
bool IsSecureContextIfOpenerIgnored() const;
867866

868867
// Calling suspend should prevent any asynchronous tasks from
869868
// executing javascript for this window. This means setTimeout,

dom/geolocation/nsGeolocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ Geolocation::ShouldBlockInsecureRequests() const
11951195
return false;
11961196
}
11971197

1198-
if (!nsGlobalWindowInner::Cast(win)->IsSecureContextIfOpenerIgnored()) {
1198+
if (!nsGlobalWindowInner::Cast(win)->IsSecureContext()) {
11991199
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
12001200
NS_LITERAL_CSTRING("DOM"), doc,
12011201
nsContentUtils::eDOM_PROPERTIES,

dom/webidl/Window.webidl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -491,19 +491,6 @@ dictionary IdleRequestOptions {
491491

492492
callback IdleRequestCallback = void (IdleDeadline deadline);
493493

494-
/**
495-
* Similar to |isSecureContext|, but doesn't pay attention to whether the
496-
* window's opener (if any) is a secure context or not.
497-
*
498-
* WARNING: Do not use this unless you are familiar with the issues that
499-
* taking opener state into account is designed to address (or else you may
500-
* introduce security issues). If in doubt, use |isSecureContext|. In
501-
* particular do not use this to gate access to JavaScript APIs.
502-
*/
503-
partial interface Window {
504-
[ChromeOnly] readonly attribute boolean isSecureContextIfOpenerIgnored;
505-
};
506-
507494
partial interface Window {
508495
/**
509496
* Returns a list of locales that the internationalization components

toolkit/components/passwordmgr/InsecurePasswordUtils.jsm

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ XPCOMUtils.defineLazyGetter(this, "log", () => {
2929
/*
3030
* A module that provides utility functions for form security.
3131
*
32-
* Note:
33-
* This module uses isSecureContextIfOpenerIgnored instead of isSecureContext.
34-
*
35-
* We don't want to expose JavaScript APIs in a non-Secure Context even if
36-
* the context is only insecure because the windows has an insecure opener.
37-
* Doing so prevents sites from implementing postMessage workarounds to enable
38-
* an insecure opener to gain access to Secure Context-only APIs. However,
39-
* in the case of form fields such as password fields we don't need to worry
40-
* about whether the opener is secure or not. In fact to flag a password
41-
* field as insecure in such circumstances would unnecessarily confuse our
42-
* users.
4332
*/
4433
this.InsecurePasswordUtils = {
4534
_formRootsWarned: new WeakMap(),
@@ -120,8 +109,7 @@ this.InsecurePasswordUtils = {
120109
* @return {boolean} whether the form is secure
121110
*/
122111
isFormSecure(aForm) {
123-
// Ignores window.opener, see top level documentation.
124-
let isSafePage = aForm.ownerDocument.defaultView.isSecureContextIfOpenerIgnored;
112+
let isSafePage = aForm.ownerDocument.defaultView.isSecureContext;
125113

126114
// Ignore insecure documents with URLs that are local IP addresses.
127115
// This is done because the vast majority of routers and other devices
@@ -156,8 +144,7 @@ this.InsecurePasswordUtils = {
156144
}
157145

158146
let domDoc = aForm.ownerDocument;
159-
// Ignores window.opener, see top level documentation.
160-
let isSafePage = domDoc.defaultView.isSecureContextIfOpenerIgnored;
147+
let isSafePage = domDoc.defaultView.isSecureContext;
161148

162149
let { isFormSubmitHTTP, isFormSubmitSecure } = this._checkFormSecurity(aForm);
163150

toolkit/components/passwordmgr/LoginManagerContent.jsm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,7 @@ var LoginManagerContent = {
492492
let hasInsecureLoginForms = (thisWindow) => {
493493
let doc = thisWindow.document;
494494
let hasLoginForm = this.stateForDocument(doc).loginFormRootElements.size > 0;
495-
// Ignores window.opener, because it's not relevant for indicating
496-
// form security. See InsecurePasswordUtils docs for details.
497-
return (hasLoginForm && !thisWindow.isSecureContextIfOpenerIgnored) ||
495+
return (hasLoginForm && !thisWindow.isSecureContext) ||
498496
Array.some(thisWindow.frames,
499497
frame => hasInsecureLoginForms(frame));
500498
};

toolkit/components/passwordmgr/test/browser/browser.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ support-files =
5151
[browser_hasInsecureLoginForms.js]
5252
[browser_hasInsecureLoginForms_streamConverter.js]
5353
[browser_http_autofill.js]
54+
support-files =
55+
form_cross_origin_insecure_action.html
5456
[browser_insecurePasswordConsoleWarning.js]
5557
support-files =
5658
form_cross_origin_insecure_action.html

toolkit/components/passwordmgr/test/browser/browser_http_autofill.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,3 @@ add_task(async function test_http_action_autofill() {
7575
gBrowser.removeTab(tab);
7676
}
7777
});
78-

0 commit comments

Comments
 (0)