Skip to content

Securing a headless checkout

When Flint hosts checkout, Flint runs the page, the buyer's session, and the code around the card fields. When you build your own checkout, your page and your backend sit in the payment path, and securing them is your job. Card data still never reaches you: Stripe Elements collects it in frames that your page can't read.

This guide assumes the integration in Build your own checkout.

What moves to you#

ConcernFlint-hosted checkoutYour checkout
Card and bank detailsStripe ElementsStripe Elements
Order total, payment confirmation, attempt stateFlintFlint
Scripts that run on the payment pageFlintYou
Buyer session, CSRF, and origin checksFlintYou
Storing the checkout credentialFlintYour backend
Limiting how fast one buyer can call checkoutFlintYour backend

Flint still decides what the buyer owes and whether the payment succeeded, and it still enforces what each credential can do. Your page and your relay are the new parts that an attacker can target.

The trust boundary#

A headless checkout touches three places: your backend, the buyer's browser, and Stripe. Card numbers, expiry dates, and CVCs stay in Stripe's frames. Every other value has one place it may live.

credentials

Stays on your backend

  • Your Flint API key, flint_live_...
  • The checkout credential, ckat_..., from checkout_auth_token on the checkout session response
  • Customer session secrets, flint_cses_...

Tie the checkout credential and customer session secret to your own browser session.

single purpose

Passes through the browser

  • payment_collection.stripe, to mount Elements, including Stripe's publishable key
  • pending_actions[].client_action.url by default when a new payment needs buyer authentication. Treat it as a bearer credential and discard it after use. Flint's API returns no Stripe client secret for this type; Stripe's authentication page can receive it during the challenge.
  • pending_actions[].client_action.stripe, only for Stripe.js handleNextAction. Its PaymentIntent client secret can also confirm the payment.
  • A ConfirmationToken, ctoken_..., from Stripe.js to your backend
  • A gift card proof, gccp_..., from Flint's challenge frame to your backend

Use each one for its job, then discard it.

Checkout session and order IDs, such as cs_... and ord_..., are identifiers, not credentials. The browser may see them, but your relay shouldn't take them from it.

The checkout credential and customer session secret are narrower than an API key, but neither is safe in a browser. A checkout credential can change its order's line items and discounts, apply gift cards, and pay. A customer session secret acts for one buyer across /v1/me, which includes renewing their subscriptions on a saved card.

Warning: The browser never calls Flint

Flint has no publishable key, and production CORS allows only Flint's own origins. Your storefront reaches Flint through your backend. The one Flint page the browser loads is the gift card challenge, in an iframe, and only after repeated failed codes.

Build a narrow relay#

Your backend relays the buyer's checkout to Flint. A relay that forwards whatever the browser asks for is an open proxy with your credentials attached, so give it only the jobs your checkout needs.

  • Derive Flint IDs from your own records. The browser sends a cart reference. Your backend looks up which order and checkout session belong to that cart and to the signed-in browser session. If the browser can name an ord_... or cs_..., a buyer can name someone else's.
  • Expose jobs, not endpoints. Routes like /checkout/{cart_id}/select-delivery and /checkout/{cart_id}/pay are each auditable. A generic /flint-proxy route is not.
  • Choose the credential in one place. Every Flint request carries either the checkout credential or your API key in Authorization: Bearer, and a checkout credential starts with ckat_. Decide centrally, so no route quietly gains more authority than it needs. Because the credential travels in Authorization, redact that header in your own request logs, proxies, and error reporters.
  • Use the checkout credential for buyer actions. Routes the buyer drives, such as delivery, gift cards, and payment, run under the checkout credential. Those calls reach only one session and its order, and Flint applies its checkout controls to them. Keep your API key for your own back-office work.
  • Return buyer-safe state. Pass the browser the amounts, statuses, and Stripe values it renders or runs, not raw Flint responses.
JavaScript
// Every Flint call goes through one function, so no route builds its own headers.
async function callFlint(path, { credential, body, idempotencyKey }) {
  const headers = { "Content-Type": "application/json" };
  if (credential.type === "checkout") {
    headers["Authorization"] = `Bearer ${credential.secret}`;
  } else {
    headers["Authorization"] = `Bearer ${process.env.FLINT_API_KEY}`;
  }
  if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;

  const response = await fetch(`https://api.withflintpay.com${path}`, {
    method: body ? "POST" : "GET",
    headers,
    body: body && JSON.stringify(body),
  });
  return response.json();
}

