- Revision
- 199039
- Author
- [email protected]
- Date
- 2016-04-04 21:12:48 -0700 (Mon, 04 Apr 2016)
Log 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 <[email protected]> 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.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (199038 => 199039)
--- trunk/Source/WebCore/ChangeLog 2016-04-05 04:04:35 UTC (rev 199038)
+++ trunk/Source/WebCore/ChangeLog 2016-04-05 04:12:48 UTC (rev 199039)
@@ -1,3 +1,23 @@
+2016-04-04 John Wilander <[email protected]>
+
+ Block plaintext WebSocket requests to domains under HSTS.
+ https://bugs.webkit.org/show_bug.cgi?id=156049
+ <rdar://problem/13820000>
+
+ 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.
+
2016-04-04 Simon Fraser <[email protected]>
Make FrameView's exposedRect an Optional<>
Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp (199038 => 199039)
--- trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp 2016-04-05 04:04:35 UTC (rev 199038)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp 2016-04-05 04:12:48 UTC (rev 199039)
@@ -109,7 +109,8 @@
if (Frame* frame = m_document->frame()) {
if (NetworkingContext* networkingContext = frame->loader().networkingContext()) {
ref();
- m_handle = SocketStreamHandle::create(m_handshake->url(), this, *networkingContext);
+ Page* page = frame->page();
+ m_handle = SocketStreamHandle::create(m_handshake->url(), this, *networkingContext, (page ? page->usesEphemeralSession() : false));
}
}
}
Modified: trunk/Source/WebCore/platform/network/cf/SocketStreamHandle.h (199038 => 199039)
--- trunk/Source/WebCore/platform/network/cf/SocketStreamHandle.h 2016-04-05 04:04:35 UTC (rev 199038)
+++ trunk/Source/WebCore/platform/network/cf/SocketStreamHandle.h 2016-04-05 04:12:48 UTC (rev 199039)
@@ -49,7 +49,7 @@
class SocketStreamHandle : public ThreadSafeRefCounted<SocketStreamHandle>, public SocketStreamHandleBase, public AuthenticationClient {
public:
- static PassRefPtr<SocketStreamHandle> create(const URL& url, SocketStreamHandleClient* client, NetworkingContext& networkingContext) { return adoptRef(new SocketStreamHandle(url, client, networkingContext)); }
+ static PassRefPtr<SocketStreamHandle> create(const URL& url, SocketStreamHandleClient* client, NetworkingContext& networkingContext, bool usesEphemeralSession) { return adoptRef(new SocketStreamHandle(url, client, networkingContext, usesEphemeralSession)); }
virtual ~SocketStreamHandle();
@@ -60,7 +60,7 @@
virtual int platformSend(const char* data, int length);
virtual void platformClose();
- SocketStreamHandle(const URL&, SocketStreamHandleClient*, NetworkingContext&);
+ SocketStreamHandle(const URL&, SocketStreamHandleClient*, NetworkingContext&, bool usesEphemeralSession);
void createStreams();
void scheduleStreams();
void chooseProxy();
Modified: trunk/Source/WebCore/platform/network/cf/SocketStreamHandleCFNet.cpp (199038 => 199039)
--- trunk/Source/WebCore/platform/network/cf/SocketStreamHandleCFNet.cpp 2016-04-05 04:04:35 UTC (rev 199038)
+++ trunk/Source/WebCore/platform/network/cf/SocketStreamHandleCFNet.cpp 2016-04-05 04:12:48 UTC (rev 199039)
@@ -60,9 +60,13 @@
extern "C" const CFStringRef _kCFStreamSocketSetNoDelay;
#endif
+#if PLATFORM(COCOA)
+#import <CFNetworkSPI.h>
+#endif
+
namespace WebCore {
-SocketStreamHandle::SocketStreamHandle(const URL& url, SocketStreamHandleClient* client, NetworkingContext& networkingContext)
+SocketStreamHandle::SocketStreamHandle(const URL& url, SocketStreamHandleClient* client, NetworkingContext& networkingContext, bool usesEphemeralSession)
: SocketStreamHandleBase(url, client)
, m_connectingSubstate(New)
, m_connectionType(Unknown)
@@ -76,6 +80,17 @@
URL httpsURL(URL(), "https://" + m_url.host());
m_httpsURL = httpsURL.createCFURL();
+#if PLATFORM(COCOA)
+ // Don't check for HSTS violation for ephemeral sessions since
+ // HSTS state should not transfer between regular and private browsing.
+ if (url.protocolIs("ws")
+ && !usesEphemeralSession
+ && _CFNetworkIsKnownHSTSHostWithSession(m_httpsURL.get(), nullptr)) {
+ m_client->didFailSocketStream(this, SocketStreamError(0, m_url.string(), "WebSocket connection failed because it violates HTTP Strict Transport Security."));
+ return;
+ }
+#endif
+
createStreams();
ASSERT(!m_readStream == !m_writeStream);
if (!m_readStream) // Doing asynchronous PAC file processing, streams will be created later.