⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 201423 in webkit


Ignore:
Timestamp:
May 26, 2016, 11:19:30 AM (10 years ago)
Author:
Brent Fulgham
Message:

Sites served over insecure connections should not be allowed to use geolocation.
https://bugs.webkit.org/show_bug.cgi?id=157423
<rdar://problem/23751632>

Patch by Pranjal Jumde <pjumde@apple.com> on 2016-05-26
Reviewed by Brent Fulgham.

Source/WebCore:

Tests: http/tests/security/insecure-geolocation.html

http/tests/security/mixedcontent-geolocation-block-insecure-content.html
http/tests/security/mixedcontent-geolocation.html

  • Modules/geolocation/Geolocation.cpp:

(WebCore::logError):
Logs an error to the console if geolocation is blocked.
(WebCore::Geolocation::startRequest):
Access to Geolocation will be blocked if site is not secure. An error will be logged when access to Geolocation is blocked.
(WebCore::Geolocation::shouldBlockGeolocationRequests)
Returns true if the access to geolocation should be blocked.

  • Modules/geolocation/Geolocation.h:
  • dom/SecurityContext.h:

(WebCore::SecurityContext::foundMixedContent):
Returns true if insecure content was accessed over secure connection.
(WebCore::SecurityContext::setFoundMixedContent):
Sets m_foundMixedContent to true if insecure content is accessed over secure connection.
(WebCore::SecurityContext::geolocationAccessed):
Returns true if geolocation was accessed
(WebCore::SecurityContext::setGeolocationAccessed):
Sets m_geolocationAccessed to true if geolocation was accessed.

  • loader/MixedContentChecker.cpp:

(WebCore::MixedContentChecker::canDisplayInsecureContent):
Insecure content will be blocked if geolocation was accessed by the page. Updates document to keep track of mixed content.
(WebCore::MixedContentChecker::canRunInsecureContent):
Insecure content will be blocked if geolocation was accessed by the page. Updates document to keep track of mixed content.

LayoutTests:

  • http/tests/security/geolocation-over-insecure-content.html: Added.
  • http/tests/security/geolocation-over-mixed-content-block.html: Added.
  • http/tests/security/geolocation-over-mixed-content.html: Added.
  • http/tests/security/insecure-geolocation-expected.txt: Added.
  • http/tests/security/insecure-geolocation.html: Added.
  • http/tests/security/mixedcontent-geolocation-block-insecure-content-expected.txt: Added.
  • http/tests/security/mixedcontent-geolocation-block-insecure-content.html: Added.
  • http/tests/security/mixedcontent-geolocation-expected.txt: Added.
  • http/tests/security/mixedcontent-geolocation.html: Added.
  • http/tests/security/sandboxed-iframe-geolocation-watchPosition.html: iframe is loaded over secure connection to avoid geolocation failures
  • http/tests/security/sandboxed-iframe-geolocation-getCurrentPosition.html: iframe is loaded over secure connection to avoid geolocation failures
