diff options
Diffstat (limited to 'Source/WebCore/loader/MixedContentChecker.cpp')
-rw-r--r-- | Source/WebCore/loader/MixedContentChecker.cpp | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/Source/WebCore/loader/MixedContentChecker.cpp b/Source/WebCore/loader/MixedContentChecker.cpp index e507aa62d..46081a722 100644 --- a/Source/WebCore/loader/MixedContentChecker.cpp +++ b/Source/WebCore/loader/MixedContentChecker.cpp @@ -6,13 +6,13 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -29,13 +29,11 @@ #include "config.h" #include "MixedContentChecker.h" -#include "Console.h" -#include "DOMWindow.h" +#include "ContentSecurityPolicy.h" #include "Document.h" #include "Frame.h" #include "FrameLoader.h" #include "FrameLoaderClient.h" -#include "SchemeRegistry.h" #include "SecurityOrigin.h" #include "Settings.h" #include <wtf/text/CString.h> @@ -54,47 +52,78 @@ FrameLoaderClient& MixedContentChecker::client() const } // static -bool MixedContentChecker::isMixedContent(SecurityOrigin* securityOrigin, const URL& url) +bool MixedContentChecker::isMixedContent(SecurityOrigin& securityOrigin, const URL& url) { - if (securityOrigin->protocol() != "https") + if (securityOrigin.protocol() != "https") return false; // We only care about HTTPS security origins. // We're in a secure context, so |url| is mixed content if it's insecure. return !SecurityOrigin::isSecure(url); } -bool MixedContentChecker::canDisplayInsecureContent(SecurityOrigin* securityOrigin, const URL& url) const +bool MixedContentChecker::canDisplayInsecureContent(SecurityOrigin& securityOrigin, ContentType type, const URL& url, AlwaysDisplayInNonStrictMode alwaysDisplayInNonStrictMode) const { if (!isMixedContent(securityOrigin, url)) return true; - bool allowed = client().allowDisplayingInsecureContent(m_frame.settings().allowDisplayOfInsecureContent(), securityOrigin, url); - logWarning(allowed, "displayed", url); + if (!m_frame.document()->contentSecurityPolicy()->allowRunningOrDisplayingInsecureContent(url)) + return false; - if (allowed) + bool isStrictMode = m_frame.document()->isStrictMixedContentMode(); + if (!isStrictMode && alwaysDisplayInNonStrictMode == AlwaysDisplayInNonStrictMode::Yes) + return true; + + bool allowed = !isStrictMode && (m_frame.settings().allowDisplayOfInsecureContent() || type == ContentType::ActiveCanWarn) && !m_frame.document()->geolocationAccessed(); + logWarning(allowed, "display", url); + + if (allowed) { + m_frame.document()->setFoundMixedContent(); client().didDisplayInsecureContent(); + } return allowed; } -bool MixedContentChecker::canRunInsecureContent(SecurityOrigin* securityOrigin, const URL& url) const +bool MixedContentChecker::canRunInsecureContent(SecurityOrigin& securityOrigin, const URL& url) const { if (!isMixedContent(securityOrigin, url)) return true; - bool allowed = client().allowRunningInsecureContent(m_frame.settings().allowRunningOfInsecureContent(), securityOrigin, url); - logWarning(allowed, "ran", url); + if (!m_frame.document()->contentSecurityPolicy()->allowRunningOrDisplayingInsecureContent(url)) + return false; - if (allowed) + bool allowed = !m_frame.document()->isStrictMixedContentMode() && m_frame.settings().allowRunningOfInsecureContent() && !m_frame.document()->geolocationAccessed(); + logWarning(allowed, "run", url); + + if (allowed) { + m_frame.document()->setFoundMixedContent(); client().didRunInsecureContent(securityOrigin, url); + } return allowed; } +void MixedContentChecker::checkFormForMixedContent(SecurityOrigin& securityOrigin, const URL& url) const +{ + // Unconditionally allow javascript: URLs as form actions as some pages do this and it does not introduce + // a mixed content issue. + if (protocolIsJavaScript(url)) + return; + + if (!isMixedContent(securityOrigin, url)) + return; + + String message = makeString("The page at ", m_frame.document()->url().stringCenterEllipsizedToLength(), " contains a form which targets an insecure URL ", url.stringCenterEllipsizedToLength(), ".\n"); + m_frame.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Warning, message); + + client().didDisplayInsecureContent(); +} + void MixedContentChecker::logWarning(bool allowed, const String& action, const URL& target) const { - String message = makeString((allowed ? "" : "[blocked] "), "The page at ", m_frame.document()->url().stringCenterEllipsizedToLength(), " ", action, " insecure content from ", target.stringCenterEllipsizedToLength(), ".\n"); - m_frame.document()->addConsoleMessage(SecurityMessageSource, WarningMessageLevel, message); + const char* errorString = allowed ? " was allowed to " : " was not allowed to "; + String message = makeString((allowed ? String() : "[blocked] "), "The page at ", m_frame.document()->url().stringCenterEllipsizedToLength(), errorString, action, " insecure content from ", target.stringCenterEllipsizedToLength(), ".\n"); + m_frame.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Warning, message); } } // namespace WebCore |