GitHub - brianhama/in-browser-sec-audit: Google Chrome security audit tool

GitHub

4 min read Original article ↗

A Chrome extension (Manifest V3) that, when enabled for a tab, captures every first-party JavaScript file the site loads and sends it to an OpenAI model with a prompt tuned to surface server-side attack vectors — API endpoints, injectable parameters, SSRF/IDOR/SQLi/auth-bypass surface, leaked secrets — plus concrete routes for further testing. Results render in a dedicated Security Audit panel in Chrome DevTools.

I built this tool because it automates the workflow that I usually use to kick off a pentest for a website. It doesn't do anything too fancy, but it saves me a lot of time and I thought others might find it useful as well. Feel free to submit pull requests.

The Security Audit DevTools panel showing server-side findings — reconstructed endpoints, a leaked API key, and SSRF (CWE-918) and IDOR (CWE-639) findings with concrete testing routes.

What it does

  • Per-tab toggle from the toolbar (and from the panel). Off by default; the content script stays completely idle until you enable a tab.
  • First-party only. Third-party CDNs/analytics are ignored. Scope is configurable: same-origin (default), same-hostname, or same-site (eTLD+1, approx).
  • Server-side focus. The default prompt treats client JS as a map of the backend and hunts for: reconstructed API/GraphQL/RPC endpoints, injection reaching the server (SQLi/NoSQLi/command/SSTI/XXE), SSRF, IDOR & broken access control, mass assignment, auth weaknesses, path traversal, insecure deserialization, business-logic gaps, and secret/config leakage.
  • DevTools panel with per-script cards: overall risk, reconstructed endpoint table, detected secrets, and findings (severity, confidence, CWE, evidence, testing routes, and a fix).
  • Configurable API key, model (picker + custom id), OpenAI-compatible base URL, concurrency, chunk size, temperature, token budget, inline-script analysis, skip patterns, and a custom system prompt.
  • Extras: content-hash result cache (dedupes identical bundles), large-file chunking, a paste-a-snippet analyzer, severity/text filtering, and Markdown/JSON report export.

Install (unpacked)

  1. Open chrome://extensions, enable Developer mode.
  2. Load unpacked → select this folder.

Configure

  1. Open DevTools (⌥⌘I / F12)
  2. Security Audit tab
  3. gear icon → set your OpenAI API key and model
  4. Save.

Audit Website

  1. Open a site you're authorized to test. Click the toolbar icon → Audit this tab.
  2. Open DevTools (⌥⌘I / F12)
  3. Security Audit tab

How capture works

A document_start content script (all frames) watches for <script> elements and resource performance entries, fetches first-party script bodies (same-origin fetch, so no CORS issues), hashes them, and forwards them to the background service worker. The worker runs a bounded-concurrency queue of OpenAI calls, caches by content hash, and streams results to the panel over a long-lived port. Because the DevTools panel occupies the tab's debugging channel, capture deliberately avoids chrome.debugger and relies on content-script fetches instead.

Permissions

Permission Why
storage Settings + result cache (local); per-tab runtime state (session).
tabs Resolve the active tab / its origin; message content scripts.
scripting Inject the content script into a tab that was loaded before enabling.
activeTab Grants host access to the current tab on the toolbar click, so enabling a pre-existing tab can inject and start immediately.
webNavigation Distinguish real document commits from SPA history/hash changes, so in-app navigation doesn't wipe results.
host_permissions: api.openai.com Call the OpenAI API from the background/panel.
optional_host_permissions Requested on demand: the page origin when you enable, a custom base-URL host, and broad host access when you pick a non-origin scope.
content scripts on http(s)://* Observe scripts on the site under test (idle unless enabled; only the top frame and same-origin subframes ever capture).

Privacy & safety notes

  • Your API key is stored in chrome.storage.local on your machine and sent only to the endpoint you configure (default api.openai.com).
  • First-party script source code is sent to that endpoint for analysis. Don't enable this on sites whose code you may not submit to a third party.
  • Script bodies are fetched with credentials: 'omit', so the authenticated / per-user variant of a dynamic script endpoint (which can embed session tokens or PII) is never pulled and forwarded.
  • Only the top frame and same-origin subframes capture — scripts inside cross-origin third-party iframes are never read or sent.

File layout

manifest.json
background/service-worker.js   coordination, queue, badge, streaming
content/content-script.js      first-party JS capture (idle until enabled)
popup/                         toolbar enable/disable + quick stats
devtools/                      panel registration + full audit UI
lib/                           constants, storage, prompt, OpenAI client
icons/                         icons

Development

  • No build step: ES modules load directly (background is a module worker; popup and panel pages use <script type="module">; the content script is a standalone classic script).
  • Syntax check: node --check on each .js, or run the checks in tools/ (see below).

Disclaimer

This tool is for legit security testing and research and we are not responsible for any misuse for illegal or unauthorized purposes!