Show More
@@ -42,23 +42,33 class ZMQStreamHandler(websocket.WebSocketHandler): | |||
|
42 | 42 | host = self.request.headers.get("Host") |
|
43 | 43 | |
|
44 | 44 | # If no header is provided, assume we can't verify origin |
|
45 |
if |
|
|
45 | if origin is None: | |
|
46 | self.log.warn("Missing Origin header, rejecting WebSocket connection.") | |
|
47 | return False | |
|
48 | if host is None: | |
|
49 | self.log.warn("Missing Host header, rejecting WebSocket connection.") | |
|
46 | 50 | return False |
|
47 | 51 | |
|
48 | host_origin = "{0}://{1}".format(self.request.protocol, host) | |
|
52 | origin = origin.lower() | |
|
53 | origin_host = urlparse(origin).netloc | |
|
49 | 54 | |
|
50 | 55 | # OK if origin matches host |
|
51 |
if origin == host |
|
|
56 | if origin_host == host: | |
|
52 | 57 | return True |
|
53 | 58 | |
|
54 | 59 | # Check CORS headers |
|
55 | 60 | if self.allow_origin: |
|
56 |
|
|
|
61 | allow = self.allow_origin == origin | |
|
57 | 62 | elif self.allow_origin_pat: |
|
58 |
|
|
|
63 | allow = bool(self.allow_origin_pat.match(origin)) | |
|
59 | 64 | else: |
|
60 | 65 | # No CORS headers deny the request |
|
61 |
|
|
|
66 | allow = False | |
|
67 | if not allow: | |
|
68 | self.log.warn("Blocking Cross Origin WebSocket Attempt. Origin: %s, Host: %s", | |
|
69 | origin, host, | |
|
70 | ) | |
|
71 | return allow | |
|
62 | 72 | |
|
63 | 73 | def clear_cookie(self, *args, **kwargs): |
|
64 | 74 | """meaningless for websockets""" |
@@ -143,7 +153,6 class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler): | |||
|
143 | 153 | # Tornado 4 already does CORS checking |
|
144 | 154 | if tornado.version_info[0] < 4: |
|
145 | 155 | if not self.check_origin(self.get_origin()): |
|
146 | self.log.warn("Cross Origin WebSocket Attempt from %s", self.get_origin()) | |
|
147 | 156 | raise web.HTTPError(403) |
|
148 | 157 | |
|
149 | 158 | self.session = Session(config=self.config) |
General Comments 0
You need to be logged in to leave comments.
Login now