Fix bug in extractHeaders and simplify its logic
`extractHeaders` had an incorrect regex that crashed Corsy with the msg: "sre_constants.error: nothing to repeat at position 1". This was caused by `^?`, which is not a valid regex, and can be reproduced with the README example: `python3 corsy.py -u https://example.com --headers "User-Agent: GoogleBot\nCookie: SESSION=Hacked"`. Instead of using the regex this commit simplifies the logic by using a `split` to split lines and header_name/value pairs.
This commit is contained in:
@@ -64,17 +64,13 @@ def prompt(default=None):
|
|||||||
return tmpfile.read().strip()
|
return tmpfile.read().strip()
|
||||||
|
|
||||||
|
|
||||||
def extractHeaders(headers):
|
def extractHeaders(headers: str):
|
||||||
headers = headers.replace('\\n', '\n')
|
|
||||||
sorted_headers = {}
|
sorted_headers = {}
|
||||||
matches = re.findall(r'^?(.*?):\s(.*?)[\n$]', headers)
|
for header in headers.split('\\n'):
|
||||||
for match in matches:
|
name, value = header.split(":", 1)
|
||||||
header = match[0]
|
name = name.strip()
|
||||||
value = match[1]
|
value = value.strip()
|
||||||
try:
|
if len(value) >= 1 and value[-1] == ',':
|
||||||
if value[-1] == ',':
|
value = value[:-1]
|
||||||
value = value[:-1]
|
sorted_headers[name] = value
|
||||||
sorted_headers[header] = value
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
return sorted_headers
|
return sorted_headers
|
||||||
Reference in New Issue
Block a user