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

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

Issue 2530343006: CSP: "local schemes" should inherit policy when window.opened. (Closed)
Patch Set: feedback Created 4 years 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..aa7ab9483abb36bde3fbe56b24f1ad0fc3f2a08d 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -5506,25 +5506,33 @@ 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
- 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);
+
+ // 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
+ //
+ // TODO(dcheng): This is similar enough to work we're doing in
+ // 'DocumentLoader::ensureWriter' that it might make sense to combine them.
+ if (m_frame) {
+ Frame* inheritFrom = m_frame->tree().parent() ? m_frame->tree().parent()
+ : m_frame->client()->opener();
+ if (inheritFrom && m_frame != 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(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