Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 3 min read

How to check Playwright HAR files for sensitive data before committing them

The first CI run on my demo pull request failed with two findings. The next run passed. Both runs checked the same file, fixtures/profile.har. The difference was two fields in a recorded API response. I built HAR Privac

The first CI run on my demo pull request failed with two findings. The next run passed. Both runs checked the same file, fixtures/profile.har. The difference was two fields in a recorded API response.

I built HAR Privacy Check for developers who keep Playwright network recordings alongside their tests. It has a local CLI, a pre-commit hook, and a GitHub Action. Here’s the small example I used to test it.

What was in the recording?

Playwright can replay recorded HTTP traffic with routeFromHAR(). In my demo, the recording contains a response from a fictional profile endpoint. This is the JSON stored inside the HAR response body:

{
  "displayName": "Demo Student",
  "access_token": "DEMO_ONLY_SENTINEL",
  "email": "[email protected]"
}

The profile test only needs displayName. The other two fields are synthetic, but they illustrate how a fixture can carry more data than the test uses.

On the first commit, the scanner reported:

HAR 1 | entry 1 | response body | sensitive field
HAR 1 | entry 1 | response body | sensitive field
1 HAR file(s), 2 finding(s). Coverage: supported fields only.

Those two identical lines are intentional. Each finding points to the first HAR entry and its response body. Neither the token nor the email appears in the CI log. The trade-off is that someone inspecting a large response still has to locate the fields.

I then restored the fixture containing only displayName and pushed a second commit. The same check reported 0 finding(s).

See the demo pull request Β· Failing run Β· Passing run

Why the pre-commit hook reads the Git index

Suppose you run git add fixtures/profile.har, spot an email address, and remove it in your editor. Your working copy is now clean. Until you stage the correction, Git still has the earlier version queued for the commit.

That detail shaped the hook. It reads the staged Git blob. A regression test stages a fixture with sensitive fields, overwrites the working copy with a clean fixture, and verifies that the check still fails. You can inspect that case in the test suite.

The timing matters too. The local hook can catch a finding before a commit. A GitHub Actions check runs after the push, when the file has already reached the remote repository.

Try it locally

With Git and Node.js 24.12 or later, you can reproduce both results using the bundled synthetic fixtures:

git clone --branch v0.1.1 https://github.com/TitanGra16/har-privacy-check.git
cd har-privacy-check

node src/cli.ts examples/clean.har
node src/cli.ts examples/synthetic-sensitive.json

The first command that runs the scanner exits with 0. The second exits with 1 and reports two findings. You can run this example without installing dependencies or using a real browser recording.

Add it to a GitHub Actions workflow

Create .github/workflows/har-privacy.yml in a repository that tracks .har fixtures:

name: HAR privacy
on: [push, pull_request]

permissions:
  contents: read

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - uses: TitanGra16/har-privacy-check@12aff46c4db620830034eb26c7901c042fdb114d # v0.1.1

One detail worth checking on the first run is the file count. If the log says 0 HAR file(s), 0 finding(s), the scanner had no tracked .har files to inspect. In the clean demo, the result is 1 HAR file(s), 0 finding(s).

What a clean result tells you

Version v0.1.1 checks plain JSON HAR files up to 8 MiB each. Its rules cover known sensitive field names in structured data, cookies, and query parameters, including those in redirect targets. A secret under an unrelated JSON key can escape detection. Compressed HAR archives are outside the index scan.

I’d be interested in feedback from people who maintain Playwright fixtures: when a response contains hundreds of fields, would you want the warning to include a JSON path such as profile.email, while keeping the value out of the log?

GitHub Marketplace Β· Source code

Writing disclosure: I used ChatGPT to draft this article from the project source and its public demo runs.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.