Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 38 ยท Payment Concepts and Security

PCI DSS, Tokenization and Card Data Safety

Understand PCI DSS in plain language, why Stripe Elements and Checkout keep you in the lightest compliance tier, how tokenization works, the Luhn check and what never to log or store.

A card number is one of the most valuable and most regulated pieces of data your system could touch. The card networks created the Payment Card Industry Data Security Standard (PCI DSS), a set of rules for anyone who stores, processes or transmits cardholder data. Break them and you can face fines, higher fees, and the loss of your ability to take cards. The good news: with Stripe's hosted pieces you can build a full checkout while your servers never see a card number, which reduces your burden to the lightest level.

This lesson explains the idea, the vocabulary, and the rules of thumb. It is not legal advice; confirm your obligations with your payment provider and, for large merchants, a qualified assessor.

What counts as card data

The standard talks about two groups:

  • Cardholder data: the primary account number (PAN, the long card number), the cardholder name, the expiry date, and the service code.
  • Sensitive authentication data: the full magnetic-stripe data, the CVC/CVV (three or four digits), and PINs. You must never store these after authorization, even encrypted.

The strict rule for developers: if a card number or CVC passes through your server, your logs, your analytics or your error tracker, you are now in scope for a much heavier standard.

Tokenization: swap the secret for a stand-in

Tokenization replaces sensitive data with a meaningless reference. The customer types the card into a field hosted by Stripe (an iframe served from Stripe's domain). The browser sends the number directly to Stripe, which stores it in its vault and returns an ID such as pm_1Ox9... (a PaymentMethod). Your server only ever sees that ID and a few harmless facts: brand, last four digits and expiry.

flowchart LR
  C["Customer types card"] -->|"card data goes directly"| S["Stripe vault<br/>(hosted fields)"]
  S -->|"returns pm_... token"| B["Browser"]
  B -->|"sends token + order"| M["Your server"]
  M -->|"charge using pm_..."| S

Your server handles tokens, never raw card numbers.

A token is useless to a thief. It can only be used with your Stripe account, only in ways your account allows, and it cannot be turned back into a card number.

The compliance tiers (SAQs)

Merchants prove compliance with a Self-Assessment Questionnaire (SAQ). The one you need depends on how you take payments.

Integration Typical SAQ Your burden
Stripe Checkout (hosted page redirect) SAQ A Smallest
Payment Element / Elements (Stripe iframes) SAQ A Smallest, if done correctly
Your own card form posting to your server SAQ D Very heavy, avoid
Card data sent to your server API directly SAQ D Heavy; Stripe disables this by default

"SAQ A" still has duties: serve your pages over HTTPS, keep scripts on your payment pages under control (a malicious script on your page could skim card fields on some integrations), and keep your own systems patched. Stripe provides an annual compliance flow in the Dashboard to help you fill it in.

Keep card data away from you

Hosted fields Card typed into Stripe
Token You receive pm_...
No raw data Not in logs either
1 / 2

What your server may keep

You may safely store, as returned by Stripe:

  • the PaymentMethod ID (pm_...),
  • the brand (visa), last four digits, and expiry month/year (to remind the customer which card is saved),
  • the customer ID (cus_...).

You may not store the PAN, the CVC, or anything that lets someone rebuild the number. If your database column is named card_number, that is a red flag.

The Luhn check: a typo detector, not security

Card numbers end with a check digit computed by the Luhn algorithm. It catches mistyped digits so a form can warn instantly, without calling any API. It proves nothing about whether the card exists or has money. Stripe's hosted fields run it for you, so you rarely implement it, but building it is a nice way to see how card numbers are structured. The numbers below are standard published test numbers.

Node.js Validate a card number with Luhn

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The last number differs by one digit and fails. That quick feedback is all Luhn gives you.

Never log card data: a scrubber

Even if you use hosted fields, a bug or a copy-paste in a support form may put a card number into your logs. A defensive scrubber that masks anything that looks like a PAN is cheap insurance. This is a stand-in for the filter you would add to your logging layer.

Node.js Scrub card numbers from log lines

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The scrubber leaves the order number alone (it fails Luhn) but masks real-looking cards. It does not catch the CVC, which is another reason to keep raw fields off your servers altogether.

Practical rules

  1. Use Checkout or the Payment Element. Do not build your own card inputs.
  2. Serve every page over HTTPS with a modern TLS configuration.
  3. Load Stripe.js directly from js.stripe.com on each page; never bundle or self-host it, or you lose security updates and may break compliance.
  4. Add a Content-Security-Policy header limiting where scripts load from, and review third-party scripts on checkout pages.
  5. Keep secrets out of the repo (see Accounts and API Keys).
  6. If you ever must store a card, you want a PCI Level 1 vault, not your own database: use Stripe's customer and PaymentMethod objects.

Next, the wider security picture around the API itself: API Security and Secrets.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which of these may you never store, even encrypted, after authorization?

    Sensitive authentication data, including the CVC, must not be stored after authorization.
  2. 2. What does tokenization give your server?

    The card data lives in Stripe's vault; your server handles only the token.
  3. 3. A passing Luhn check proves that...

    Luhn only detects typos in the number. Authorization is what checks the card with the issuer.
  4. 4. Why load Stripe.js from js.stripe.com instead of self-hosting it?

    Stripe updates the library continuously. A stale self-hosted copy can miss fixes and risk compliance.

Summary

  • PCI DSS governs card data; hosted fields and Checkout keep you at the lightest tier (SAQ A).
  • Tokenization swaps the card for a pm_ reference.
  • Store only IDs, brand, last four and expiry; never PAN or CVC.
  • Luhn catches typos only; scrub card-like numbers from logs.
  • Use HTTPS, load Stripe.js from Stripe, and control scripts on checkout pages.

Next: API Security and Secrets