Bug 1377426 - Set CSP on freshly created nullprincipal when iframe is sandboxed. r=dveditz

This commit is contained in:
Christoph Kerschbaumer 2017-07-11 08:48:37 +02:00
Родитель 88d86847fe
Коммит 250d4b1ff8
2 изменённых файлов: 17 добавлений и 4 удалений

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

@ -2792,10 +2792,14 @@ nsDocument::InitCSP(nsIChannel* aChannel)
mSandboxFlags |= cspSandboxFlags; mSandboxFlags |= cspSandboxFlags;
if (cspSandboxFlags & SANDBOXED_ORIGIN) { // Probably the iframe sandbox attribute already caused the creation of a
// If the new CSP sandbox flags do not have the allow-same-origin flag // new NullPrincipal. Only create a new NullPrincipal if CSP requires so
// reset the document principal to a null principal // and no one has been created yet.
principal = NullPrincipal::Create(); bool needNewNullPrincipal =
(cspSandboxFlags & SANDBOXED_ORIGIN) && !(mSandboxFlags & SANDBOXED_ORIGIN);
if (needNewNullPrincipal) {
principal = NullPrincipal::CreateWithInheritedAttributes(principal);
principal->SetCsp(csp);
SetPrincipal(principal); SetPrincipal(principal);
} }

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

@ -106,6 +106,15 @@ var testCases = [
results: { img12_bad: -1, script12_bad: -1 }, results: { img12_bad: -1, script12_bad: -1 },
nrOKmessages: 4 // sends 4 ok message nrOKmessages: 4 // sends 4 ok message
}, },
{
// Test 13: same as Test 5 and Test 11, but:
// * using sandbox flag 'allow-scripts' in CSP and not as iframe attribute
// * not using allow-same-origin in CSP (so a new NullPrincipal is created).
csp: "default-src 'none'; script-src 'unsafe-inline'; sandbox allow-scripts",
file: "file_sandbox_5.html",
results: { img13_bad: -1, img13a_bad: -1, script13_bad: -1, script13a_bad: -1 },
nrOKmessages: 2 // sends 2 ok message
},
]; ];
// a postMessage handler that is used by sandboxed iframes without // a postMessage handler that is used by sandboxed iframes without