app.post("/checkout/:cartId/pay", requireSession, requireSameOrigin, limitPerSession("pay"), async (req, res) => {
  // The browser names its cart. Your records say which order and session it owns.
  const checkout = await db.checkouts.findOne({
    cartId: req.params.cartId,
    browserSessionId: req.session.id,
  });
  if (!checkout) return res.sendStatus(404);

  const result = await callFlint(`/v1/orders/${checkout.orderId}/pay`, {
    credential: {
      type: "checkout",
      secret: checkout.checkoutAuthToken,
    },
    idempotencyKey: `pay-${checkout.id}-${req.body.submission_id}`,
    body: {
      action: "pay",
      payment_source: { credential_type: "stripe_confirmation_token", stripe: { confirmation_token: req.body.confirmation_token } },
      // The total and order version you showed the buyer, from your records, not from the request.
      expected_outstanding_money: checkout.displayedOutstandingMoney,
      expected_version: checkout.displayedOrderVersion,
    },
  });

  res.json(toBuyerState(result));
});

The browser sends the cart ID, the ConfirmationToken, and a submission ID it generates once per click. Everything else comes from your records.

Rate limit by buyer#

Flint rate limits API requests by credential, merchant, and the IP address that calls it. Card payments made with a headless checkout credential have a separate failed-attempt budget for each checkout session. Buyers who share your relay's IP keep their own session budgets. The fingerprint and billing email budgets apply across sessions for the same card or email. Keep each buyer on their own session and enforce per-buyer limits on your payment and session creation routes. See card testing for the hourly limits and how to respond to an attack.

Limit your own routes for session bootstrap, pricing, delivery quotes, gift cards, payment start, and payment resume. Key the limits on your browser session and on signals such as the buyer's IP address.

Protect your endpoints#

Cookie-authenticated checkout routes need CSRF protection and a strict check of the Origin header. Serve checkout over HTTPS only, and mark session cookies Secure, HttpOnly, and SameSite. Flint's hosted checkout handled these for you; ordinary web application practice applies to yours.

Credential handling#

Keep API keys, checkout credentials, customer session secrets, Stripe client secrets, ConfirmationTokens, and gift card proofs out of logs, analytics, URLs, error messages, and persistent browser storage. Error-reporting and session-replay tools capture request bodies by default, so configure them to drop these fields.

Use a ConfirmationToken once. A ctoken_... is bound to the payment it confirms, and Flint rejects a token already used for another payment with 409 ACTION_NOT_ALLOWED with reason confirmation_token_unusable. Don't keep it as retry authority. To resume an attempt after a 3D Secure challenge, send only action: "resume" and the order_payment_attempt_id. Embedded payments covers the resume request.

Scope each key to its job. Give the key your relay uses only what checkout needs, and keep administrative work on a separate key.

JobScopes
Create and pay orderscommerce.orders.read, commerce.orders.write
Create, read, and close checkout sessionscheckouts.checkout_sessions.read, checkouts.checkout_sessions.write
Register Apple Pay and Google Pay domainspayments.payment_method_domains.write, on a separate administrative key

Revoke what leaks.

LeakedWhat to do
API keyRevoke it immediately. It works until you do. If a key leaks covers the replacement and the audit.
Checkout credentialBefore payment, close the session with POST /v1/checkout-sessions/{checkout_session_id}/close and create a new one for the order. The credential reaches only its own session and order.
Customer session secretRevoke the session, or all of the customer's sessions if you suspect an account takeover. See Revoke on sign-out and on suspicion.

Promotion code attempts#

Flint counts unknown promotion codes submitted with a checkout credential, including codes applied through POST /v1/orders/{order_id}/discounts. The failure budgets match the gift card thresholds: five per checkout session, ten per IP within the merchant environment, and fifty per merchant environment. Each budget expires one hour after its first attempt; later failures do not extend it. Promotion and gift card budgets are separate.

