You've proven the bug. You have the request that shows it, the response that confirms it, and the browser's network log that ties it together. The easiest way to hand all of that to a triager, a developer or a vendor's support desk is a HAR file: one click in DevTools, one attachment.
That file is also a copy of your session. Every cookie, every Authorization header, every token the app returned in a response body is in there, in plain JSON. Whoever reads the attachment, or whoever later gets into the system it was uploaded to, can try to replay it.
This isn't a hypothetical. In October 2023, Okta reported unauthorized access to its support system, where customers upload HAR files for troubleshooting. Okta noted that HAR files can contain cookies and session tokens, revoked the tokens embedded in them, and recommended sanitizing credentials before sharing. Cloudflare wrote that an attack on its own systems started from a token stolen from that support system, and released an open-source HAR sanitizer in response.
This post is about the reporter's side of that problem: how to strip a HAR so it still proves the bug, and how to prove to yourself that the scrub actually worked.
Only capture and share traffic from systems you own or are authorized to test, using your own test accounts.
What's in a HAR, exactly
HAR (HTTP Archive) is a JSON format for recording a browser's HTTP transactions. Its W3C spec, now marked as a historical draft, is short and worth a skim. A few details matter for scrubbing:
- Each entry has a
requestand aresponse. Headers live inheadersarrays of{name, value}pairs. - Cookies appear twice: once inside the
Cookie/Set-Cookieheaders, and again as parsedcookiesarrays on the request and the response. Clean one and forget the other, and the value is still there. - The URL is stored whole, and its query string again as parsed
queryStringpairs. Tokens in query strings show up in both. -
postDataholds what you sent (text, orparamsfor form posts). That's where a login request keeps your password. -
response.content.textholds the response body, possibly base64-encoded (encoding: "base64"). Login and token endpoints return credentials here. -
redirectURLcopies theLocationheader, which can carry an OAuthcodeor similar. - Tools may add custom fields, which must start with an underscore. A parser that didn't write them is supposed to ignore them, but they're still in the file, and you don't know what's inside.
The spec's privacy section is one sentence: HAR files may contain sensitive data, and the user agent should tell the user so before the file goes anywhere.
Chrome's "sanitized" export helps, but read what it covers
Chrome DevTools now exports a sanitized HAR by default. Per the DevTools release notes and the Network panel reference, the sanitized export leaves out the Cookie, Set-Cookie and Authorization headers. To get them back you have to turn on a setting and pick "Export HAR (with sensitive data)".
That's a good default, and you should use it. But look at what's on the list: three header names. The documentation doesn't say anything about:
- the parsed
cookiesarrays that repeat the cookie values - custom auth headers such as
X-Api-Key - tokens in URLs and query strings (RFC 6750 already warns that bearer tokens in page URLs end up in history and logs)
- passwords in
postData - tokens and personal data in response bodies
Response bodies are the easy one to miss. In OWASP Juice Shop, for example, the login route returns the session JWT and the user's email inside the JSON body (authentication.token and authentication.umail in routes/login.ts). A header-only sanitizer leaves both in place.
So treat the sanitized export as step one, then check the file yourself.
Scrub it so the proof survives
The lazy fix is to delete every header and every body. The result is safe and useless: the triager can no longer see the thing you were proving.
Take a typical access-control proof. Alice's session fetches an invoice that belongs to Bob, and Bob fetching his own invoice is the control. If you blank both Authorization headers to REDACTED, the two requests look identical. The proof depends on showing that they came from different sessions.
The fix is to replace each distinct secret with a stable placeholder: the same token always becomes <SECRET_3>, and a different token becomes <SECRET_6>. The OWASP Logging Cheat Sheet suggests the same idea for logs: keep session IDs, access tokens and passwords out, and use a hashed value instead when you still need to track which events belong to one session.
Here's a scrubber that does that with only the Python standard library:
#!/usr/bin/env python3 """Scrub secrets from a HAR file but keep the proof readable. Each distinct secret value becomes a stable placeholder (<SECRET_1>, ...), so a reader can still tell which requests shared a session. Usage: python3 har_scrub.py in.har out.har """ import json, re, sys from urllib.parse import urlsplit, urlunsplit, parse_qsl, urlencode SENSITIVE_NAME = re.compile( r"(auth|cookie|token|secret|session|passw|api[-_]?key|csrf|signature|code)", re.I) JWT = re.compile(r"eyJ[\w-]+\.eyJ[\w-]+\.[\w-]*") BEARER = re.compile(r"(?i)\b(bearer|basic)\s+[\w.~+/=-]+") placeholders = {} # original value -> placeholder def mask(value): if not value: return value if value not in placeholders: placeholders[value] = f"<SECRET_{len(placeholders) + 1}>" return placeholders[value] def scrub_text(text): """Catch tokens that sit in free text (bodies, URLs, odd headers).""" text = JWT.sub(lambda m: mask(m.group(0)), text) return BEARER.sub(lambda m: m.group(1) + " " + mask(m.group(0).split(None, 1)[1]), text) def mask_header(name, value): """Mask the secret part only, so the same token gets the same placeholder whether it appears in a header, a cookie list or a response body.""" name = name.lower() if name == "cookie": pairs = [c.strip().split("=", 1) for c in value.split(";") if "=" in c] return "; ".join(f"{k}={mask(v)}" for k, v in pairs) if name == "set-cookie": first, _, attrs = value.partition(";") k, _, v = first.partition("=") return f"{k}={mask(v)}" + (";" + attrs if attrs else "") scheme, _, cred = value.partition(" ") if scheme.lower() in ("bearer", "basic") and cred: return f"{scheme} {mask(cred)}" return mask(value) def scrub_pairs(pairs): for p in pairs: value = p.get("value", "") if SENSITIVE_NAME.search(p.get("name", "")): p["value"] = mask_header(p["name"], value) elif value.startswith(("http://", "https://", "/")): # Location, Referer... p["value"] = scrub_url(value) else: p["value"] = scrub_text(value) def scrub_url(url): parts = urlsplit(url) q = [(k, mask(v) if SENSITIVE_NAME.search(k) else v) for k, v in parse_qsl(parts.query, keep_blank_values=True)] return scrub_text(urlunsplit(parts._replace(query=urlencode(q, safe="<>_")))) def scrub_json(node): if isinstance(node, dict): return {k: (mask(v) if isinstance(v, str) and SENSITIVE_NAME.search(k) else scrub_json(v)) for k, v in node.items()} if isinstance(node, list): return [scrub_json(v) for v in node] return scrub_text(node) if isinstance(node, str) else node def scrub_body(text, mime): if not text: return text if "json" in (mime or ""): try: return json.dumps(scrub_json(json.loads(text))) except ValueError: pass if "x-www-form-urlencoded" in (mime or ""): pairs = [{"name": k, "value": v} for k, v in parse_qsl(text, keep_blank_values=True)] scrub_pairs(pairs) return urlencode([(p["name"], p["value"]) for p in pairs], safe="<>_") return scrub_text(text) def drop_custom_fields(obj): """HAR custom fields start with '_' and can hold anything: drop them.""" if isinstance(obj, dict): return {k: drop_custom_fields(v) for k, v in obj.items() if not k.startswith("_")} if isinstance(obj, list): return [drop_custom_fields(v) for v in obj] return obj def scrub_entry(e): req, res = e["request"], e["response"] req["url"] = scrub_url(req["url"]) for part in (req, res): scrub_pairs(part.get("headers", [])) for c in part.get("cookies", []): c["value"] = mask(c.get("value", "")) scrub_pairs(req.get("queryString", [])) post = req.get("postData") if post: scrub_pairs(post.get("params", [])) post["text"] = scrub_body(post.get("text", ""), post.get("mimeType")) content = res.get("content", {}) if content.get("encoding") == "base64": content["text"] = "<BINARY BODY REMOVED>" else: content["text"] = scrub_body(content.get("text", ""), content.get("mimeType")) if res.get("redirectURL"): res["redirectURL"] = scrub_url(res["redirectURL"]) def main(src, dst): with open(src, encoding="utf-8-sig") as f: # spec: UTF-8, BOM allowed har = drop_custom_fields(json.load(f)) for entry in har["log"]["entries"]: scrub_entry(entry) out = json.dumps(har, indent=2) leaked = [v for v in placeholders if len(v) >= 6 and v in out] if leaked: sys.exit(f"refusing to write: {len(leaked)} secret value(s) still present") with open(dst, "w", encoding="utf-8") as f: f.write(out) print(f"{len(har['log']['entries'])} entries, {len(placeholders)} distinct secrets masked") if __name__ == "__main__": main(sys.argv[1], sys.argv[2]) A few design choices worth calling out:
- It errs toward masking. Any header, cookie, query parameter or JSON key whose name contains
auth,token,session,codeand so on gets masked. That will also hit harmless names likeauthororcountryCode. That's fine for evidence. - Cookie and bearer values are masked without their wrapper.
Bearer eyJ…in a header and the bareeyJ…in a login response map to the same placeholder, so the reader can see that the token the login returned is the one the next request used. - It refuses to write a file that still contains a value it masked. Placeholders are assigned as values are found, so the last step searches the output for every original value. An earlier version of this script didn't handle the
Locationheader: it masked the OAuthcodeinredirectURLbut left the same code in the header, and this check caught it and refused to write. - Base64 bodies and custom
_fields are dropped, not inspected. You rarely need them to prove a web bug, and you can't easily check what's inside them.
Here it is on a stand-in HAR for app.example.com, with four entries: a login, the cross-account read, the control, and an export link with a token in the query string. A small summary script prints one line per entry:
import json, sys from urllib.parse import urlsplit har = json.load(open(sys.argv[1], encoding="utf-8-sig")) for e in har["log"]["entries"]: req, res = e["request"], e["response"] u = urlsplit(req["url"]) path = u.path + ("?" + u.query if u.query else "") auth = next((h["value"] for h in req["headers"] if h["name"].lower() == "authorization"), "-") print(f'{req["method"]:5} {path:44} {res["status"]} {auth:18} {res["content"]["text"][:42]}') $ python3 har_scrub.py standin.har clean.har 4 entries, 8 distinct secrets masked $ python3 har_summary.py clean.har POST /api/login 200 - {"authentication": {"token": "<SECRET_3>", GET /api/invoices/1002 200 Bearer <SECRET_3> {"id": 1002, "owner": "bob-test", "total": GET /api/invoices/1002 200 Bearer <SECRET_6> {"id": 1002, "owner": "bob-test", "total": GET /export?format=csv&access_token=<SECRET_7> 302 - The proof is still readable: the token Alice got at login (<SECRET_3>) fetched invoice 1002, which belongs to bob-test, and Bob's own session (<SECRET_6>) is a different token. None of the eight values can be replayed.
Prove the scrub worked
A scrubber that says "done" is a detection, not a proof. Check the output with something that doesn't share the scrubber's logic. This checker walks every string in the file and flags anything that still looks like a credential:
#!/usr/bin/env python3 """Second opinion: flag anything in a HAR that still looks like a credential.""" import json, re, sys JWT = re.compile(r"eyJ[\w-]+\.eyJ[\w-]+\.[\w-]*") CRED = re.compile(r"(?i)\b(bearer|basic)\s+(?!<SECRET_)\S+") NAME = re.compile(r"(auth|cookie|token|secret|session|passw|api[-_]?key)", re.I) PLACEHOLDER = re.compile(r"^(<SECRET_\d+>|\w+ <SECRET_\d+>)$") def walk(node, path="$"): if isinstance(node, dict): if "name" in node and "value" in node and NAME.search(str(node["name"])): v = str(node["value"]).split(";")[0].split("=", 1)[-1].strip() if v and not PLACEHOLDER.match(v): yield path, f"{node['name']} has a raw value" for k, v in node.items(): yield from walk(v, f"{path}.{k}") elif isinstance(node, list): for i, v in enumerate(node): yield from walk(v, f"{path}[{i}]") elif isinstance(node, str): if JWT.search(node): yield path, "JWT-shaped string" if CRED.search(node): yield path, "Bearer/Basic credential" with open(sys.argv[1], encoding="utf-8-sig") as f: findings = list(walk(json.load(f))) for path, why in findings: print(f"{why:28} {path}") print("clean" if not findings else f"{len(findings)} finding(s)") sys.exit(1 if findings else 0) On the raw stand-in file it finds 14 problems, including a JWT the stand-in file tucks into a custom _initiator field (output trimmed):
$ python3 har_check.py standin.har session has a raw value $.log.entries[0].response.cookies[0] Set-Cookie has a raw value $.log.entries...

