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

Side by Side Diff: Source/modules/websockets/NewWebSocketChannelImpl.cpp

Issue 222153002: Disallow connecting an insecure WebSocket from a secure page. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "modules/websockets/NewWebSocketChannelImpl.h" 32 #include "modules/websockets/NewWebSocketChannelImpl.h"
33 33
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
36 #include "core/fileapi/FileReaderLoader.h" 36 #include "core/fileapi/FileReaderLoader.h"
37 #include "core/fileapi/FileReaderLoaderClient.h" 37 #include "core/fileapi/FileReaderLoaderClient.h"
38 #include "core/frame/LocalFrame.h"
38 #include "core/inspector/InspectorInstrumentation.h" 39 #include "core/inspector/InspectorInstrumentation.h"
40 #include "core/loader/FrameLoader.h"
41 #include "core/loader/MixedContentChecker.h"
39 #include "core/loader/UniqueIdentifier.h" 42 #include "core/loader/UniqueIdentifier.h"
40 #include "modules/websockets/WebSocketChannelClient.h" 43 #include "modules/websockets/WebSocketChannelClient.h"
41 #include "modules/websockets/WebSocketFrame.h" 44 #include "modules/websockets/WebSocketFrame.h"
42 #include "platform/Logging.h" 45 #include "platform/Logging.h"
43 #include "platform/network/WebSocketHandshakeRequest.h" 46 #include "platform/network/WebSocketHandshakeRequest.h"
44 #include "platform/weborigin/SecurityOrigin.h" 47 #include "platform/weborigin/SecurityOrigin.h"
45 #include "public/platform/Platform.h" 48 #include "public/platform/Platform.h"
46 #include "public/platform/WebSerializedOrigin.h" 49 #include "public/platform/WebSerializedOrigin.h"
47 #include "public/platform/WebSocketHandshakeRequestInfo.h" 50 #include "public/platform/WebSocketHandshakeRequestInfo.h"
48 #include "public/platform/WebSocketHandshakeResponseInfo.h" 51 #include "public/platform/WebSocketHandshakeResponseInfo.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 { 115 {
113 if (context->isDocument() && toDocument(context)->page()) 116 if (context->isDocument() && toDocument(context)->page())
114 m_identifier = createUniqueIdentifier(); 117 m_identifier = createUniqueIdentifier();
115 } 118 }
116 119
117 NewWebSocketChannelImpl::~NewWebSocketChannelImpl() 120 NewWebSocketChannelImpl::~NewWebSocketChannelImpl()
118 { 121 {
119 abortAsyncOperations(); 122 abortAsyncOperations();
120 } 123 }
121 124
122 void NewWebSocketChannelImpl::connect(const KURL& url, const String& protocol) 125 bool NewWebSocketChannelImpl::connect(const KURL& url, const String& protocol)
123 { 126 {
124 WTF_LOG(Network, "NewWebSocketChannelImpl %p connect()", this); 127 WTF_LOG(Network, "NewWebSocketChannelImpl %p connect()", this);
125 if (!m_handle) 128 if (!m_handle)
126 return; 129 return false;
130
131 if (executionContext()->isDocument() && document()->frame() && !document()-> frame()->loader().mixedContentChecker()->canConnectInsecureWebSocket(document()- >securityOrigin(), url))
132 return false;
133 if (MixedContentChecker::isMixedContent(document()->securityOrigin(), url)) {
134 String message = "Connecting to a non-secure WebSocket server from a sec ure origin is deprecated.";
135 document()->addConsoleMessage(JSMessageSource, WarningMessageLevel, mess age);
136 }
137
127 m_url = url; 138 m_url = url;
128 Vector<String> protocols; 139 Vector<String> protocols;
129 // Avoid placing an empty token in the Vector when the protocol string is 140 // Avoid placing an empty token in the Vector when the protocol string is
130 // empty. 141 // empty.
131 if (!protocol.isEmpty()) { 142 if (!protocol.isEmpty()) {
132 // Since protocol is already verified and escaped, we can simply split 143 // Since protocol is already verified and escaped, we can simply split
133 // it. 144 // it.
134 protocol.split(", ", true, protocols); 145 protocol.split(", ", true, protocols);
135 } 146 }
136 blink::WebVector<blink::WebString> webProtocols(protocols.size()); 147 blink::WebVector<blink::WebString> webProtocols(protocols.size());
137 for (size_t i = 0; i < protocols.size(); ++i) { 148 for (size_t i = 0; i < protocols.size(); ++i) {
138 webProtocols[i] = protocols[i]; 149 webProtocols[i] = protocols[i];
139 } 150 }
140 m_handle->connect(url, webProtocols, *executionContext()->securityOrigin(), this); 151 m_handle->connect(url, webProtocols, *executionContext()->securityOrigin(), this);
141 flowControlIfNecessary(); 152 flowControlIfNecessary();
142 if (m_identifier) 153 if (m_identifier)
143 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, u rl, protocol); 154 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, u rl, protocol);
155 return true;
144 } 156 }
145 157
146 String NewWebSocketChannelImpl::subprotocol() 158 String NewWebSocketChannelImpl::subprotocol()
147 { 159 {
148 WTF_LOG(Network, "NewWebSocketChannelImpl %p subprotocol()", this); 160 WTF_LOG(Network, "NewWebSocketChannelImpl %p subprotocol()", this);
149 return m_subprotocol; 161 return m_subprotocol;
150 } 162 }
151 163
152 String NewWebSocketChannelImpl::extensions() 164 String NewWebSocketChannelImpl::extensions()
153 { 165 {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 if (errorCode == FileError::ABORT_ERR) { 503 if (errorCode == FileError::ABORT_ERR) {
492 // The error is caused by cancel(). 504 // The error is caused by cancel().
493 return; 505 return;
494 } 506 }
495 // FIXME: Generate human-friendly reason message. 507 // FIXME: Generate human-friendly reason message.
496 failAsError("Failed to load Blob: error code = " + String::number(errorCode) ); 508 failAsError("Failed to load Blob: error code = " + String::number(errorCode) );
497 // |this| can be deleted here. 509 // |this| can be deleted here.
498 } 510 }
499 511
500 } // namespace WebCore 512 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/websockets/NewWebSocketChannelImpl.h ('k') | Source/modules/websockets/WebSocket.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698