# Security Audit of a Chrome Extension

Yes. An agent reads your extension's manifest, scripts and build, loads it in a browser, checks permissions, messaging and dependencies, and writes a report.

[Run this on Rush](https://cloud.getrush.ai/run/security-audit/chrome-extension/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent starts with the manifest, because that is what the store and the user see. In an extension built from chibat/chrome-extension-typescript-starter, `public/manifest.json` is Manifest V3 with an `action` popup, an `options_ui` page, a content script that runs `js/vendor.js` and `js/content_script.js` on `<all_urls>`, a `background` service worker at `js/background.js`, the `storage` permission and `<all_urls>` under `host_permissions`. The agent notes what is absent as well: no `content_security_policy` key, so the MV3 default policy applies to the popup and options pages; no `web_accessible_resources`, so nothing in `dist` is reachable from web pages; no `externally_connectable`, so web pages cannot message the extension; and no `minimum_chrome_version`.

Then it reads what the scripts do with those permissions. `src/content_script.tsx` listens on `chrome.runtime.onMessage`, and when a message carries `color` it writes the value into `document.body.style.backgroundColor` and logs it to the page's console; it never checks `sender`. `src/popup.tsx` queries the active tab, shows its URL in the popup, keeps a counter in the action badge, and sends `{ color: "#555555" }` to the tab. `src/options.tsx` reads and writes `favoriteColor` and `likesColor` in `chrome.storage.sync`. `src/background.ts` is a `setTimeout` loop every thirty seconds that does nothing, which in a service worker also keeps nothing alive. The agent weighs each against the manifest: a content script on every site that will set a style from any extension message, a popup that reads every tab's URL, and host permissions far wider than a colour demo needs.

The build and the dependencies get the same reading. `webpack/webpack.common.js` has four entries, splits a `vendor` chunk for everything but the background script, and copies `public/` into `dist/`; `webpack.dev.js` uses `inline-source-map`, so a development build ships TypeScript source inside the JavaScript, while `webpack.prod.js` sets production mode and no source map. `package.json` pins `react` and `react-dom` on 18, `@types/chrome` at 0.0.158, `webpack` with a caret on 5.94.0, `webpack-cli` on the 4 line, `ts-loader` on the 8 line and `typescript` on 5, with a `package-lock.json`; `.github/workflows/build.yml` runs `npm ci`, `npm run build` and `npm test` on Node 20 and 22 for every push and pull request. The agent runs `npm audit` against the lockfile and reads each advisory against where the package is used, since a build-time tool and a runtime bundle carry different weight.

The report is checked against a running extension, not only the source. The agent runs `npm ci` and `npm run build`, starts a Chromium in its sandbox with the unpacked `dist` loaded, reads the permission warnings Chrome shows for the manifest, opens a page and confirms the content script is injected there, opens the popup and the options page and reads the console for errors, and sends a message from the extension context to show that the content script accepts it without a sender check. It writes `security-audit.md` with one section each for permissions and host scope, the content script and messaging, the popup and tab access, storage, the service worker, the build and source maps, and dependencies. Each finding has a severity, the file and line, the check that showed it and the fix in terms of the manifest key or the API call, from narrowing `matches` and `host_permissions` to using `activeTab` to checking `sender.id` in the message listener.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "codex",
  "input": "Audit this Chrome extension for security problems and write security-audit.md. Read public/manifest.json, public/popup.html, public/options.html, src/background.ts, src/content_script.tsx, src/popup.tsx, src/options.tsx, src/sum.ts, webpack/webpack.common.js, webpack/webpack.dev.js, webpack/webpack.prod.js, package.json, package-lock.json, tsconfig.json, jest.config.js, .github/workflows/build.yml and README.md first. Run npm ci, npm run build and npm audit. Start a Chromium with the unpacked dist loaded, note the permission warnings the manifest produces, open a page and confirm the content script runs on it, open the popup and the options page and read their consoles, and send a runtime message from the extension context to show whether the content script checks the sender. Cover the content script's match pattern and host_permissions against what the code needs and whether activeTab would do, the message listener's missing sender check and what it writes into the page, the popup's reading of tab URLs, storage.sync use, the empty service worker loop, the absence of content_security_policy, web_accessible_resources, externally_connectable and minimum_chrome_version keys and what each default means, inline source maps in development builds, and each npm audit advisory judged by whether the package ships in the bundle. For each finding give the severity, the file and line, the check that showed it and the fix. Do not paste any secret. Change no code.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

`security-audit.md` comes back as an artifact on the session, with a `name`, a `mime_type` and a `url` on `api.phoenix.so` that downloads it with no key for about an hour; reading the session again returns a fresh link, and `GET /o/{org}/sessions/{id}/artifacts/security-audit.md` with the key works too. The report has sections for permissions and host scope, the content script and messaging, the popup and tab access, storage, the service worker, the build and source maps, and dependencies. Each finding has a severity, the file and line, the check performed against the loaded extension or the tool output that raised it, and the fix in terms of the manifest key or the Chrome API.

The run's full record at `GET /o/{org}/sessions/{id}/messages` keeps the build, the `npm audit` output, the browser steps with the permission warnings and console reads, and the message test, so a reviewer can trace every finding to the command or page that produced it. The repository has no new commit, because the prompt forbids code changes.

A reviewer reads the report top down, decides which findings to act on, and opens issues or a follow-up run for the fixes: narrowing the match pattern, adding a sender check, moving to `activeTab`, or updating the build tooling. The audit is a document to discuss, not a change to merge.

## Run it on every release build

Before the zip for the store is built, a job in the release workflow sends this body to `POST /o/{org}/sessions`, with `resources` naming the repository at the release branch through a `…/tree/<branch>` URL so the audit reads the code being shipped. One `request_id` per tag means a re-run of the workflow gets the session already started rather than a second audit. The repository must be covered by a Rush GitHub App installation, or the resource is `422 RESOURCE_NOT_ACCESSIBLE`.

A `webhook_url` on the API key delivers `run.completed` with `session_url`; your handler reads the session, downloads `security-audit.md` from its artifact `url`, and attaches it to the release so the audit travels with the build it describes, before the zip goes to the store.

## Why run it on Rush?

An extension audit needs a browser as much as a code reader: the permission warning a user will see, whether the content script really runs on a given page, and what the console says when the popup opens are all facts of a loaded extension, not of its source. The agent has a sandbox with Chromium in it, loads the unpacked build, and checks each claim before it writes it down.

Running it on Rush keeps the whole record: the build, the audit output, the browser steps and the report, each in one session a reviewer can open. Running it per release, from a workflow, makes the audit a document that exists for every version rather than once.

## Frequently asked questions

### Does the agent change the manifest or the code?

No. The prompt says to change no code, and the result is a report, not a pull request. Each finding names the manifest key or the line to change and the fix, so a follow-up run with the same repository can be asked to apply the ones you accept.

### What does loading the extension in a browser add?

The permission warning text Chrome derives from `host_permissions` and `content_scripts`, confirmation that the content script is injected on an arbitrary page, the consoles of the popup and options page, and a live check that the message listener accepts a message without inspecting `sender`. Those are things the source suggests and the browser confirms.

### How are npm audit results weighed?

By where the package runs. A finding in `webpack-cli` or `ts-loader` affects the build machine and is rated accordingly; a finding in a package that `webpack.common.js` bundles into `vendor.js` ships to every user and is rated higher. The report quotes the advisory and the path in the dependency tree for each.

### Is activeTab enough for this extension?

For the demo as written, the popup acts on the current tab after a click, which is what `activeTab` grants without a broad host permission or an install-time warning. The content script's `<all_urls>` match is the separate question, and the report sets out what narrowing it would cost in behaviour.

## More Chrome Extension jobs

- [Upgrade npm Dependencies in a Chrome Extension Project](https://getrush.ai/run/upgrade-npm-dependencies/chrome-extension/)
- [Upgrade a Chrome Extension to React 19](https://getrush.ai/run/upgrade-react-19/chrome-extension/)
- [Write Tests for a Chrome Extension](https://getrush.ai/run/write-extension-tests/chrome-extension/)

## The same job on other stacks

- [Run a Security Audit on an Electron App](https://getrush.ai/run/security-audit/electron/)
- [Run a Security Audit on an Elixir App](https://getrush.ai/run/security-audit/elixir/)
- [Run a Security Audit on a FastAPI App](https://getrush.ai/run/security-audit/fastapi/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
