mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 754202 - Disallow calling EvaluateString{,WithValue} with a principal that doesn't match the global. r=mrbkap
This commit is contained in:
parent
285b2d0a7e
commit
ebec529f3b
@ -1199,27 +1199,29 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
||||
xpc_UnmarkGrayObject(aScopeObject);
|
||||
nsAutoMicroTask mt;
|
||||
|
||||
// Safety first: get an object representing the script's principals, i.e.,
|
||||
// the entities who signed this script, or the fully-qualified-domain-name
|
||||
// or "codebase" from which it was loaded.
|
||||
nsCOMPtr<nsIPrincipal> principal = aPrincipal;
|
||||
nsresult rv;
|
||||
if (!aPrincipal) {
|
||||
nsIScriptGlobalObject *global = GetGlobalObject();
|
||||
if (!global)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
|
||||
do_QueryInterface(global, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
// Ignore the principal that was passed in, and just assert that it matches
|
||||
// the one we pull off the global.
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(GetGlobalObject());
|
||||
if (!objPrincipal)
|
||||
return NS_ERROR_FAILURE;
|
||||
principal = objPrincipal->GetPrincipal();
|
||||
if (!principal)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
bool equal = false;
|
||||
principal->Equals(aPrincipal, &equal);
|
||||
MOZ_ASSERT(equal);
|
||||
nsIPrincipal *scopeObjectPrincipal =
|
||||
nsJSPrincipals::get(JS_GetCompartmentPrincipals(js::GetObjectCompartment(aScopeObject)));
|
||||
equal = false;
|
||||
principal->Equals(scopeObjectPrincipal, &equal);
|
||||
MOZ_ASSERT(equal);
|
||||
#endif
|
||||
|
||||
bool ok = false;
|
||||
|
||||
rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok);
|
||||
nsresult rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -1401,19 +1403,25 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
|
||||
xpc_UnmarkGrayObject(aScopeObject);
|
||||
|
||||
// Safety first: get an object representing the script's principals, i.e.,
|
||||
// the entities who signed this script, or the fully-qualified-domain-name
|
||||
// or "codebase" from which it was loaded.
|
||||
nsCOMPtr<nsIPrincipal> principal = aPrincipal;
|
||||
if (!aPrincipal) {
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
|
||||
do_QueryInterface(GetGlobalObject());
|
||||
// Ignore the principal that was passed in, and just assert that it matches
|
||||
// the one we pull off the global.
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(GetGlobalObject());
|
||||
if (!objPrincipal)
|
||||
return NS_ERROR_FAILURE;
|
||||
principal = objPrincipal->GetPrincipal();
|
||||
if (!principal)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
bool equal = false;
|
||||
principal->Equals(aPrincipal, &equal);
|
||||
MOZ_ASSERT(equal);
|
||||
nsIPrincipal *scopeObjectPrincipal =
|
||||
nsJSPrincipals::get(JS_GetCompartmentPrincipals(js::GetObjectCompartment(aScopeObject)));
|
||||
equal = false;
|
||||
principal->Equals(scopeObjectPrincipal, &equal);
|
||||
MOZ_ASSERT(equal);
|
||||
#endif
|
||||
|
||||
bool ok = false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user