function examiner() {
SpecialPowers.addObserver(this, "csp-on-violate-policy");
SpecialPowers.addObserver(this, "specialpowers-http-notify-request");
}
examiner.prototype = {
observe(subject, topic, data) { var testpat = new RegExp("testid=([a-zA-Z]+)");
if (topic === "specialpowers-http-notify-request") { var uri = data;
if (!testpat.test(uri)) return; var testid = testpat.exec(uri)[1];
window.testResult(testid,
/Loaded/.test(testid), "resource loaded");
}
if(topic === "csp-on-violate-policy") {
// these were blocked... record that they were blocked
// try because the subject could be an nsIURI or an nsISupportsCString
try { var asciiSpec = SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(subject, "nsIURI"), "asciiSpec");
if (!testpat.test(asciiSpec)) return; var testid = testpat.exec(asciiSpec)[1];
window.testResult(testid,
/Blocked/.test(testid), "resource blocked by CSP");
} catch(e) {
// if that fails, the subject is probably a string. Strings are only
// reported for inline and eval violations. Since we are testing those
// via the observed effects of script on CSSOM, we can simply ignore
// these subjects.
}
}
},
// must eventually call this to remove the listener,
// or mochitests might get borked.
remove() {
SpecialPowers.removeObserver(this, "csp-on-violate-policy");
SpecialPowers.removeObserver(this, "specialpowers-http-notify-request");
}
}
// Helpers for inline script/style checks var black = 'rgb(0, 0, 0)'; var green = 'rgb(0, 128, 0)';
function getElementColorById(doc, id) {
return window.getComputedStyle(doc.contentDocument.getElementById(id)).color;
}
function checkInlineWithStar() { var testframe = document.getElementById('testframe1');
window.testResult("starInlineStyleAllowed",
getElementColorById(testframe, 'inline-style') === green, "Inline styles should be allowed (style-src 'unsafe-inline' with star)");
window.testResult("starInlineScriptBlocked",
getElementColorById(testframe, 'inline-script') === black, "Inline scripts should be blocked (style-src 'unsafe-inline' with star)");
}
function checkInlineWithNone() {
// If a directive has 'none' in addition to other sources, 'none' is ignored
// and the other sources are used. 'none' is only a valid source if it is
// used by itself. var testframe = document.getElementById('testframe2');
window.testResult("noneInlineStyleAllowed",
getElementColorById(testframe, 'inline-style') === green, "Inline styles should be allowed (style-src 'unsafe-inline' with none)");
window.testResult("noneInlineScriptBlocked",
getElementColorById(testframe, 'inline-script') === black, "Inline scripts should be blocked (style-src 'unsafe-inline' with none)");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.