Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 2530343006: CSP: "local schemes" should inherit policy when window.opened. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/Document.cpp
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
index 8a394b442085bdb71681852e61ec9f615ff941ec..844c2365322efaf4edce4827ccdb268edeba2706 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -5506,26 +5506,31 @@ void Document::initSecurityContext(const DocumentInit& initializer) {
void Document::initContentSecurityPolicy(ContentSecurityPolicy* csp) {
setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create());
- if (m_frame && m_frame->tree().parent() &&
- m_frame->tree().parent()->isLocalFrame()) {
- ContentSecurityPolicy* parentCSP = toLocalFrame(m_frame->tree().parent())
- ->document()
- ->contentSecurityPolicy();
-
- // We inherit the parent frame's CSP for documents with "local" schemes:
- // 'about', 'blob', 'data', and 'filesystem'. We also inherit the parent
- // frame's CSP for documents with empty/invalid URLs because we treat
- // those URLs as 'about:blank' in Blink.
- //
- // https://w3c.github.io/webappsec-csp/#initialize-document-csp
+
+ // We inherit the parent/opener's CSP for documents with "local" schemes:
+ // 'about', 'blob', 'data', and 'filesystem'. We also inherit CSP for
+ // documents with empty/invalid URLs because we treat those URLs as
+ // 'about:blank' in Blink.
+ //
+ // https://w3c.github.io/webappsec-csp/#initialize-document-csp
+ Frame* inheritFrom = nullptr;
+ if (m_frame && m_frame->tree().parent())
dcheng 2016/11/29 22:37:23 Random musing: this feels kind of similar to https
+ inheritFrom = m_frame->tree().parent();
+ else if (m_frame && m_frame->client())
dcheng 2016/11/29 22:37:23 Nit: I think we should be able to assume client()
+ inheritFrom = m_frame->client()->opener();
+ if (inheritFrom) {
+ DCHECK(inheritFrom->securityContext() &&
+ inheritFrom->securityContext()->contentSecurityPolicy());
+ ContentSecurityPolicy* policyToInherit =
+ inheritFrom->securityContext()->contentSecurityPolicy();
if (m_url.isEmpty() || m_url.protocolIsAbout() || m_url.protocolIsData() ||
m_url.protocolIs("blob") || m_url.protocolIs("filesystem")) {
- contentSecurityPolicy()->copyStateFrom(parentCSP);
- } else if (isPluginDocument()) {
- // Per CSP2, plugin-types for plugin documents in nested browsing
- // contexts gets inherited from the parent.
- contentSecurityPolicy()->copyPluginTypesFrom(parentCSP);
+ contentSecurityPolicy()->copyStateFrom(policyToInherit);
}
+ // Plugin documents inherit their parent/opener's 'plugin-types' directive
+ // regardless of URL.
+ if (isPluginDocument())
+ contentSecurityPolicy()->copyPluginTypesFrom(policyToInherit);
}
contentSecurityPolicy()->bindToExecutionContext(this);
}
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/cascade/same-origin-with-own-policy-window-open.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698