Skip to content

Commit 3cae75e

Browse files
add body to data
1 parent a1e0e9d commit 3cae75e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ci/github/save_mitm_requests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from datetime import datetime
66
from pathlib import Path
77

8+
MAX_RESPONSE_BODY_CHARS = 2000 # or any limit you prefer
9+
10+
811
# Import SecretDetector directly without package initialization
912
secret_detector_path = (
1013
Path(__file__).parent
@@ -275,9 +278,11 @@ def safe_str(value, max_length=5000):
275278
"duration_ms",
276279
"request_headers",
277280
"response_headers",
281+
"response_body",
278282
"error_message",
279283
]
280284
)
285+
281286
f.flush()
282287
logger.info("Header written and flushed successfully")
283288
except Exception as file_error:
@@ -313,6 +318,15 @@ def response(flow):
313318

314319
# Write row to CSV with safe string conversion
315320
timestamp = datetime.now().isoformat()
321+
322+
# Truncated and masked response body
323+
try:
324+
raw_body = flow.response.content or b""
325+
decoded_body = safe_str(raw_body, max_length=MAX_RESPONSE_BODY_CHARS)
326+
masked_body = SecretDetector.mask_secrets(decoded_body).masked_text
327+
except Exception as e:
328+
masked_body = f"[RESPONSE BODY ERROR: {type(e).__name__}]"
329+
316330
writer.writerow(
317331
[
318332
safe_str(timestamp),
@@ -328,6 +342,7 @@ def response(flow):
328342
safe_str(duration_ms),
329343
safe_str(request_headers),
330344
safe_str(response_headers),
345+
safe_str(masked_body),
331346
"", # No error for successful requests
332347
]
333348
)
@@ -370,6 +385,7 @@ def response(flow):
370385
"", # Empty duration for errors
371386
"", # Empty request headers for errors
372387
"", # Empty response headers for errors
388+
"", # Empty body
373389
safe_str(
374390
SecretDetector.mask_secrets(str(e)).masked_text
375391
), # Error message

0 commit comments

Comments
 (0)