Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Python/modules/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def sort_data_and_write(cli_parsed, data):
web_index_head = create_web_index_head(cli_parsed.date, cli_parsed.time)
table_head = create_table_head()
counter = 1
csv_request_data = "Protocol,Port,Domain,URL,Resolved,Request Status,Title,Category,Default Creds,Screenshot Path, Source Path"
csv_request_data = "Protocol,Port,Domain,URL,Resolved,Request Status,Status Code,Title,Category,Default Creds,Screenshot Path, Source Path"

# Generate and write json log of requests
for json_request in data:
Expand Down Expand Up @@ -151,7 +151,10 @@ def sort_data_and_write(cli_parsed, data):
csv_request_data += "Successful,"
else:
csv_request_data += json_request._error_state + ","


# CSV - STATUS CODE (HTTP response code captured in the collected headers)
csv_request_data += str(json_request.http_headers.get('Response Code', '')) + ","

# CSV - TITLE
try:
# get attribute safely
Expand Down
13 changes: 11 additions & 2 deletions Python/modules/security_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,25 @@ def collect_http_headers(url: str, timeout: int = 10, user_agent: str = None, pr
headers = {}
for header_name, header_value in response.headers.items():
headers[header_name] = header_value


# Capture the HTTP response status code so it can be surfaced in the
# report headers section and the CSV (see issue #141).
status_code = getattr(response, 'status', None)
if status_code is None:
status_code = response.getcode()
if status_code is not None:
headers['Response Code'] = str(status_code)

response.close()
return headers, None

except urllib.error.HTTPError as e:
# Still try to get headers from error response
if e.headers:
headers = {}
for header_name, header_value in e.headers.items():
headers[header_name] = header_value
headers['Response Code'] = str(e.code)
return headers, f"HTTP {e.code} {e.reason}"
return None, f"HTTP Error {e.code}: {e.reason}"

Expand Down