A support engineer asks for a network trace to reproduce a flaky API bug. You open Chrome DevTools, check Preserve log, reproduce the error, right-click, and hit Save all as HAR with content. Two minutes later that .har file is attached to a Jira ticket, a Zendesk thread, or a public GitHub issue.

What just left your machine is not a harmless timing waterfall. A single HAR 1.2 archive from a logged-in session typically contains:

  • Active Cookie headers (session IDs, SSO tokens, CSRF cookies)
  • Set-Cookie responses that let anyone replay your authenticated session
  • Authorization: Bearer ... JWTs, OAuth access tokens, and custom X-Api-Key headers
  • Signed S3/GCS URLs and password-reset tokens sitting inside queryString
  • Request postData bodies (login forms, customer PII, GraphQL mutations)
  • Full JSON/HTML response payloads (response.content.text), often including internal account records
  • Non-standard browser extension fields (_initiator, _priority, vendor metadata) and serverIPAddress values

Even worse: many developers paste that sensitive .har file into the first "online HAR sanitizer" they find on Google, uploading the exact production credentials they were trying to protect to a third-party server.

When I built the Sunasty HAR Sanitizer (and extracted the standalone scrubbing core as har-clean on npm), I wanted two guarantees:

  1. Zero uploads: every byte stays in browser memory, verifiable in the browser's own DevTools Network tab.
  2. Allowlist reconstruction instead of regex blocklisting: never trust a blocklist to catch every secret header name or custom vendor field.

Why Regex Blocklists Fail on Real HAR Files

The intuitive first draft of a HAR scrubber looks like this: parse the JSON, clone the object, walk every headers array, and redact anything whose name matches /authorization|cookie|token|api-key|secret/i.

That approach breaks in production for four concrete reasons:

  1. Custom auth headers: internal gateways routinely use names like X-Session-Context, X-Tenant-Proof, X-User-Assertion, or X-Edge-Sig. A regex misses them silently.
  2. Secrets inside URLs and redirects: OAuth callback codes, magic-link tokens, and pre-signed download signatures live in request.url, request.queryString, and response.redirectURL.
  3. Unknown vendor keys: Chromium, Firefox, Charles Proxy, and browser extensions attach extra properties to log, entries[], request, and response. If your scrubber copies the source object with { ...entry }, unknown keys pass straight through into the output.
  4. Wall-clock correlation: startedDateTime timestamps and serverIPAddress fields can tie an anonymized bug report back to a specific customer session or internal VPC node.

Switching to Default-Deny Allowlist Reconstruction

Instead of mutating or spreading the input HAR object, har-sanitizer.ts builds a brand-new HAR 1.2 structure from scratch using explicit allowlists. Nothing from the input survives unless it is explicitly validated and reconstructed.

Here is the core policy model used in Sunasty's TypeScript engine:

export interface HarPolicy { domains: string[]; retainPaths: boolean; retainTimes: boolean; retainRequestBodies: number[]; retainResponseBodies: number[]; } 

By default, when you load a .har file and run sanitization:

  • All headers and cookies are dropped (headers: [], cookies: [], headersSize: -1) on both requests and responses.
  • Query strings are dropped (queryString: []), and URLs are rewritten to origin + '/[redacted]' unless you explicitly opt into retainPaths: true.
  • Redirect URLs are cleared unless the redirect target belongs to an explicitly allowed domain.
  • Request and response bodies are dropped (bodySize: 0, no postData, no content.text) unless you check a specific entry index in retainRequestBodies or retainResponseBodies. Even then, retention is blocked for binary/base64 payloads or decoded UTF-8 text larger than 1 MiB, and restricted to a strict text/JSON/XML/form-urlencoded MIME allowlist.
  • HTTP methods and versions are normalized against explicit sets (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, CONNECT, TRACE; HTTP/1.0 through HTTP/3).
  • Timestamps are rebased to Unix epoch (1970-01-01T00:00:00.000Z plus relative offset from the earliest retained entry) unless retainTimes is enabled. That preserves the exact waterfall timing deltas needed to diagnose slow requests while erasing when the session actually happened.
  • Unknown keys are never copied and are logged explicitly as unknownField removals in the audit report.

Here is the simplified request builder showing the zero-spread pattern:

