Learning center

Check a HAR or trace that someone else cleaned

Before you draw a conclusion from a cleaned recording, find out what was removed and whether the missing part could hold your answer. Before you pass it on, search it yourself, because one value is stored in several places.

One secret, several fields#

A fixture page filled two inputs, sent a POST with a bearer token, a key in the query and a value in the body, and received a cookie and a JSON body. Playwright 1.65 recorded a HAR and a trace.

ValueIn the HARIn the trace archive
Authorization headerRequest headerstrace.network, and trace.trace because a script passed it
Query keyRequest URL, and queryStringtrace.network, trace.trace
Request bodypostData.textA file in resources, trace.trace
Response bodyresponse.content.textA file in resources
Session cookieResponse headers, response cookies, request headers, request cookiestrace.network
Text typed in an input, password type includedNot presenttrace.trace

A cleaner then removed Authorization, Cookie and Set-Cookie headers, and emptied the requests' cookies. The token was gone. The query key was still there twice and the request body once. The response body and the session cookie, in the cookies array, remained in each of the two API responses. Cleaning by header name left four of the five values that the HAR held.

The trace row for typed text is a surprise for people who check only network data: actions record their arguments. With sources enabled, the test's own source file is in the archive as well.

Before you trust a conclusion#

Finding in the recordingCould cleaning cause it?Ask
No Cookie on the requestYes"Was the header removed, or absent?"
An empty response bodyYes, or the body was never recordedThe response's size fields, and the original's hash
A request is missingYes, if entries were filteredThe number of entries before and after
Order and timing look oddRarelyWhether the file was merged from two

A good cleaner replaces and does not delete: Cookie: [value removed] keeps the fact that a cookie was sent. If you clean one, do that, and list the rules in a file next to it.

Before you pass it on#

python3 -m zipfile -e trace.zip trace/        # a trace is a zip
grep -rlE 'Bearer |eyJ[A-Za-z0-9_-]{10,}' trace/ recording.har
jq -r '
  .log.entries | to_entries[]
  | (.key + 1) as $entry
  | [
      (.value.request.url | capture("^[^?#]*\\?(?<query>[^#]*)").query
       | split("&")[] | split("=")[0]),
      .value.request.queryString[]?.name
    ]
  | map(ascii_downcase | select(test("^(key|token|code|sig)$"))) | unique
  | select(length > 0) | [$entry, join(",")] | @tsv
' recording.har
jq -r '
  .log.entries | to_entries[]
  | (.value.response.cookies | length) as $count
  | select($count > 0) | [(.key + 1), $count] | @tsv
' recording.har

The first jq command checks both URL queries and the HAR's queryString fields. It prints the entry number, starting at 1, and only matching names from the list in the command. The second prints the entry number and the number of response cookies. For the fictional recording below, the output is 1<TAB>token and 1<TAB>1 respectively.

These checks cover common names and shapes. Check application-specific parameter names and secrets elsewhere in the recording. Put a known marker in the test account, such as a display name of ZZMARKER, and search for it with grep -rlF 'ZZMARKER' trace/ recording.har to list matching files. A text search misses markers in HAR bodies stored with encoding: "base64".

Screenshots and video in a trace need eyes.

Decide#

If a value that the cleaning removed decides the question, ask for a new recording with a test account. That avoids both problems. If only structure matters, the cleaned file is enough. If a live credential is in it, stop passing it on, tell its owner and have it revoked.

Worked example#

In a synthetic HAR, entry 1 is a POST /cart with a token query parameter and a 401 response. The sender removed cookie headers and cleared the request cookie arrays. The response's cookies array still contains one cookie. Ben asks the sender to remove the remaining values before sharing the file again.

A new recording with a test account shows the 401 response setting a cookie that the browser sends on entry 2. A response can also expire a cookie. The later request shows what the browser sent then. To learn whether entry 1 reached the server with a valid session, Ben checks the server's authentication decision for that request using its request ID. See how Set-Cookie stores, replaces and expires cookies.

Recording and sharing one yourself is covered in sharing a HAR file. Return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading