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

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: alexmos comments Created 4 years, 9 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 3368 matching lines...) Expand 10 before | Expand all | Expand 10 after
3379 // Additionally, with 3379 // Additionally, with
3380 // <iframe src="scheme-has-exception://host"> 3380 // <iframe src="scheme-has-exception://host">
3381 // <iframe src="http://host"></iframe> 3381 // <iframe src="http://host"></iframe>
3382 // <iframe sandbox src="http://host"></iframe> 3382 // <iframe sandbox src="http://host"></iframe>
3383 // </iframe> 3383 // </iframe>
3384 // both inner iframes would fail the check, even though the outermost iframe 3384 // both inner iframes would fail the check, even though the outermost iframe
3385 // passes. 3385 // passes.
3386 // 3386 //
3387 // In all cases, a frame must be potentially trustworthy in addition to 3387 // In all cases, a frame must be potentially trustworthy in addition to
3388 // having an exception listed in order for the exception to be granted. 3388 // having an exception listed in order for the exception to be granted.
3389 if (SecurityContext::isSandboxed(SandboxOrigin)) { 3389 if (!isOriginPotentiallyTrustworthy(securityOrigin(), errorMessage))
3390 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url()); 3390 return false;
3391 if (!isOriginPotentiallyTrustworthy(origin.get(), errorMessage)) 3391 if (SchemeRegistry::schemeShouldBypassSecureContextCheck(securityOrigin()->p rotocol()))
3392 return false; 3392 return true;
3393 if (SchemeRegistry::schemeShouldBypassSecureContextCheck(origin->protoco l()))
3394 return true;
3395 } else {
3396 if (!isOriginPotentiallyTrustworthy(securityOrigin(), errorMessage))
3397 return false;
3398 if (SchemeRegistry::schemeShouldBypassSecureContextCheck(securityOrigin( )->protocol()))
3399 return true;
3400 }
3401 3393
3402 if (privilegeContextCheck == StandardSecureContextCheck) { 3394 if (privilegeContextCheck == StandardSecureContextCheck) {
3403 Document* context = parentDocument(); 3395 if (!m_frame)
3404 while (context) { 3396 return true;
3405 // Skip to the next ancestor if it's a srcdoc. 3397 Frame* parent = m_frame->tree().parent();
3406 if (!context->isSrcdocDocument()) { 3398 while (parent) {
3407 if (context->securityContext().isSandboxed(SandboxOrigin)) { 3399 if (!isOriginPotentiallyTrustworthy(parent->securityContext()->secur ityOrigin(), errorMessage))
3408 // For a sandboxed origin, use the document's URL. 3400 return false;
3409 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(conte xt->url()); 3401 parent = parent->tree().parent();
3410 if (!isOriginPotentiallyTrustworthy(origin.get(), errorMessa ge))
3411 return false;
3412 } else {
3413 if (!isOriginPotentiallyTrustworthy(context->securityOrigin( ), errorMessage))
3414 return false;
3415 }
3416 }
3417 context = context->parentDocument();
3418 } 3402 }
3419 } 3403 }
3420 return true; 3404 return true;
3421 } 3405 }
3422 3406
3423 StyleSheetList* Document::styleSheets() 3407 StyleSheetList* Document::styleSheets()
3424 { 3408 {
3425 if (!m_styleSheetList) 3409 if (!m_styleSheetList)
3426 m_styleSheetList = StyleSheetList::create(this); 3410 m_styleSheetList = StyleSheetList::create(this);
3427 return m_styleSheetList.get(); 3411 return m_styleSheetList.get();
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after
4935 enforceStrictMixedContentChecking(); 4919 enforceStrictMixedContentChecking();
4936 setInsecureRequestsPolicy(initializer.getInsecureRequestsPolicy()); 4920 setInsecureRequestsPolicy(initializer.getInsecureRequestsPolicy());
4937 if (initializer.insecureNavigationsToUpgrade()) { 4921 if (initializer.insecureNavigationsToUpgrade()) {
4938 for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade()) 4922 for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade())
4939 addInsecureNavigationUpgrade(toUpgrade); 4923 addInsecureNavigationUpgrade(toUpgrade);
4940 } 4924 }
4941 4925
4942 if (isSandboxed(SandboxOrigin)) { 4926 if (isSandboxed(SandboxOrigin)) {
4943 m_cookieURL = m_url; 4927 m_cookieURL = m_url;
4944 setSecurityOrigin(SecurityOrigin::createUnique()); 4928 setSecurityOrigin(SecurityOrigin::createUnique());
4945 // If we're supposed to inherit our security origin from our owner, 4929 // If we're supposed to inherit our security origin from our
4946 // but we're also sandboxed, the only thing we inherit is the ability 4930 // owner, but we're also sandboxed, the only things we inherit are
4947 // to load local resources. This lets about:blank iframes in file:// 4931 // the origin's potential trustworthiness and the ability to
4948 // URL documents load images and other resources from the file system. 4932 // load local resources. The latter lets about:blank iframes in
4933 // file:// URL documents load images and other resources from
4934 // the file system.
4935 if (initializer.owner() && initializer.owner()->securityOrigin()->isPote ntiallyTrustworthy())
4936 securityOrigin()->setUniqueOriginIsPotentiallyTrustworthy(true);
4949 if (initializer.owner() && initializer.owner()->securityOrigin()->canLoa dLocalResources()) 4937 if (initializer.owner() && initializer.owner()->securityOrigin()->canLoa dLocalResources())
4950 securityOrigin()->grantLoadLocalResources(); 4938 securityOrigin()->grantLoadLocalResources();
4951 } else if (initializer.owner()) { 4939 } else if (initializer.owner()) {
4952 m_cookieURL = initializer.owner()->cookieURL(); 4940 m_cookieURL = initializer.owner()->cookieURL();
4953 // We alias the SecurityOrigins to match Firefox, see Bug 15313 4941 // We alias the SecurityOrigins to match Firefox, see Bug 15313
4954 // https://bugs.webkit.org/show_bug.cgi?id=15313 4942 // https://bugs.webkit.org/show_bug.cgi?id=15313
4955 setSecurityOrigin(initializer.owner()->securityOrigin()); 4943 setSecurityOrigin(initializer.owner()->securityOrigin());
4956 } else { 4944 } else {
4957 m_cookieURL = m_url; 4945 m_cookieURL = m_url;
4958 setSecurityOrigin(SecurityOrigin::create(m_url)); 4946 setSecurityOrigin(SecurityOrigin::create(m_url));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4994 securityOrigin()->blockLocalAccessFromLocalOrigin(); 4982 securityOrigin()->blockLocalAccessFromLocalOrigin();
4995 } 4983 }
4996 } 4984 }
4997 } 4985 }
4998 4986
4999 if (initializer.shouldTreatURLAsSrcdocDocument()) { 4987 if (initializer.shouldTreatURLAsSrcdocDocument()) {
5000 m_isSrcdocDocument = true; 4988 m_isSrcdocDocument = true;
5001 setBaseURLOverride(initializer.parentBaseURL()); 4989 setBaseURLOverride(initializer.parentBaseURL());
5002 } 4990 }
5003 4991
5004 if (securityOrigin()->hasSuborigin()) 4992 if (securityOrigin()->isUnique() && SecurityOrigin::create(m_url)->isPotenti allyTrustworthy())
5005 enforceSuborigin(securityOrigin()->suboriginName()); 4993 securityOrigin()->setUniqueOriginIsPotentiallyTrustworthy(true);
5006 } 4994 }
5007 4995
5008 void Document::initContentSecurityPolicy(PassRefPtrWillBeRawPtr<ContentSecurityP olicy> csp) 4996 void Document::initContentSecurityPolicy(PassRefPtrWillBeRawPtr<ContentSecurityP olicy> csp)
5009 { 4997 {
5010 setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create()); 4998 setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create());
5011 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal Frame()) { 4999 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal Frame()) {
5012 ContentSecurityPolicy* parentCSP = toLocalFrame(m_frame->tree().parent() )->document()->contentSecurityPolicy(); 5000 ContentSecurityPolicy* parentCSP = toLocalFrame(m_frame->tree().parent() )->document()->contentSecurityPolicy();
5013 if (shouldInheritSecurityOriginFromOwner(m_url)) { 5001 if (shouldInheritSecurityOriginFromOwner(m_url)) {
5014 contentSecurityPolicy()->copyStateFrom(parentCSP); 5002 contentSecurityPolicy()->copyStateFrom(parentCSP);
5015 } else if (isPluginDocument()) { 5003 } else if (isPluginDocument()) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
5056 LocalFrame* frame = executingFrame(); 5044 LocalFrame* frame = executingFrame();
5057 if (!frame) 5045 if (!frame)
5058 return false; 5046 return false;
5059 if (!node->document().executingFrame()) 5047 if (!node->document().executingFrame())
5060 return false; 5048 return false;
5061 if (!frame->script().canExecuteScripts(AboutToExecuteScript)) 5049 if (!frame->script().canExecuteScripts(AboutToExecuteScript))
5062 return false; 5050 return false;
5063 return true; 5051 return true;
5064 } 5052 }
5065 5053
5054 void Document::enforceSandboxFlags(SandboxFlags mask)
5055 {
5056 RefPtr<SecurityOrigin> standInOrigin = securityOrigin();
5057 applySandboxFlags(mask);
5058 // Send a notification if the origin has been updated.
5059 if (standInOrigin && !standInOrigin->isUnique() && securityOrigin()->isUniqu e()) {
5060 securityOrigin()->setUniqueOriginIsPotentiallyTrustworthy(standInOrigin- >isPotentiallyTrustworthy());
5061 if (frame())
5062 frame()->loader().client()->didUpdateToUniqueOrigin();
5063 }
5064 }
5065
5066 void Document::updateSecurityOrigin(PassRefPtr<SecurityOrigin> origin) 5066 void Document::updateSecurityOrigin(PassRefPtr<SecurityOrigin> origin)
5067 { 5067 {
5068 setSecurityOrigin(origin); 5068 setSecurityOrigin(origin);
5069 didUpdateSecurityOrigin(); 5069 didUpdateSecurityOrigin();
5070 } 5070 }
5071 5071
5072 void Document::didUpdateSecurityOrigin() 5072 void Document::didUpdateSecurityOrigin()
5073 { 5073 {
5074 if (!m_frame) 5074 if (!m_frame)
5075 return; 5075 return;
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
5996 #ifndef NDEBUG 5996 #ifndef NDEBUG
5997 using namespace blink; 5997 using namespace blink;
5998 void showLiveDocumentInstances() 5998 void showLiveDocumentInstances()
5999 { 5999 {
6000 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 6000 Document::WeakDocumentSet& set = Document::liveDocumentSet();
6001 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 6001 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
6002 for (Document* document : set) 6002 for (Document* document : set)
6003 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 6003 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
6004 } 6004 }
6005 #endif 6005 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698