Extension code analysis

How to analyze a Chrome extension's JavaScript

The manual version of what our pipeline does to every extension: pull the package, read it, then run it and watch the traffic. Everything here works with free tools.

How do you analyze a Chrome extension's JavaScript?

Download the extension's CRX file from Google's update server using its ID, unzip it, and start with manifest.json: it lists the permissions, the background service worker, the content scripts and which sites they run on. Format the JavaScript with Prettier, then search it for network calls (fetch, XMLHttpRequest, sendBeacon, WebSocket), dynamic code (eval, new Function, remote scripts) and sensitive APIs (chrome.cookies, chrome.tabs, chrome.scripting, message listeners). Trace what data reaches each network call.

Then run it. Load it unpacked in a throwaway Chrome profile, open DevTools on its service worker and content scripts, and route the browser through an intercepting proxy such as mitmproxy so you see every request it makes while you use real sites. Static reading misses anything obfuscated or downloaded after install; running it is how you find out what it actually sends.

Updated

Step by step

  1. 1

    Get the extension ID

    It's the 32 characters (a to p) at the end of the Chrome Web Store URL, and on chrome://extensions with Developer mode on.

  2. 2

    Download the CRX

    Google's update server returns the current package for any ID. Set prodversion to a recent Chrome version or it may refuse.

    ID=cmkdbmfndkfgebldhnkbfhlneefdaaip
    curl -L -o ext.crx \
      "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=131.0&acceptformat=crx2,crx3&x=id%3D${ID}%26uc"
  3. 3

    Unpack it

    A CRX is a ZIP with a signed header in front. unzip skips the header and warns about extra bytes; the warning is expected.

    mkdir ext && unzip -q ext.crx -d ext; ls ext
  4. 4

    Read manifest.json first

    Note the permissions and host_permissions, the background service_worker, each content script and its matches, web_accessible_resources, externally_connectable and any content_security_policy. This tells you which files run where, and with what access.

    jq '{permissions, host_permissions, background, content_scripts, externally_connectable, web_accessible_resources}' ext/manifest.json
  5. 5

    Make the code readable

    Minified bundles become readable with a formatter. Heavier obfuscation (string arrays, encoded payloads) needs a deobfuscator such as webcrack or de4js, or stepping through it in DevTools.

    npx prettier --write 'ext/**/*.js'
    npx webcrack ext/background.js -o ext-deob
  6. 6

    Search for sinks and sensitive APIs

    Find every place data can leave and every place code can arrive. Then read back from each hit to see what data reaches it.

    grep -rnE 'fetch\(|XMLHttpRequest|sendBeacon|WebSocket|importScripts|eval\(|new Function|chrome\.(cookies|history|tabs|scripting|webRequest|runtime\.connectNative)|onMessage(External)?|addEventListener\(.message' ext
  7. 7

    Pull out every URL and domain

    Hardcoded hosts are the quickest lead. A coupon extension talking to an analytics host in another country is worth a closer look. Remember that hosts can also arrive from remote config.

    grep -rhoE 'https?://[a-zA-Z0-9._-]+' ext | sort | uniq -c | sort -rn
  8. 8

    Run it with DevTools and a proxy

    Load the folder with Load unpacked on chrome://extensions in a fresh profile, or start Chrome for Testing with it (branded Chrome ignores --load-extension since version 137). Open the service worker's DevTools from the extension card, and run mitmproxy to capture traffic. Then use the browser: sign in to webmail, search, shop. Watch what leaves and when.

    mitmweb --listen-port 8080 &
    "$CHROME_FOR_TESTING" --user-data-dir=$(mktemp -d) \
      --proxy-server=127.0.0.1:8080 --load-extension=$PWD/ext
  9. 9

    Follow the messages

    Content scripts, the service worker, injected page scripts and iframes talk through chrome.runtime messages and window.postMessage. A message listener that doesn't check the sender's origin is a vulnerability even when nothing is malicious. That's how MultiPassword leaked passwords and how any website could command Urban VPN.

  10. 10

    Check for delayed or conditional behavior

    Payloads often wait: a timer of days, a check on country or language, a remote flag. Search for setTimeout and alarms with long delays, and for code paths gated on navigator.language, timezone or a fetched config. If you can, change the clock and locale and run it again.

What each finding means

In the codeWhy it matters
fetch / XHR / sendBeacon to a third-party hostWhere data leaves. Check what is in the body: URLs, page text, form fields.
eval, new Function, remote script tagsCode that wasn't in the package the store reviewed. Manifest V3 forbids remote code, so seeing it is a red flag.
chrome.cookies with broad host accessCan read session cookies for every site, enough to take over accounts.
chrome.tabs / chrome.history listenersCan record every URL you visit, the basis of browsing-history resale.
Content script reading document.body or input valuesPage scraping or form capture. Normal for some tools, alarming for most.
runtime.connectNativeA bridge to a native program on the machine. Audit the native host too; Signer.Digital's CVSS 9.3 was there.
window.addEventListener('message') without an origin checkAny page can talk to the extension. Classic source of extension vulnerabilities.
Base64 blobs, string arrays, AES or XOR routinesSomething is being hidden. Decode it before deciding anything.

Where manual analysis stops

  • You analyzed one version. Extensions auto-update, and the next one can be different without any change in permissions.
  • Server-side behavior is invisible. If the extension fetches its instructions, you only see the ones you were sent.
  • Conditional payloads may never fire on your machine, in your country, on your first day.
  • It takes hours per extension. A typical company runs a few hundred distinct extensions.

Frequently asked questions

How do I download a Chrome extension's source code?

Download the CRX from Google's update server: https://clients2.google.com/service/update2/crx?response=redirect&prodversion=131.0&acceptformat=crx2,crx3&x=id%3D<ID>%26uc, replacing <ID> with the extension ID. Then unzip it. If it's already installed, the unpacked files are in your Chrome profile's Extensions folder, under a folder named after the ID.

Can I see what data a Chrome extension sends?

Yes. Open chrome://extensions, turn on Developer mode, click the service worker link on the extension's card and use the Network tab. Content-script requests appear in the page's own DevTools. To catch everything in one place, run the browser through an intercepting proxy such as mitmproxy or Burp Suite.

What tools help analyze Chrome extensions?

Chrome DevTools, jq and grep cover most of it. Prettier and webcrack make bundled or obfuscated code readable. tarnish and ExtAnalysis automate static checks, DoubleX traces data flows, and mitmproxy captures network traffic.

Is the code in a CRX the code that runs?

It's the code the store shipped. Under Manifest V3 extensions may not run remotely hosted code, but they can still fetch configuration, and older or sideloaded extensions may load scripts at runtime. That is why running the extension matters as much as reading it.

Related

Skip the hours per extension.

We read and run every extension your company uses, and show you the evidence.