// Regression test for bug 1960363. Verifies that the pdf.js viewer document // ships with a Content-Security-Policy that locks down scripts (no inline, // no eval, only resource:), and that real violations are routed through the // shared internal-page CSP telemetry in nsCSPContext::HandleInternalPageViolation.
const D = Ci.nsIContentSecurityPolicy; // Non-pdf.js URIs go through the real CSP checks. resource://pdf.js/* // is short-circuited inside nsCSPContext::Permits (see hotfix there), // so it can't be used to probe the policy. const httpsURI = Services.io.newURI("https://example.com/x.js"); const resourceURI = Services.io.newURI("resource://gre/modules/x.js");
// Trigger a real violation in the viewer document. With the loading // principal's URI now considered by HandleInternalPageViolation, the // event must land in Glean.security.cspViolationInternalPage.
await SpecialPowers.spawn(browser, [], async function () { const violation = ContentTaskUtils.waitForEvent(
content.document, "securitypolicyviolation"
);
content.document.documentElement.setAttribute("onclick", "foobar()");
await violation;
});
// Flush before closing the viewer: closing tears down the content // process and discards any not-yet-flushed Glean events.
await Services.fog.testFlushAllChildren();
await waitForPdfJSClose(browser);
}
);
const events = Glean.security.cspViolationInternalPage.testGetValue(); Assert.ok(
Array.isArray(events) && events.length >= 1, "internal-page CSP violation telemetry recorded"
); const viewerEvent = events.find(e => e.extra.selfdetails === VIEWER_URL); Assert.ok(viewerEvent, "a violation was recorded for the pdf.js viewer"); Assert.equal(
viewerEvent.extra.selftype, "resourceuri", "selftype is resourceuri"
);
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.