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
Cookieheaders (session IDs, SSO tokens, CSRF cookies) -
Set-Cookieresponses that let anyone replay your authenticated session -
Authorization: Bearer ...JWTs, OAuth access tokens, and customX-Api-Keyheaders - Signed S3/GCS URLs and password-reset tokens sitting inside
queryString - Request
postDatabodies (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) andserverIPAddressvalues
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:
- Zero uploads: every byte stays in browser memory, verifiable in the browser's own DevTools Network tab.
- 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:
- Custom auth headers: internal gateways routinely use names like
X-Session-Context,X-Tenant-Proof,X-User-Assertion, orX-Edge-Sig. A regex misses them silently. - Secrets inside URLs and redirects: OAuth callback codes, magic-link tokens, and pre-signed download signatures live in
request.url,request.queryString, andresponse.redirectURL. - Unknown vendor keys: Chromium, Firefox, Charles Proxy, and browser extensions attach extra properties to
log,entries[],request, andresponse. If your scrubber copies the source object with{ ...entry }, unknown keys pass straight through into the output. - Wall-clock correlation:
startedDateTimetimestamps andserverIPAddressfields 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 toorigin + '/[redacted]'unless you explicitly opt intoretainPaths: true. - Redirect URLs are cleared unless the redirect target belongs to an explicitly allowed domain.
- Request and response bodies are dropped (
bodySize: 0, nopostData, nocontent.text) unless you check a specific entry index inretainRequestBodiesorretainResponseBodies. Even then, retention is blocked for binary/base64 payloads or decoded UTF-8 text larger than1 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.0throughHTTP/3). - Timestamps are rebased to Unix epoch (
1970-01-01T00:00:00.000Zplus relative offset from the earliest retained entry) unlessretainTimesis 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
unknownFieldremovals 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:
- Dedicated one-shot Web Worker: both
inspectandsanitizejobs run insidehar-sanitizer.worker.tsvia an abortable runner. If a user cancels or drops a new file,AbortControllerterminates the in-flight worker cleanly. - Strict structural limits before parsing: the validator enforces a
30 MiBbyte cap (HAR_MAX_BYTES), a20,000entry ceiling (HAR_MAX_ENTRIES), a max JSON nesting depth of60, and a1,000,000node cap before acceptinglog.version === '1.2'. - Structured audit report + review gate: sanitization returns two files:
cleaned.harandhar-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. - 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/ssltimings) 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:
- Open https://sunasty.com/har-sanitizer/.
- Press F12 -> Network, filter by Fetch/XHR, and clear the log.
- Click Load Sample (or drop your own
.harfile) and run Sanitize. - 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, andqueryStringfields by default rather than manually deletingAuthorizationlines in a text editor. - Filter out third-party analytics, auth provider, and payment domains before exporting.
- Keep
retainPathsandretainTimesoff 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.
