Web Development 5 min read 868 words

Skimmers that tunnel under CSP with WebRTC

ES
Skimmers that tunnel under CSP with WebRTC

You can have the perfect fence round your vegetable patch, tall, with no gaps and a gate only you open, and still one day find your carrots nibbled. The mole didn’t jump the fence or force the gate: it went underneath, where nobody was looking.

A couple of weeks ago, with the Optimizely attack, I explained that a well-made CSP would have stopped much of the damage, and that on 17 sites connect-src stopped the stolen data from leaving the page. Well, InfoHawk has now published a case that looks designed to dodge exactly that defence: card skimmers on online shops that get the data out through a WebRTC channel, under the fence.

What happened

The week before Black Friday, someone planted a skimmer on five shops, and the curious thing is they did it through four different routes:

ShopHow it got in
LascanaA modified Quorum marketing pixel
Samsonite and American TouristerThe Seers cookie banner configuration
Revolve and FWRDA modified file on Revolve’s own CDN

The cookie banner one is quite something: a configuration field that should have held a URL (the privacy policy link) contained a hidden image with an onerror handler that loaded the malicious code. InfoHawk notified everyone on 24 November and the code was removed between that day and the next, although nobody knows how many shoppers may have been affected. Lascana was the only one where they saw the skimmer send test card data off-site.

How it gets underneath

The attack has seven steps, and the key is that only two are normal web requests:

flowchart LR
    A["Loader · pixel, banner or CDN"] --> B["Script on S3"]
    B -->|HTTP · signalling| C["northbridgeads · ice and rel"]
    B -->|WebRTC| D["Cloudflare TURN relay"]
    D --> E["Attacker · skimmer and stolen data"]
  1. The loader reaches the page through one of the routes in the table.
  2. It downloads a script (Insds.js or gtage.js) from an S3 bucket.
  3. It checks whether it’s worth acting: only on small touch screens, and on Samsonite only on /checkout.
  4. It makes two HTTP requests to a domain named like an ad agency to negotiate the connection: GET /_cf/ice and POST /_cf/rel.
  5. It opens a WebRTC data channel through Cloudflare’s TURN relay, so only Cloudflare addresses are visible and never the real server.
  6. Over that channel it receives the skimmer in chunks, checks its SHA-256 and runs it with eval.
  7. And over that same channel it sends out the card number, expiry, security code, name, address, phone and email, while the shopper is typing them, even before the shop validates the payment.

The important detail is in steps 5 to 7. The CSP connect-src directive controls the “usual” requests (fetch, XMLHttpRequest, WebSockets…), but according to InfoHawk the WebRTC data channel falls outside its reach. So a CSP that would have blocked sending data via fetch lets the same data out over WebRTC without noticing.

And then there’s the hiding: since it only activates on mobile checkout, scans run from a desktop browser, or that only check the homepage, see nothing. It’s the mole that only comes out at night.

How to block the tunnel

The good news is that the tunnel has an entrance you can see: the two signalling requests in step 4 are plain old HTTP, and those connect-src does control. Without them, the skimmer can’t negotiate the WebRTC connection, whichever file was tampered with. Hence the report’s first recommendation: on payment pages, a connect-src that only allows the domains you really use.

Content-Security-Policy: connect-src 'self' https://api.your-gateway.example; script-src 'self' https://js.your-gateway.example

The rest of the recommendations are along the lines of what we saw with Optimizely, but they’re worth going over:

  • Isolate the card fields in the payment gateway’s iframe, where your page’s scripts can’t read them.
  • Remove third-party tags from payment and sign-in pages. The marketing pixel can live perfectly well on the rest of the site.
  • Review vendor configurations (cookie banners, tag managers…), and make sure a URL field contains only a URL.
  • Test checkout on mobile, not just on desktop, and watch for WebRTC connections where there shouldn’t be any.
  • Look for the indicators the report publishes: scripts from <brand>-static.s3.amazonaws[.]com, requests to *.northbridgeads[.]com and strings like KghRtc or rtc-signal-v1.

As a note of my own: the CSP Level 3 draft includes a specific directive, webrtc, to block these connections, but browser support is very limited, so for now it’s best not to count on it.

The underlying lesson

What I take away is that CSP is a great fence, but it only protects where you’ve put it. Every new browser API is a potential tunnel nobody had thought about, and attackers are very good at finding them. And once again, the way in wasn’t the shop itself, but one of those third-party scripts (a pixel, a cookie banner) someone added one day and nobody looks at any more, which can change at any moment and load code you’ve never reviewed.

So, as well as the fence, it’s the usual: know which scripts you have on the pages that matter, remove the ones you don’t need and don’t assume that what worked yesterday is still safe today. Especially on checkout, which is where the carrots are.