When any budget is exhausted, Flint returns 429 RATE_LIMIT_EXCEEDED before checking another code. Retry-After gives the remaining cooldown in seconds. Show the buyer "Too many incorrect promotion codes. Try again later." and wait for that delay before retrying. A fresh checkout session, including one created by resolving a payment link, does not reset the IP or merchant budget. The cooldown applies to every code lookup, so a correct code entered after the limit must also wait.

Known codes do not consume failure budget, even when the order is ineligible for the promotion. Valid codes require no challenge. Your relay should use the checkout credential for buyer-entered codes and enforce its own per-buyer limits. For single-use promotions, generate long, random codes rather than short or predictable patterns.

The gift card challenge frame#

Flint counts failed gift card codes. After enough failures in an hour, every code a buyer applies needs a proof from a challenge that runs on a Flint page, framed in your checkout. Apply gift cards walks through the flow and the message format. These are its security controls:

  • Apply typed codes with the checkout credential. Flint counts and challenges code lookups only under the checkout credential. Requests with an API key skip those controls, so a storefront that applied buyer-entered codes with one would let anyone guess codes through your backend.
  • Set page_origin when you create the session. Flint lets only that origin frame the challenge, and posts the result only to it, never to *. A headless session without page_origin can't show the challenge.
  • Load only gift_card_challenge.url. Take the URL from the API and treat it as opaque. It is the only Flint page your checkout embeds.
  • Allow the frame in your CSP. Add https://checkout.withflintpay.com to frame-src. No script-src change is needed, because your page loads no Flint script.
  • Check every message. Accept a message only when event.origin is the origin of gift_card_challenge.url, event.source is your iframe's contentWindow, type is one you expect, and checkout_session_id is the session on your page. Any window can post to yours, and the check is yours to make.
  • Treat the proof as a credential. It is single use, valid for five minutes, and bound to its checkout session. Send it only to your own backend, over your CSRF-protected session.

Verification code requests#

A buyer who reloads the page between asking for a code and typing it needs the form back. Your backend can read the checkout's code requests with the checkout credential, as Restore the code form after a reload shows, without sending another code.

  • Only the checkout credential reads. Your API key can't call these routes, and another checkout's credential gets 404 RESOURCE_NOT_FOUND. Relay these reads from your backend with the checkout credential, and derive the checkout session from your own records.
  • Emails are masked. A read returns email as b•••@example.com, even where the request response returned the address as typed. Anyone holding a credential for the session, such as a forwarded checkout link, sees only the masked form of an address someone else typed. Render it as returned, and don't ask your relay to unmask it.
  • No secret comes back. A read never returns the code, a hash of it, or a token, and never says how many tries remain or whether the request was confirmed or replaced. Confirming a code still requires the buyer to type it.
  • An emailed request reads the same whether or not Flint sent a code. Someone who requests codes for chosen addresses and reads them back learns nothing about which addresses have saved details at your business. A text request still shows phone_last_digits, as the request response does.
  • Reads end at expires_at. A code request is readable for 15 minutes, or 10 for a text. After that it leaves the list and reading it by ID returns 404 RESOURCE_NOT_FOUND. Don't store code request IDs beyond the page state that uses them.
  • Reads don't count against the buyer. They use no try and add nothing to the code limits, so rate limit your own relay route for them as you do for code requests: Rate limit by buyer.

Your payment page runs your JavaScript#

Flint's hosted checkout ran only Flint's code. Your checkout runs your code, plus whatever your tag manager, analytics, session recorder, and testing tools load. All of it runs on the page that surrounds the card fields.

A script on your page can't read inside Stripe's frames, so the card number stays out of reach. It can do everything around them: draw fake card fields over the real ones, change the amount the buyer sees, or send the buyer somewhere else. Protect the page itself.

  • Set a Content Security Policy. Allow only the scripts and frames checkout needs.
  • Load Stripe.js from js.stripe.com. Stripe requires it to be loaded from there, not bundled or self-hosted.
  • Pin other third-party code. Load a fixed version with subresource integrity, or host a reviewed copy.
  • Inventory every script. Know what each script on the payment page does and who can change it. Remove what checkout doesn't need, especially session recorders.
  • Don't let other sites frame checkout. Set frame-ancestors 'none'. The gift card challenge won't load if another origin frames your page.

This starting policy covers Stripe Elements, 3D Secure, and gift card challenges on a checkout page using Flint's production API.

