Bug 369427: perform window.open() URL security check before popup blocking, to ensure that we don't notify UI of a blocked popup that would have otherwise failed anyways, r+sr=bzbarsky

This commit is contained in:
gavin%gavinsharp.com 2007-02-06 05:11:13 +00:00
parent 7a522c0451
commit fe1a9c03ff

View File

@ -6184,6 +6184,28 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
aCalleePrincipal->GetURI(getter_AddRefs(currentCodebase));
}
// Note: it's very important that this be an nsXPIDLCString, since we want
// .get() on it to return nsnull until we write stuff to it. The window
// watcher expects a null URL string if there is no URL to load.
nsXPIDLCString url;
nsresult rv = NS_OK;
// It's important to do this security check before determining whether this
// window opening should be blocked, to ensure that we don't FireAbuseEvents
// for a window opening that wouldn't have succeeded in the first place.
if (!aUrl.IsEmpty()) {
AppendUTF16toUTF8(aUrl, url);
/* Check whether the URI is allowed, but not for dialogs --
see bug 56851. The security of this function depends on
window.openDialog being inaccessible from web scripts */
if (url.get() && !aDialog)
rv = SecurityCheckURL(url.get());
}
if (NS_FAILED(rv))
return rv;
// These next two variables are only accessed when checkForPopup is true
PopupControlState abuseLevel;
OpenAllowValue allowReason;
@ -6210,25 +6232,6 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
}
}
// Note: it's very important that this be an nsXPIDLCString, since we want
// .get() on it to return nsnull until we write stuff to it. The window
// watcher expects a null URL string if there is no URL to load.
nsXPIDLCString url;
nsresult rv = NS_OK;
if (!aUrl.IsEmpty()) {
AppendUTF16toUTF8(aUrl, url);
/* Check whether the URI is allowed, but not for dialogs --
see bug 56851. The security of this function depends on
window.openDialog being inaccessible from web scripts */
if (url.get() && !aDialog)
rv = SecurityCheckURL(url.get());
}
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMWindow> domReturn;
nsCOMPtr<nsIWindowWatcher> wwatch =