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

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

Issue 1504403003: Calling isSecureContext() with no arguments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small refactoring to isSecureContext() calls Created 5 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 5163577596583956aac44fb63d5c25e8caec1774..c6880856fe5d551d7c65a236fb2c2345697b0aa5 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -341,6 +341,13 @@ static bool acceptsEditingFocus(const Element& element)
return element.document().frame() && element.rootEditableElement();
}
+static bool isOriginPotentiallyTrustworthy(SecurityOrigin* origin, String* errorMessage)
+{
+ if (errorMessage)
+ return origin->isPotentiallyTrustworthy(*errorMessage);
+ return origin->isPotentiallyTrustworthy();
+}
+
uint64_t Document::s_globalTreeVersion = 0;
static bool s_threadedParsingEnabledForTesting = true;
@@ -3303,6 +3310,70 @@ void Document::cloneDataFromDocument(const Document& other)
setMimeType(other.contentType());
}
+bool Document::isSecureContextImpl(String* errorMessage, const SecureContextCheck privilegeContextCheck) const
+{
+ // There may be exceptions for the secure context check defined for certain
+ // schemes. The exceptions are applied only to the special scheme and to
+ // sandboxed URLs from those origins, but *not* to any children.
+ //
+ // For example:
+ // <iframe src="http://host">
+ // <iframe src="scheme-has-exception://host"></iframe>
+ // <iframe sandbox src="scheme-has-exception://host"></iframe>
+ // </iframe>
+ // both inner iframes pass this check, assuming that the scheme
+ // "scheme-has-exception:" is granted an exception.
+ //
+ // However,
+ // <iframe src="http://host">
+ // <iframe sandbox src="http://host"></iframe>
+ // </iframe>
+ // would fail the check (that is, sandbox does not grant an exception itself).
+ //
+ // Additionally, with
+ // <iframe src="scheme-has-exception://host">
+ // <iframe src="http://host"></iframe>
+ // <iframe sandbox src="http://host"></iframe>
+ // </iframe>
+ // both inner iframes would fail the check, even though the outermost iframe
+ // passes.
+ //
+ // In all cases, a frame must be potentially trustworthy in addition to
+ // having an exception listed in order for the exception to be granted.
+ if (SecurityContext::isSandboxed(SandboxOrigin)) {
+ RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url());
+ if (!isOriginPotentiallyTrustworthy(origin.get(), errorMessage))
+ return false;
+ if (SchemeRegistry::schemeShouldBypassSecureContextCheck(origin->protocol()))
+ return true;
+ } else {
+ if (!isOriginPotentiallyTrustworthy(securityOrigin(), errorMessage))
+ return false;
+ if (SchemeRegistry::schemeShouldBypassSecureContextCheck(securityOrigin()->protocol()))
+ return true;
+ }
+
+ if (privilegeContextCheck == StandardSecureContextCheck) {
+ Document* context = parentDocument();
+ while (context) {
+ // Skip to the next ancestor if it's a srcdoc.
+ if (!context->isSrcdocDocument()) {
+ if (context->securityContext().isSandboxed(SandboxOrigin)) {
+ // For a sandboxed origin, use the document's URL.
+ RefPtr<SecurityOrigin> origin = SecurityOrigin::create(context->url());
+ if (!isOriginPotentiallyTrustworthy(origin.get(), errorMessage))
+ return false;
+ } else {
+ if (!isOriginPotentiallyTrustworthy(context->securityOrigin(), errorMessage))
+ return false;
+ }
+ }
+ context = context->parentDocument();
+ }
+ }
+ return true;
+}
+
StyleSheetList* Document::styleSheets()
{
if (!m_styleSheetList)
@@ -5673,66 +5744,12 @@ v8::Local<v8::Object> Document::associateWithWrapper(v8::Isolate* isolate, const
bool Document::isSecureContext(String& errorMessage, const SecureContextCheck privilegeContextCheck) const
{
- // There may be exceptions for the secure context check defined for certain
- // schemes. The exceptions are applied only to the special scheme and to
- // sandboxed URLs from those origins, but *not* to any children.
- //
- // For example:
- // <iframe src="http://host">
- // <iframe src="scheme-has-exception://host"></iframe>
- // <iframe sandbox src="scheme-has-exception://host"></iframe>
- // </iframe>
- // both inner iframes pass this check, assuming that the scheme
- // "scheme-has-exception:" is granted an exception.
- //
- // However,
- // <iframe src="http://host">
- // <iframe sandbox src="http://host"></iframe>
- // </iframe>
- // would fail the check (that is, sandbox does not grant an exception itself).
- //
- // Additionally, with
- // <iframe src="scheme-has-exception://host">
- // <iframe src="http://host"></iframe>
- // <iframe sandbox src="http://host"></iframe>
- // </iframe>
- // both inner iframes would fail the check, even though the outermost iframe
- // passes.
- //
- // In all cases, a frame must be potentially trustworthy in addition to
- // having an exception listed in order for the exception to be granted.
- if (SecurityContext::isSandboxed(SandboxOrigin)) {
- RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url());
- if (!origin->isPotentiallyTrustworthy(errorMessage))
- return false;
- if (SchemeRegistry::schemeShouldBypassSecureContextCheck(origin->protocol()))
- return true;
- } else {
- if (!securityOrigin()->isPotentiallyTrustworthy(errorMessage))
- return false;
- if (SchemeRegistry::schemeShouldBypassSecureContextCheck(securityOrigin()->protocol()))
- return true;
- }
+ return isSecureContextImpl(&errorMessage, privilegeContextCheck);
+}
- if (privilegeContextCheck == StandardSecureContextCheck) {
- Document* context = parentDocument();
- while (context) {
- // Skip to the next ancestor if it's a srcdoc.
- if (!context->isSrcdocDocument()) {
- if (context->securityContext().isSandboxed(SandboxOrigin)) {
- // For a sandboxed origin, use the document's URL.
- RefPtr<SecurityOrigin> origin = SecurityOrigin::create(context->url());
- if (!origin->isPotentiallyTrustworthy(errorMessage))
- return false;
- } else {
- if (!context->securityOrigin()->isPotentiallyTrustworthy(errorMessage))
- return false;
- }
- }
- context = context->parentDocument();
- }
- }
- return true;
+bool Document::isSecureContext(const SecureContextCheck privilegeContextCheck) const
+{
+ return isSecureContextImpl(nullptr, privilegeContextCheck);
}
WebTaskRunner* Document::loadingTaskRunner() const
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.h ('k') | third_party/WebKit/Source/core/dom/ExecutionContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698