Handle abuse better

- close connections on any encoding error
- if the connection is closing do not process buffered requests
This commit is contained in:
Neil Booth 2016-11-23 11:52:17 +09:00
parent a886eeca73
commit cebf93cdc3

View File

@ -97,6 +97,9 @@ class JSONRPC(asyncio.Protocol, LoggedClass):
decode_message for handling.
'''
self.recv_size += len(data)
if self.transport.is_closing():
return
while True:
npos = data.find(ord('\n'))
if npos == -1:
@ -118,6 +121,7 @@ class JSONRPC(asyncio.Protocol, LoggedClass):
except UnicodeDecodeError as e:
msg = 'cannot decode binary bytes: {}'.format(e)
self.send_json_error(msg, self.PARSE_ERROR)
self.transport.close()
return
try:
@ -125,6 +129,7 @@ class JSONRPC(asyncio.Protocol, LoggedClass):
except json.JSONDecodeError as e:
msg = 'cannot decode JSON: {}'.format(e)
self.send_json_error(msg, self.PARSE_ERROR)
self.transport.close()
return
self.on_json_request(message)