Location:
trunk
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r201422 r201423  
     12016-05-26  Pranjal Jumde  <pjumde@apple.com>
     2
     3        Sites served over insecure connections should not be allowed to use geolocation.
     4        https://bugs.webkit.org/show_bug.cgi?id=157423
     5        <rdar://problem/23751632>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        * http/tests/security/geolocation-over-insecure-content.html: Added.
     10        * http/tests/security/geolocation-over-mixed-content-block.html: Added.
     11        * http/tests/security/geolocation-over-mixed-content.html: Added.
     12        * http/tests/security/insecure-geolocation-expected.txt: Added.
     13        * http/tests/security/insecure-geolocation.html: Added.
     14        * http/tests/security/mixedcontent-geolocation-block-insecure-content-expected.txt: Added.
     15        * http/tests/security/mixedcontent-geolocation-block-insecure-content.html: Added.
     16        * http/tests/security/mixedcontent-geolocation-expected.txt: Added.
     17        * http/tests/security/mixedcontent-geolocation.html: Added.
     18        * http/tests/security/sandboxed-iframe-geolocation-watchPosition.html:
     19          iframe is loaded over secure connection to avoid geolocation failures
     20        * http/tests/security/sandboxed-iframe-geolocation-getCurrentPosition.html:
     21          iframe is loaded over secure connection to avoid geolocation failures
     22
    1232016-05-26  Brady Eidson  <beidson@apple.com>
    224
  • trunk/LayoutTests/http/tests/security/sandboxed-iframe-geolocation-getCurrentPosition.html

    r195075 r201423  
    1212<body>
    1313<p>Tests that navigator.geolocation.getCurrentPosition() returns error POSITION_UNAVAILABLE when called from a document in a sandboxed iframe.</p>
    14 <iframe src="resources/sandboxed-iframe-geolocation-getCurrentPosition.html" sandbox="allow-scripts" width="100%" height="300"></iframe>
     14<iframe src="https://127.0.0.1:8443/security/resources/sandboxed-iframe-geolocation-getCurrentPosition.html" sandbox="allow-scripts" width="100%" height="300"></iframe>
    1515</body>
    1616</html>
  • trunk/LayoutTests/http/tests/security/sandboxed-iframe-geolocation-watchPosition.html

    r195075 r201423  
    1212<body>
    1313<p>Tests that navigator.geolocation.watchPosition() returns error POSITION_UNAVAILABLE when called from a document in a sandboxed iframe.</p>
    14 <iframe src="resources/sandboxed-iframe-geolocation-watchPosition.html" sandbox="allow-scripts" width="100%" height="300"></iframe>
     14<iframe src="https://127.0.0.1:8443/security/resources/sandboxed-iframe-geolocation-watchPosition.html" sandbox="allow-scripts" width="100%" height="300"></iframe>
    1515</body>
    1616</html>
  • trunk/Source/WebCore/ChangeLog

    r201422 r201423  
     12016-05-26  Pranjal Jumde  <pjumde@apple.com>
     2
     3        Sites served over insecure connections should not be allowed to use geolocation.
     4        https://bugs.webkit.org/show_bug.cgi?id=157423
     5        <rdar://problem/23751632>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Tests: http/tests/security/insecure-geolocation.html
     10               http/tests/security/mixedcontent-geolocation-block-insecure-content.html
     11               http/tests/security/mixedcontent-geolocation.html
     12
     13        * Modules/geolocation/Geolocation.cpp:
     14        (WebCore::logError):
     15        Logs an error to the console if geolocation is blocked.
     16        (WebCore::Geolocation::startRequest):
     17        Access to Geolocation will be blocked if site is not secure. An error will be logged when access to Geolocation is blocked.
     18        (WebCore::Geolocation::shouldBlockGeolocationRequests)
     19        Returns true if the access to geolocation should be blocked.
     20        * Modules/geolocation/Geolocation.h:
     21        * dom/SecurityContext.h:
     22        (WebCore::SecurityContext::foundMixedContent):
     23        Returns true if insecure content was accessed over secure connection.
     24        (WebCore::SecurityContext::setFoundMixedContent):
     25        Sets m_foundMixedContent to true if insecure content is accessed over secure connection.
     26        (WebCore::SecurityContext::geolocationAccessed):
     27        Returns true if geolocation was accessed
     28        (WebCore::SecurityContext::setGeolocationAccessed):
     29        Sets m_geolocationAccessed to true if geolocation was accessed.
     30        * loader/MixedContentChecker.cpp:
     31        (WebCore::MixedContentChecker::canDisplayInsecureContent):
     32        Insecure content will be blocked if geolocation was accessed by the page. Updates document to keep track of mixed content.
     33        (WebCore::MixedContentChecker::canRunInsecureContent):
     34        Insecure content will be blocked if geolocation was accessed by the page. Updates document to keep track of mixed content.
     35
    1362016-05-26  Brady Eidson  <beidson@apple.com>
    237
  • trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp

    r200895 r201423  
    4444#include <wtf/CurrentTime.h>
    4545#include <wtf/Ref.h>
     46#include <wtf/text/StringBuilder.h>
    4647
    4748namespace WebCore {
     
    173174    return true;
    174175}
    175 
     176   
    176177void Geolocation::suspend(ReasonForSuspension reason)
    177178{
     
    338339}
    339340
     341static void logError(const String& target, const bool isSecure, const bool isMixedContent, Document* document)
     342{
     343    StringBuilder message;
     344    message.append("[blocked] Access to geolocation was blocked over");
     345   
     346    if (!isSecure)
     347        message.append(" insecure connection to ");
     348    else if (isMixedContent)
     349        message.append(" secure connection with mixed content to ");
     350    else
     351        return;
     352   
     353    message.append(target);
     354    message.append(".\n");
     355    document->addConsoleMessage(MessageSource::Security, MessageLevel::Error, message.toString());
     356}
     357
     358bool Geolocation::shouldBlockGeolocationRequests()
     359{
     360    bool isSecure = SecurityOrigin::isSecure(document()->url());
     361    bool hasMixedContent = document()->foundMixedContent();
     362    bool isLocalFile = document()->url().isLocalFile();
     363    if (securityOrigin()->canRequestGeolocation()) {
     364        if (isLocalFile || (isSecure && !hasMixedContent))
     365            return false;
     366    }
     367   
     368    logError(securityOrigin()->toString(), isSecure, hasMixedContent, document());
     369    return true;
     370}
     371
    340372void Geolocation::startRequest(GeoNotifier* notifier)
    341373{
    342     if (!securityOrigin()->canRequestGeolocation()) {
     374    if (shouldBlockGeolocationRequests()) {
    343375        notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, ASCIILiteral(originCannotRequestGeolocationErrorMessage)));
    344376        return;
    345377    }
     378    document()->setGeolocationAccessed();
    346379
    347380    // Check whether permissions have already been denied. Note that if this is the case,
  • trunk/Source/WebCore/Modules/geolocation/Geolocation.h

    r200691 r201423  
    7373    void positionChanged();
    7474    void setError(GeolocationError*);
     75    bool shouldBlockGeolocationRequests();
    7576
    7677private:
  • trunk/Source/WebCore/dom/SecurityContext.h

    r200691 r201423  
    7676
    7777    static SandboxFlags parseSandboxPolicy(const String& policy, String& invalidTokensErrorMessage);
     78    bool foundMixedContent() const { return m_foundMixedContent; }
     79    void setFoundMixedContent() { m_foundMixedContent = true; }
     80    bool geolocationAccessed() const { return m_geolocationAccessed; }
     81    void setGeolocationAccessed() { m_geolocationAccessed = true; }
    7882
    7983protected:
     
    9195    RefPtr<SecurityOriginPolicy> m_securityOriginPolicy;
    9296    std::unique_ptr<ContentSecurityPolicy> m_contentSecurityPolicy;
     97    bool m_foundMixedContent { false };
     98    bool m_geolocationAccessed { false };
    9399};
    94100
  • trunk/Source/WebCore/loader/MixedContentChecker.cpp

    r200691 r201423  
    6666        return true;
    6767
    68     bool allowed = m_frame.settings().allowDisplayOfInsecureContent() || type == ContentType::ActiveCanWarn;
     68    bool allowed = (m_frame.settings().allowDisplayOfInsecureContent() || type == ContentType::ActiveCanWarn) && !m_frame.document()->geolocationAccessed();
    6969    logWarning(allowed, "display", url);
    7070
    71     if (allowed)
     71    if (allowed) {
     72        m_frame.document()->setFoundMixedContent();
    7273        client().didDisplayInsecureContent();
     74    }
    7375
    7476    return allowed;
     
    8082        return true;
    8183
    82     bool allowed = m_frame.settings().allowRunningOfInsecureContent();
     84    bool allowed = m_frame.settings().allowRunningOfInsecureContent() && !m_frame.document()->geolocationAccessed();
    8385    logWarning(allowed, "run", url);
    8486
    85     if (allowed)
     87    if (allowed) {
     88        m_frame.document()->setFoundMixedContent();
    8689        client().didRunInsecureContent(securityOrigin, url);
     90    }
    8791
    8892    return allowed;
Note: See TracChangeset for help on using the changeset viewer.