function cleanHarUrl(value: unknown, retainPaths: boolean): string { const parsed = parseHttpUrl(value); if (!parsed) return 'https://redacted.invalid/'; return `${parsed.origin}${retainPaths ? parsed.pathname : '/[redacted]'}`; } function buildSafeRequest( request: Record<string, unknown>, policy: HarPolicy, keepRequest: boolean, ): Record<string, unknown> { const safe: Record<string, unknown> = { method: cleanHttpMethod(request.method), url: cleanHarUrl(request.url, policy.retainPaths), httpVersion: cleanHttpVersion(request.httpVersion), cookies: [], headers: [], queryString: [], headersSize: -1, bodySize: keepRequest ? new TextEncoder().encode(asString(asRecord(request.postData).text)).byteLength : 0, }; if (keepRequest) { safe.postData = { mimeType: cleanMime(asRecord(request.postData).mimeType), text: asRecord(request.postData).text, }; } return safe; } 

Notice what is missing: there is no ...request anywhere. If a proxy tool injects a custom _authSnapshot field onto request, it cannot leak into cleaned.har.

Guardrails for Untrusted 30 MiB Browser Traces

A HAR file from a long SPA session can easily reach tens of megabytes or contain deeply nested JSON payloads that freeze the main UI thread.

To keep browser execution predictable and safe:

  1. Dedicated one-shot Web Worker: both inspect and sanitize jobs run inside har-sanitizer.worker.ts via an abortable runner. If a user cancels or drops a new file, AbortController terminates the in-flight worker cleanly.
  2. Strict structural limits before parsing: the validator enforces a 30 MiB byte cap (HAR_MAX_BYTES), a 20,000 entry ceiling (HAR_MAX_ENTRIES), a max JSON nesting depth of 60, and a 1,000,000 node cap before accepting log.version === '1.2'.
  3. Structured audit report + review gate: sanitization returns two files: cleaned.har and har-removal-report.json (format: "sunasty-har-cleanup-v1"), listing every removed path (removed, redacted, excludedDomain, unknownField) without echoing raw secret values into the report. In the UI, the download button stays disabled until the user inspects the before/after review list and checks the confirmation box.
  4. Debugging utility preserved: even with all headers and bodies stripped, the sanitizer computes a clean waterfall summary (total duration, per-entry blocked/dns/connect/send/wait/receive/ssl timings) and sanitized cURL snippets so engineers can still reproduce timing bottlenecks.

Using har-clean in Node.js or CI

If you prefer scrubbing HAR files from the terminal or inside a support intake script, the standalone npm package (har-clean) is zero-dependency TypeScript/ESM:

npm install har-clean 

You can also test the browser version directly without installing anything at sunasty.com/har-sanitizer/.

Verifying the Zero-Upload Claim Yourself (F12 Check)

Never take a website's privacy badge at face value when handling credentials. Because Sunasty is a static Astro 7 build with Web Workers and WebAssembly processing in browser RAM, verifying zero uploads takes ten seconds:

  1. Open https://sunasty.com/har-sanitizer/.
  2. Press F12 -> Network, filter by Fetch/XHR, and clear the log.
  3. Click Load Sample (or drop your own .har file) and run Sanitize.
  4. Watch the Network panel: 0 requests, 0 bytes uploaded. You can even disconnect Wi-Fi after the page loads and run the entire inspect + sanitize + export workflow offline.

If you also need to scrub personal data (emails, IBANs, phone numbers, credit card numbers, or custom keywords) from text logs or support tickets before pasting them into an LLM, the companion PII Redactor follows the exact same local-only model with reversible tokens.

Checklist Before Attaching Any HAR File to a Ticket

  • Export the trace in a fresh incognito window whenever possible so unrelated tabs and extensions stay out of the log.
  • Strip all headers, cookies, and queryString fields by default rather than manually deleting Authorization lines in a text editor.
  • Filter out third-party analytics, auth provider, and payment domains before exporting.
  • Keep retainPaths and retainTimes off unless the bug genuinely depends on URL path parameters or wall-clock correlation.
  • Check the before/after diff and keep the removal audit report if your security team requires proof of redaction.

How does your team handle HAR traces from customers or staging environments today? If you have run into weird non-standard HAR fields from proxies or mobile debuggers, drop them in the comments.