protocol: limit meta line length in request

This commit is contained in:
dece 2021-03-05 19:28:17 +01:00
parent 72111bce70
commit 524bda5b39

View file

@ -175,6 +175,7 @@ class Response:
content: bytes = b"" content: bytes = b""
HEADER_RE = re.compile(r"(\d{2}) (.*)") HEADER_RE = re.compile(r"(\d{2}) (.*)")
MAX_META_LEN = 1024
@property @property
def generic_code(self): def generic_code(self):
@ -192,6 +193,8 @@ class Response:
if not match: if not match:
return None return None
code, meta = match.groups() code, meta = match.groups()
if len(meta) > Response.MAX_META_LEN:
return None
response = Response(StatusCode(int(code)), meta=meta) response = Response(StatusCode(int(code)), meta=meta)
if response.generic_code == StatusCode.SUCCESS: if response.generic_code == StatusCode.SUCCESS:
content_offset = response_header_len + len(LINE_TERM) content_offset = response_header_len + len(LINE_TERM)