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

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 1723753002: Make Document::isSecureContext() work for OOPIFs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 3371 matching lines...) Expand 10 before | Expand all | Expand 10 after
3382 // <iframe src="scheme-has-exception://host"> 3382 // <iframe src="scheme-has-exception://host">
3383 // <iframe src="http://host"></iframe> 3383 // <iframe src="http://host"></iframe>
3384 // <iframe sandbox src="http://host"></iframe> 3384 // <iframe sandbox src="http://host"></iframe>
3385 // </iframe> 3385 // </iframe>
3386 // both inner iframes would fail the check, even though the outermost iframe 3386 // both inner iframes would fail the check, even though the outermost iframe
3387 // passes. 3387 // passes.
3388 // 3388 //
3389 // In all cases, a frame must be potentially trustworthy in addition to 3389 // In all cases, a frame must be potentially trustworthy in addition to
3390 // having an exception listed in order for the exception to be granted. 3390 // having an exception listed in order for the exception to be granted.
3391 if (SecurityContext::isSandboxed(SandboxOrigin)) { 3391 if (SecurityContext::isSandboxed(SandboxOrigin)) {
3392 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url()); 3392 if (!SecurityContext::isPotentiallyTrustworthySandboxedOrigin()) {
3393 if (!isOriginPotentiallyTrustworthy(origin.get(), errorMessage)) 3393 if (errorMessage)
3394 *errorMessage = securityOrigin()->isPotentiallyTrustworthyErrorM essage();
3394 return false; 3395 return false;
3395 if (SchemeRegistry::schemeShouldBypassSecureContextCheck(origin->protoco l())) 3396 }
3397 if (SecurityContext::bypassSecureContextCheckForSandboxedOrigin())
3396 return true; 3398 return true;
3397 } else { 3399 } else {
3398 if (!isOriginPotentiallyTrustworthy(securityOrigin(), errorMessage)) 3400 if (!isOriginPotentiallyTrustworthy(securityOrigin(), errorMessage))
3399 return false; 3401 return false;
3400 if (SchemeRegistry::schemeShouldBypassSecureContextCheck(securityOrigin( )->protocol())) 3402 if (SchemeRegistry::schemeShouldBypassSecureContextCheck(securityOrigin( )->protocol()))
3401 return true; 3403 return true;
3402 } 3404 }
3403 3405
3404 if (privilegeContextCheck == StandardSecureContextCheck) { 3406 if (privilegeContextCheck == StandardSecureContextCheck) {
3405 Document* context = parentDocument(); 3407 if (!m_frame)
3406 while (context) { 3408 return true;
3407 // Skip to the next ancestor if it's a srcdoc. 3409 Frame* parent = m_frame->tree().parent();
3408 if (!context->isSrcdocDocument()) { 3410 while (parent) {
3409 if (context->securityContext().isSandboxed(SandboxOrigin)) { 3411 if (parent->securityContext()->isSandboxed(SandboxOrigin)) {
3410 // For a sandboxed origin, use the document's URL. 3412 if (!parent->securityContext()->isPotentiallyTrustworthySandboxe dOrigin()) {
3411 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(conte xt->url()); 3413 if (errorMessage)
3412 if (!isOriginPotentiallyTrustworthy(origin.get(), errorMessa ge)) 3414 *errorMessage = parent->securityContext()->securityOrigi n()->isPotentiallyTrustworthyErrorMessage();
3413 return false; 3415 return false;
3414 } else {
3415 if (!isOriginPotentiallyTrustworthy(context->securityOrigin( ), errorMessage))
3416 return false;
3417 } 3416 }
3417 } else {
3418 if (!isOriginPotentiallyTrustworthy(parent->securityContext()->s ecurityOrigin(), errorMessage))
3419 return false;
3418 } 3420 }
3419 context = context->parentDocument(); 3421 parent = parent->tree().parent();
3420 } 3422 }
3421 } 3423 }
3422 return true; 3424 return true;
3423 } 3425 }
3424 3426
3425 StyleSheetList* Document::styleSheets() 3427 StyleSheetList* Document::styleSheets()
3426 { 3428 {
3427 if (!m_styleSheetList) 3429 if (!m_styleSheetList)
3428 m_styleSheetList = StyleSheetList::create(this); 3430 m_styleSheetList = StyleSheetList::create(this);
3429 return m_styleSheetList.get(); 3431 return m_styleSheetList.get();
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after
4891 // This can occur via document.implementation.createDocument(). 4893 // This can occur via document.implementation.createDocument().
4892 m_cookieURL = KURL(ParsedURLString, emptyString()); 4894 m_cookieURL = KURL(ParsedURLString, emptyString());
4893 setSecurityOrigin(SecurityOrigin::createUnique()); 4895 setSecurityOrigin(SecurityOrigin::createUnique());
4894 initContentSecurityPolicy(); 4896 initContentSecurityPolicy();
4895 return; 4897 return;
4896 } 4898 }
4897 4899
4898 // In the common case, create the security context from the currently 4900 // In the common case, create the security context from the currently
4899 // loading URL with a fresh content security policy. 4901 // loading URL with a fresh content security policy.
4900 m_cookieURL = m_url; 4902 m_cookieURL = m_url;
4903 // Set the origin initially based on the URL. enforceSandboxFlags()
4904 // will adjust it to be a unique origin if necessary.
4905 setSecurityOrigin(SecurityOrigin::create(m_url));
4901 enforceSandboxFlags(initializer.sandboxFlags()); 4906 enforceSandboxFlags(initializer.sandboxFlags());
4902 if (initializer.shouldEnforceStrictMixedContentChecking()) 4907 if (initializer.shouldEnforceStrictMixedContentChecking())
4903 enforceStrictMixedContentChecking(); 4908 enforceStrictMixedContentChecking();
4904 setInsecureRequestsPolicy(initializer.insecureRequestsPolicy()); 4909 setInsecureRequestsPolicy(initializer.insecureRequestsPolicy());
4905 if (initializer.insecureNavigationsToUpgrade()) { 4910 if (initializer.insecureNavigationsToUpgrade()) {
4906 for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade()) 4911 for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade())
4907 addInsecureNavigationUpgrade(toUpgrade); 4912 addInsecureNavigationUpgrade(toUpgrade);
4908 } 4913 }
4909 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique( ) : SecurityOrigin::create(m_url));
4910 4914
4911 if (importsController()) { 4915 if (importsController()) {
4912 // If this document is an HTML import, grab a reference to it's master d ocument's Content 4916 // If this document is an HTML import, grab a reference to it's master d ocument's Content
4913 // Security Policy. We don't call 'initContentSecurityPolicy' in this ca se, as we can't 4917 // Security Policy. We don't call 'initContentSecurityPolicy' in this ca se, as we can't
4914 // rebind the master document's policy object: its ExecutionContext need s to remain tied 4918 // rebind the master document's policy object: its ExecutionContext need s to remain tied
4915 // to the master document. 4919 // to the master document.
4916 setContentSecurityPolicy(importsController()->master()->contentSecurityP olicy()); 4920 setContentSecurityPolicy(importsController()->master()->contentSecurityP olicy());
4917 } else { 4921 } else {
4918 initContentSecurityPolicy(); 4922 initContentSecurityPolicy();
4919 } 4923 }
(...skipping 25 matching lines...) Expand all
4945 // If we do not obtain a meaningful origin from the URL, then we try to 4949 // If we do not obtain a meaningful origin from the URL, then we try to
4946 // find one via the frame hierarchy. 4950 // find one via the frame hierarchy.
4947 4951
4948 if (!initializer.owner()) { 4952 if (!initializer.owner()) {
4949 didFailToInitializeSecurityOrigin(); 4953 didFailToInitializeSecurityOrigin();
4950 return; 4954 return;
4951 } 4955 }
4952 4956
4953 if (isSandboxed(SandboxOrigin)) { 4957 if (isSandboxed(SandboxOrigin)) {
4954 // If we're supposed to inherit our security origin from our owner, 4958 // If we're supposed to inherit our security origin from our owner,
4955 // but we're also sandboxed, the only thing we inherit is the ability 4959 // but we're also sandboxed, the only things we inherit are the
4956 // to load local resources. This lets about:blank iframes in file:// 4960 // potential trustworthiness of the origin and the ability to
4961 // load local resources. This lets about:blank iframes in file://
4957 // URL documents load images and other resources from the file system. 4962 // URL documents load images and other resources from the file system.
4963 if (initializer.owner()->isPotentiallyTrustworthySandboxedOrigin() || in itializer.owner()->securityOrigin()->isPotentiallyTrustworthy())
4964 setIsPotentiallyTrustworthySandboxedOrigin();
4958 if (initializer.owner()->securityOrigin()->canLoadLocalResources()) 4965 if (initializer.owner()->securityOrigin()->canLoadLocalResources())
4959 securityOrigin()->grantLoadLocalResources(); 4966 securityOrigin()->grantLoadLocalResources();
4960 return; 4967 return;
4961 } 4968 }
4962 4969
4963 m_cookieURL = initializer.owner()->cookieURL(); 4970 m_cookieURL = initializer.owner()->cookieURL();
4964 // We alias the SecurityOrigins to match Firefox, see Bug 15313 4971 // We alias the SecurityOrigins to match Firefox, see Bug 15313
4965 // https://bugs.webkit.org/show_bug.cgi?id=15313 4972 // https://bugs.webkit.org/show_bug.cgi?id=15313
4966 setSecurityOrigin(initializer.owner()->securityOrigin()); 4973 setSecurityOrigin(initializer.owner()->securityOrigin());
4967 } 4974 }
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
5945 #ifndef NDEBUG 5952 #ifndef NDEBUG
5946 using namespace blink; 5953 using namespace blink;
5947 void showLiveDocumentInstances() 5954 void showLiveDocumentInstances()
5948 { 5955 {
5949 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 5956 Document::WeakDocumentSet& set = Document::liveDocumentSet();
5950 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5957 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5951 for (Document* document : set) 5958 for (Document* document : set)
5952 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5959 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5953 } 5960 }
5954 #endif 5961 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698