← All postsBlog

Showing real card data in a mobile wallet — without ever holding it

Overhead view of an engineer at a desk with a laptop and a curved monitor

The problem

A wallet app we work on has to show the user their payment card: the full number, the expiry date, the CVV, and a form to set the PIN. The card is issued through Gnosis Pay. The rule around that screen is simple. Our servers must never see, log or store any of that data. The moment card numbers pass through our code we are inside the PCI DSS scope, and one careless log line turns a small feature into a serious incident.

Gnosis Pay solves this with PSE (Partner Secure Elements). The card data is rendered inside iframes that Gnosis Pay hosts, so it never enters our DOM and never reaches our backend. To open one of those iframes the front end needs an ephemeral token. To get an ephemeral token, someone has to authenticate with mTLS — a client certificate signed by Gnosis Pay — and a mobile app can never hold that certificate safely. So the real problem was not "how do we show the card". It was: how do we build the smallest possible backend that holds a private key, hands out short-lived tokens, and still works inside a React Native WebView on both iOS and Android?

Our approach

The backend does two things and nothing else. It holds the certificate. We generated an EC P-256 key and a CSR with the App ID as the common name, sent the CSR to Gnosis Pay, and got a signed certificate back. The key never left the machine that created it, and the certificate and key live in environment variables, not in the repository.

In Node the whole mTLS setup is one agent:

const httpsAgent = new https.Agent({
  cert: process.env.SIGNED_CERTIFICATES,
  key: process.env.PRIVATE_KEY,
  rejectUnauthorized: true,
});

await axios({
  httpsAgent,
  method: "POST",
  url: "https://api-pse.gnosispay.com/api/v1/ephemeral-token"
});

It exposes the token in the two shapes our clients need. One shared function makes the mTLS call; two routes wrap it.

  • GET /api/gnosis/ephemeral-token → { ephemeralToken, expiresAt, appID }
  • GET /api/gnosis/native-webview → an HTML page with the token already in it

The JSON route serves our web frontend, while the HTML route exists to support React Native. Since @gnosispay/pse-sdk is a browser-only SDK, the mobile app loads a lightweight, hosted HTML page inside a WebView to run it. This ~40-line page contains an unpkg import map, a container div for the secure frame, and a postMessage listener. The native side passes the App ID, card token, Gnosis API auth token, and element type (card-data or set-pin) to the page, which then invokes gp.init().

This separation is intentional: ephemeral tokens come from our backend, while user sessions and card references originate directly from the app, ensuring we never proxy user sessions.

The hard decisions and trade-offs

Instead of having the WebView fetch the token asynchronously, we inject it directly into the HTML during server-side rendering. While this places the token in the page source, it is an acceptable trade-off: the page is served over TLS, the token is short-lived and bound to our App ID, and the template engine safely escapes the output. In exchange, this approach eliminates an extra network round-trip and completely bypasses CORS complexity within the WebView.

Content Security Policy took most of the time. Six commits over eight days are all CSP, and every one of them was a guess that turned out wrong. Two things we learned the hard way:

  • There are two hosts, not one. The token API is api-pse.gnosispay.com (backend, mTLS). The iframes come from api-pse-public.gnosispay.com. Allow the wrong one and you get an empty frame and no useful error.
  • frame-src and frame-ancestors answer different questions. frame-src says who we may embed; frame-ancestors says who may embed us. We needed both while testing in a desktop browser, and removed frame-ancestors once the page only lived in the WebView.

We also keep 'unsafe-inline' in script-src, because the SDK is loaded through an import map and an inline module script. That is a real weakening, and the reason this page sits on its own route with nothing else on it.

The outcome

The card screen works on the web and inside the React Native WebView, and no card data touches our infrastructure. There is nothing to store, so there is no card data in our database, none in our logs, and no PCI scope beyond the token call itself.

  • About 90 lines of controller code, one mTLS call, two routes.
  • A fresh token on every opening of the card screen; expiresAt goes back to the client, so the app knows what it holds.
  • One shared function serves both the JSON and the HTML path.
  • The certificate is EC P-256 and valid for two years, April 2026 to April 2028. That date is in the calendar now.

The last bug was the least interesting and the most annoying: on Android the card was invisible. The iframe had no height, because its container had no height. Nineteen lines of CSS setting html, body and the frame container to 100% fixed it.

Stack & takeaways

Stack: Node 18, Express 5, axios with https.Agent, Helmet, EJS, @gnosispay/pse-sdk 1.2.2, Docker on Heroku.

  • When a vendor says "backend only", they mean the private key. Design that backend as a key holder with exactly one job and keep everything else out of it.
  • Read the CSP violation in the browser console before changing code. Most of our commits were guesses at the wrong domain.
  • A PEM file in an environment variable works, but the newlines have to survive. Use multi-line quoted values, and check the value the process actually receives — not the one you pasted.
  • Put *.pem in .gitignore in the first commit, not the tenth.
  • Short-lived tokens make other problems smaller. If a token leaks from an HTML source, it has probably already expired.

Related: Native, Flutter or React Native? Choosing a stack based on the application