Bug 805807 - Make Components wrapper throw on denial. r=mrbkap

There's really no reason to use the wishy-washy static COW Deny() here.

Also, note that the xpcshell-test wasn't testing what it thought it
was - interfaces is accessible from content code.
This commit is contained in:
Bobby Holley 2012-11-02 13:27:59 +01:00
Родитель e21debf331
Коммит f485a6c791
4 изменённых файлов: 28 добавлений и 22 удалений

Просмотреть файл

@ -42,7 +42,6 @@ function checkStylesheets() {
function runTest() { function runTest() {
const Ci = SpecialPowers.Ci; const Ci = SpecialPowers.Ci;
const Cc = SpecialPowers.Components.classes;
/** Found while fixing bug 440614 **/ /** Found while fixing bug 440614 **/
var editframe = window.frames[0]; var editframe = window.frames[0];

Просмотреть файл

@ -1,5 +1,6 @@
const Cu = Components.utils;
function run_test() { function run_test() {
var Cu = Components.utils;
var sb1 = Cu.Sandbox("http://www.blah.com"); var sb1 = Cu.Sandbox("http://www.blah.com");
var sb2 = Cu.Sandbox("http://www.blah.com"); var sb2 = Cu.Sandbox("http://www.blah.com");
var sb3 = Cu.Sandbox(this); var sb3 = Cu.Sandbox(this);
@ -13,25 +14,19 @@ function run_test() {
// non-chrome accessing chrome Components // non-chrome accessing chrome Components
sb1.C = Components; sb1.C = Components;
rv = Cu.evalInSandbox("C.utils", sb1); checkThrows("C.utils", sb1);
do_check_eq(rv, undefined); checkThrows("C.classes", sb1);
rv = Cu.evalInSandbox("C.interfaces", sb1);
do_check_neq(rv, undefined);
// non-chrome accessing own Components // non-chrome accessing own Components
rv = Cu.evalInSandbox("Components.utils", sb1); checkThrows("Components.utils", sb1);
do_check_eq(rv, undefined); checkThrows("Components.classes", sb1);
rv = Cu.evalInSandbox("Components.interfaces", sb1);
do_check_neq(rv, undefined);
// non-chrome same origin // non-chrome same origin
var C2 = Cu.evalInSandbox("Components", sb2); var C2 = Cu.evalInSandbox("Components", sb2);
do_check_neq(rv, C2.utils); do_check_neq(rv, C2.utils);
sb1.C2 = C2; sb1.C2 = C2;
rv = Cu.evalInSandbox("C2.utils", sb1); checkThrows("C2.utils", sb1);
do_check_eq(rv, undefined); checkThrows("C2.classes", sb1);
rv = Cu.evalInSandbox("C2.interfaces", sb1);
do_check_neq(rv, undefined);
// chrome accessing chrome // chrome accessing chrome
sb3.C = Components; sb3.C = Components;
@ -40,9 +35,11 @@ function run_test() {
// non-chrome cross origin // non-chrome cross origin
sb4.C2 = C2; sb4.C2 = C2;
rv = Cu.evalInSandbox("C2.interfaces", sb1); checkThrows("C2.utils", sb1);
do_check_neq(rv, undefined); checkThrows("C2.classes", sb1);
rv = Cu.evalInSandbox("C2.utils", sb1); }
do_check_eq(rv, undefined);
function checkThrows(expression, sb) {
var result = Cu.evalInSandbox('(function() { try { ' + expression + '; return "allowed"; } catch (e) { return e.toString(); }})();', sb);
do_check_true(!!/denied/.exec(result));
} }

Просмотреть файл

@ -523,7 +523,8 @@ ComponentsObjectPolicy::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper
return true; return true;
} }
return Deny(cx, id, act); AccessCheck::deny(cx, id);
return false;
} }
} }

Просмотреть файл

@ -18,6 +18,15 @@
return false; return false;
} }
function CcDenied() {
try {
Components.classes;
return false;
} catch (e) {
return !!/denied/.exec(e);
}
}
// Build an object with test results (true = pass) // Build an object with test results (true = pass)
let results = { let results = {
windowTop: window.top == window, windowTop: window.top == window,
@ -28,7 +37,7 @@
.docCharsetIsForced; .docCharsetIsForced;
}), }),
ccAccess: SpecialPowers.Components.classes == null, ccAccess: !!CcDenied(),
}; };
let resultsJSON = JSON.stringify(results); let resultsJSON = JSON.stringify(results);