HTTP
Content-Security-Policy:
  default-src 'self';
  script-src 'self' https://js.stripe.com https://*.js.stripe.com;
  frame-src https://js.stripe.com https://*.js.stripe.com https://hooks.stripe.com https://payment-returns.withflintpay.com https://checkout.withflintpay.com;
  connect-src 'self' https://api.stripe.com;
  frame-ancestors 'none';
  object-src 'none';
  base-uri 'self'

The 3D Secure frame loads the Flint action and return on payment-returns.withflintpay.com and the Stripe challenge on hooks.stripe.com. If you use Flint's staging API, use https://payment-returns.staging.withflintpay.com and https://checkout.staging.withflintpay.com in place of the production Flint origins. API keys for Flint sandboxes still use the production origins. For a return inside the iframe, add the destination origin to frame-src and serve a return page whose frame-ancestors allows your checkout origin. If the destination is the checkout page protected by frame-ancestors 'none', use a full-page redirect.

Send the policy as a single header line. connect-src 'self' covers calls to your own backend. Stripe lists additional directives for Link, the Address Element, and web fonts in its security guide. Ship a new policy with Content-Security-Policy-Report-Only first, and fix what it reports before you enforce it. Check Safari's Web Inspector Console while running a test challenge. A report-only violation identifies a request the enforcing policy would block. If you collect reports from Safari versions that lack report-to support, include report-uri as a fallback. Check the blocked origin and the document that reported it before changing your allowlist.

PCI scope#

Card details go from the buyer's browser into Stripe's frames and on to Stripe. Your servers and Flint's receive a ConfirmationToken, never a card number.

Where card data goesResponse
Your pageStripeYour backendFlintcard details, typed into Elements framesctoken_...ctoken_...POST /v1/orders/{order_id}/payconfirm the payment with the tokenpayment attempt
  1. Your page sends card details, typed into Elements frames to Stripe
  2. Stripe returns ctoken_... to Your page
  3. Your page sends ctoken_... to Your backend
  4. Your backend sends POST /v1/orders/{order_id}/pay to Flint
  5. Flint sends confirm the payment with the token to Stripe
  6. Flint returns payment attempt to Your backend

Keeping card data off your systems is the largest single factor in reducing your PCI scope. It doesn't decide your self-assessment questionnaire on its own.

Because the page around the card fields is yours, its integrity is yours too. PCI DSS v4 requirement 6.4.3 covers authorizing and checking the integrity of every script on a payment page, and 11.6.1 covers detecting unauthorized changes to the page and its headers. SAQ A, since its January 2025 revision, instead asks you to confirm your site isn't susceptible to script attacks that could affect your e-commerce systems. Either way, the controls in Your payment page runs your JavaScript are how you meet them. Moving card entry into an iframe doesn't move them off you.

Flint can describe the data flow. It can't tell you which questionnaire you are eligible for, because that depends on your whole environment, the other systems it touches, and your acquirer. Take the flow above to your acquirer or a Qualified Security Assessor (QSA), and be wary of anyone who assigns a questionnaire from the integration type alone.

Before you go live#

  • API keys, checkout credentials, and customer session secrets never reach the browser.
  • Every relay route derives Flint IDs from your own records, never from IDs the browser sends.
  • One function chooses the credential for each Flint request, and buyer actions use the checkout credential.
  • Checkout routes have CSRF protection, Origin checks, and per-buyer rate limits.
  • No log, URL, analytics event, or browser storage holds a credential, client secret, ConfirmationToken, or gift card proof.
  • Checkout is served over HTTPS with an enforced Content Security Policy and frame-ancestors 'none'.
  • Every script on the payment page is inventoried and justified.
  • If you take gift cards: sessions are created with page_origin, frame-src allows https://checkout.withflintpay.com, challenge messages are checked for origin, source, type, and session, and buyer-entered codes are applied with the checkout credential.
  • Fulfillment runs from a signature-verified, deduplicated order.paid webhook or a backend read, never from the browser reporting success. It checks the order's dispute_status first.
Build your own checkoutThe headless checkout session, Stripe Elements, payment attempts, and gift cards.Checkout sessionsWhat the checkout credential can do, and the session lifecycle.API key securityStoring, scoping, and rotating API keys.WebhooksVerifying signatures and deduplicating deliveries before you fulfill.

Was this helpful?