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

Changeset 199039 in webkit


Ignore:
Timestamp:
Apr 4, 2016, 9:12:48 PM (11 years ago)
Author:
Brent Fulgham
Message:

Block plaintext WebSocket requests to domains under HSTS.
​https://bugs.webkit.org/show_bug.cgi?id=156049
<rdar://problem/13820000>

Patch by John Wilander <​wilander@apple.com> on 2016-04-04
Reviewed by Brent Fulgham.

No new tests because the way TLS is setup for layout tests doesn't allow the server to set HSTS for 127.0.0.1 nor localhost. This is tracked in <rdar://problem/25467825>.

  • Modules/websockets/WebSocketChannel.cpp:

(WebCore::WebSocketChannel::connect):

  • Now sends usesEphemeralSession to SocketStreamHandle::create.
  • platform/network/cf/SocketStreamHandle.h:

(WebCore::SocketStreamHandle::create):

  • Added parameter usesEphemeralSession which it passes on to the SocketStreamHandle constructor.
  • platform/network/cf/SocketStreamHandleCFNet.cpp:

(WebCore::SocketStreamHandle::SocketStreamHandle):

  • Now blocks plaintext WebSocket connections for domains under HSTS if not in an ephemeral session.
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r199038 r199039  
     12016-04-04  John Wilander  <wilander@apple.com>
     2
     3        Block plaintext WebSocket requests to domains under HSTS.
     4        https://bugs.webkit.org/show_bug.cgi?id=156049
     5        <rdar://problem/13820000>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        No new tests because the way TLS is setup for layout tests doesn't allow the server to set HSTS for 127.0.0.1 nor localhost. This is tracked in <rdar://problem/25467825>.
     10
     11        * Modules/websockets/WebSocketChannel.cpp:
     12        (WebCore::WebSocketChannel::connect):
     13            - Now sends usesEphemeralSession to SocketStreamHandle::create.
     14        * platform/network/cf/SocketStreamHandle.h:
     15        (WebCore::SocketStreamHandle::create):
     16            - Added parameter usesEphemeralSession which it passes on to the SocketStreamHandle constructor.
     17        * platform/network/cf/SocketStreamHandleCFNet.cpp:
     18        (WebCore::SocketStreamHandle::SocketStreamHandle):
     19            - Now blocks plaintext WebSocket connections for domains under HSTS if not in an ephemeral session.
     20
    1212016-04-04  Simon Fraser  <simon.fraser@apple.com>
    222
  • trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp

    r198869 r199039  
    110110        if (NetworkingContext* networkingContext = frame->loader().networkingContext()) {
    111111            ref();
    112             m_handle = SocketStreamHandle::create(m_handshake->url(), this, *networkingContext);
     112            Page* page = frame->page();
     113            m_handle = SocketStreamHandle::create(m_handshake->url(), this, *networkingContext, (page ? page->usesEphemeralSession() : false));
    113114        }
    114115    }
  • trunk/Source/WebCore/platform/network/cf/SocketStreamHandle.h

    r186476 r199039  
    5050class SocketStreamHandle : public ThreadSafeRefCounted<SocketStreamHandle>, public SocketStreamHandleBase, public AuthenticationClient {
    5151public:
    52     static PassRefPtr<SocketStreamHandle> create(const URL& url, SocketStreamHandleClient* client, NetworkingContext& networkingContext) { return adoptRef(new SocketStreamHandle(url, client, networkingContext)); }
     52    static PassRefPtr<SocketStreamHandle> create(const URL& url, SocketStreamHandleClient* client, NetworkingContext& networkingContext, bool usesEphemeralSession) { return adoptRef(new SocketStreamHandle(url, client, networkingContext, usesEphemeralSession)); }
    5353
    5454    virtual ~SocketStreamHandle();
    … …  
    6161    virtual void platformClose();
    6262
    63     SocketStreamHandle(const URL&, SocketStreamHandleClient*, NetworkingContext&);
     63    SocketStreamHandle(const URL&, SocketStreamHandleClient*, NetworkingContext&, bool usesEphemeralSession);
    6464    void createStreams();
    6565    void scheduleStreams();
  • trunk/Source/WebCore/platform/network/cf/SocketStreamHandleCFNet.cpp

    r188642 r199039  
    6161#endif
    6262
     63#if PLATFORM(COCOA)
     64#import <CFNetworkSPI.h>
     65#endif
     66
    6367namespace WebCore {
    6468
    65 SocketStreamHandle::SocketStreamHandle(const URL& url, SocketStreamHandleClient* client, NetworkingContext& networkingContext)
     69SocketStreamHandle::SocketStreamHandle(const URL& url, SocketStreamHandleClient* client, NetworkingContext& networkingContext, bool usesEphemeralSession)
    6670    : SocketStreamHandleBase(url, client)
    6771    , m_connectingSubstate(New)
    … …  
    7680    URL httpsURL(URL(), "https://" + m_url.host());
    7781    m_httpsURL = httpsURL.createCFURL();
     82
     83#if PLATFORM(COCOA)
     84    // Don't check for HSTS violation for ephemeral sessions since
     85    // HSTS state should not transfer between regular and private browsing.
     86    if (url.protocolIs("ws")
     87        && !usesEphemeralSession
     88        && _CFNetworkIsKnownHSTSHostWithSession(m_httpsURL.get(), nullptr)) {
     89        m_client->didFailSocketStream(this, SocketStreamError(0, m_url.string(), "WebSocket connection failed because it violates HTTP Strict Transport Security."));
     90        return;
     91    }
     92#endif
    7893
    7994    createStreams();
Note: See TracChangeset for help on using the changeset viewer.