In Manifest v2, we were able to easily intecept and read server responses via the webRequestBlocking API. Manifest v2 is deprecated, and the webRequestBlocking API was replaced with DNR (declarativeNetRequest) in Manifest v3. DNR doesn't allow you to read responses or manipulate them. Instead, we need to use other APIs.
We have a client side app (./server/index.html) which is distributed via a web server.
This extension verifies that the server only distributes authentic versions of them i.e. not tampered with.
The extension performs the following steps:
- Block the request to the app URL via DNR (declarativeNetRequest API)
- Intercept top level browser navigation to the server, using the tabs API
- Register a response interceptor using the debugger API
- Hash the response and check it matches the expected hash
- If they match, allow the response to pass through to the user
- If they don't match, redirect to an error page
This process ensures that when a user visits the app, their browser will only load it if it passes the integrity checks.
The server distributes a client side app: ./server/index.html.
- Navigate to chrome://extensions
- Toggle "Developer mode" in the top right corner if you haven't already
- Click "Load unpacked" button in the top left corner
- Select the "extension" directory of this repository
- The extension will now be loaded, you can turn it on or off with the toggle
- Run
npm start
from this repository to start the http://localhost:9191 server - Visit http://localhost:9191 in your browser to see the extension verify the integrity
- Modify ./server/index.html and reload http://localhost:9191 in your browser to see the extension block the request and redirect to an error page
This same extension can be built much easier in Firefox using the filterResponseData API.
There appears to be a bug in Chrome whereby if you have devtools open on the network tab, the chrome.tabs.update API just hangs forever when called from the debugger interceptor. I recommend testing the extension with devtools closed.
- Check if browser caching affects interception if the user has already visited the site without the extension and has a local cached version