Security rules

NGB015: Sensitive payment data persistence

Reports cardholder data — primary account numbers (PAN), card verification codes (CVV/CVC) and card expiry stored next to them — written to localStorage, sessionStorage, IndexedDB or document.cookie.

Property Value
Rule ID NGB015
Category Sensitive data & payment security
Default severity critical
CWE CWE-312, CWE-922
Built-in presets recommended: error, strict: error, payments: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports cardholder data — primary account numbers (PAN), card verification codes (CVV/CVC) and card expiry stored next to them — written to localStorage, sessionStorage, IndexedDB or document.cookie. Evidence comes from storage keys, value and object-literal property names, declared types, names along the data flow, and Luhn-valid card-number literals.

Why it matters

Browser storage is unencrypted at rest and readable by any script in the origin. Persisting card numbers expands the PCI DSS scope of the frontend; persisting CVV/CVC after authorization is forbidden by PCI DSS in all cases.

Detection behavior and supported patterns

  • Storage writes as in NGB014, plus document.cookie = "pan=…"
  • Names: cardNumber, ccNumber, pan, cvv, cvc, cvv2, securityCode, track2, cardExpiry (weak on its own)
  • localStorage.setItem("checkout", JSON.stringify({ cardNumber, cvv })) — object literal keys are inspected
  • Luhn-valid 13–19 digit literals reaching storage
  • Not reported: last4, maskedPan, cardBrand, paymentId, opaque PSP payment tokens, hashed/masked values

Example

TypeScript
localStorage.setItem('checkout', JSON.stringify({ cardNumber: this.form.value.cardNumber, cvv: this.form.value.cvv }));

Safer alternative

TypeScript
localStorage.setItem('checkout', JSON.stringify({ paymentToken: result.token, brand: result.brand, last4: result.last4 }));

Remediation

Never persist card data in the browser. Use your payment provider's hosted fields / iframe so card data never touches your code, and keep only the opaque token, brand and last four digits.

False-positive considerations

  • A field named pan that is not a card number (e.g. a camera pan setting) can be reported; rename it or add a scoped exception.

Known limitations

  • Card data stored under neutral names with untyped values is not detected.
  • Card data inside forms serialized wholesale (JSON.stringify(this.form.value)) is reported only when the form type or flow reveals card fields.
  • Server-side storage and logging are out of scope.

References

Run it

Shell
ngbastion explain NGB015