# Walk through a client-side attack (/docs/consent-management/security-controls/walkthrough-a-client-side-attack)

This page follows one attacker through your page. After reading it, you can match each attempt to the airgap.js setting that stops it, and say what you would see afterward.

The attack is web skimming. An attacker gets a script onto your checkout page, often through a third-party vendor. The script reads the form and sends the data to a server that the attacker controls. The same pattern has other names, such as Magecart and formjacking.

## Run it yourself [#run-it-yourself]

The [airgap security demo](https://github.com/transcend-io/examples/tree/main/airgap-security-demo) is a small page that makes attempts 1 to 3 below, plus one call to an approved host as a control. It runs in four modes: off, report-only, block, and block with navigation control.

## What the attacker tries [#what-the-attacker-tries]

| Attempt | What the script does                                                               |
| ------- | ---------------------------------------------------------------------------------- |
| 1       | Loads an image from a host you never approved, with the data in the URL.           |
| 2       | Calls `fetch` on an unapproved host from an injected inline script.                |
| 3       | Sets `location` to an unapproved host, with the form fields in the query string.   |
| 4       | Sends the data to a host you approved, but to the attacker's own account on it.    |
| 5       | Sends an email address or card number to a third-party host that your rules allow. |

## Which control stops each attempt [#which-control-stops-each-attempt]

| Attempt | Nothing installed | Report-only                 | Block unknown requests                | Block plus navigation control                   |
| ------- | ----------------- | --------------------------- | ------------------------------------- | ----------------------------------------------- |
| 1       | Data leaves.      | Data leaves. Host listed.   | Stopped. The host appears in Triage.  | Stopped.                                        |
| 2       | Data leaves.      | Data leaves. Host listed.   | Stopped. The host appears in Triage.  | Stopped.                                        |
| 3       | Data leaves.      | Data leaves.                | Data leaves. The page is replaced.    | Stopped. The navigation host appears in Triage. |
| 4       | Data leaves.      | Data leaves.                | Data leaves. The host is approved.    | Data leaves. The host is approved.              |
| 5       | Data leaves.      | Data leaves.                | Data leaves if the host is approved.  | Data leaves if the host is approved.            |

Attempts 4 and 5 need a request override. See [Attempt 4](#attempt-4-an-approved-host-with-the-wrong-account) and [Attempt 5](#attempt-5-sensitive-data-sent-to-an-allowed-host).

<Callout type="info" title="Use Block to enforce">
  Report-only mode tries to allow every request. Use it to build an inventory, not to stop an attack. See [Inventory a site in report-only mode](./inventory-a-site-in-report-only-mode.mdx).
</Callout>

## Attempts 1 and 2: unapproved hosts [#attempts-1-and-2-unapproved-hosts]

Set the Unknown Request Policy to **Block**. airgap.js blocks requests to hosts that are not in your data flows.

In the browser, the **Network** tab shows no request to the host. In Triage, the host appears as a new host, so you learn that something tried to reach it. See [Block unknown requests](./block-unknown-requests.mdx).

## Attempt 3: navigation [#attempt-3-navigation]

A navigation replaces the page, so request rules do not see it. Turn on navigation control to treat it as a request. airgap.js then cancels a navigation to an unknown host. See [Stop exfiltration through navigation](./stop-exfiltration-through-navigation.mdx).

Navigation control needs the Navigation API for full coverage. In an older browser, it covers only form submissions and `window.open()`.

## Attempt 4: an approved host with the wrong account [#attempt-4-an-approved-host-with-the-wrong-account]

A host in your data flows is allowed for every request. A script can use that to send data to its own account on a vendor you approved. A host rule cannot tell your account from the attacker's.

A request override can. It reads the URL and blocks any request with an account that is not yours. See [Pin the analytics account](./write-request-overrides.mdx#pin-the-analytics-account).

## Attempt 5: sensitive data sent to an allowed host [#attempt-5-sensitive-data-sent-to-an-allowed-host]

An override can also read the content of a request. Block an email address, a card number, or a session token that is headed to a host outside your site. See [Write request overrides](./write-request-overrides.mdx#block-an-email-address-in-a-request-to-another-site).

## What you see afterward [#what-you-see-afterward]

| Control                   | Where to look                                                                                                                   |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| Block unknown requests    | Triage lists the new host. The **Network** tab shows no request.                                                                |
| Generated CSP             | The browser fires a `securitypolicyviolation` event. airgap.js sends the blocked host to telemetry.                             |
| Navigation control        | Telemetry lists the navigation host. The page stays in place.                                                                   |
| Request override          | The **Network** tab shows no request.                                                                                           |

Telemetry sends only the host and scheme of each request. It never sends the path or query string, so a stolen card number in a URL does not reach telemetry.

## What this does not stop [#what-this-does-not-stop]

- **A compromised script on an allowed host can still run.** airgap.js authorizes by URL and host. It does not hash script contents or read what a script does. Use Subresource Integrity and a nonce-based `script-src` in your header for that.
- **A script that loads before airgap.js is not regulated.** airgap.js must be the first script on the page.
- **Overrides cannot wait.** A rule runs in the page and cannot call a remote service. It sees only text bodies.
- **Browser actions are out of reach.** Typing in the address bar and the back and forward buttons are not covered by navigation control.

See the [security overview](./overview.mdx#limitations) for the full list.
