Bug 867486 - Remove |Components| from content sandboxes. r=gabor

This commit is contained in:
Bobby Holley 2013-07-08 10:05:31 -07:00
parent 6075a3d281
commit fb8f42b563
6 changed files with 33 additions and 9 deletions

View File

@ -1310,6 +1310,11 @@ public:
*/
static bool IsSystemPrincipal(nsIPrincipal* aPrincipal);
/**
* Returns true if aPrincipal is an nsExpandedPrincipal.
*/
static bool IsExpandedPrincipal(nsIPrincipal* aPrincipal);
/**
* Gets the system principal from the security manager.
*/

View File

@ -4360,6 +4360,13 @@ nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal)
return NS_SUCCEEDED(rv) && isSystem;
}
bool
nsContentUtils::IsExpandedPrincipal(nsIPrincipal* aPrincipal)
{
nsCOMPtr<nsIExpandedPrincipal> ep = do_QueryInterface(aPrincipal);
return !!ep;
}
nsIPrincipal*
nsContentUtils::GetSystemPrincipal()
{

View File

@ -3336,15 +3336,14 @@ xpc_CreateSandboxObject(JSContext *cx, jsval *vp, nsISupports *prinOrSop, Sandbo
// Pass on ownership of sbp to |sandbox|.
JS_SetPrivate(sandbox, sbp.forget().get());
{
JSAutoCompartment ac(cx, sandbox);
if (options.wantComponents &&
!nsXPCComponents::AttachComponentsObject(cx, GetObjectScope(sandbox)))
return NS_ERROR_XPC_UNEXPECTED;
bool allowComponents = nsContentUtils::IsSystemPrincipal(principal) ||
nsContentUtils::IsExpandedPrincipal(principal);
if (options.wantComponents && allowComponents &&
!nsXPCComponents::AttachComponentsObject(cx, GetObjectScope(sandbox)))
return NS_ERROR_XPC_UNEXPECTED;
if (!XPCNativeWrapper::AttachNewConstructorObject(cx, sandbox))
return NS_ERROR_XPC_UNEXPECTED;
}
if (!XPCNativeWrapper::AttachNewConstructorObject(cx, sandbox))
return NS_ERROR_XPC_UNEXPECTED;
if (!JS_DefineFunctions(cx, sandbox, SandboxFunctions))
return NS_ERROR_XPC_UNEXPECTED;

View File

@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Cu = Components.utils;
function run_test() {
var sb = new Cu.Sandbox('http://www.example.com', { wantComponents: true } );
do_check_false(Cu.evalInSandbox('"Components" in this', sb));
}

View File

@ -2,7 +2,9 @@ const Cu = Components.utils;
function run_test() {
// Make a content sandbox with an Xrayable object.
var contentSB = new Cu.Sandbox('http://www.google.com',
// NB: We use an nsEP here so that we can have access to Components, but still
// have Xray behavior from this scope.
var contentSB = new Cu.Sandbox(['http://www.google.com'],
{wantXHRConstructor: true, wantComponents: true});
// Make an XHR in the content sandbox.

View File

@ -21,6 +21,7 @@ tail =
[test_bug851895.js]
[test_bug854558.js]
[test_bug868675.js]
[test_bug867486.js]
[test_bug872772.js]
[test_bug885800.js]
[test_bug_442086.js]