A CVV, CVC or CID is a security code used in card verification. A form can check its length and characters, but it cannot determine the correct code from a PAN. This guide focuses on the developer boundary: what to validate locally, what a provider response means, and how a plausible logging test can miss the very data it was meant to detect.
Format is not verification
In this site’s profile, American Express uses four digits and the other configured networks use three. Keep the value as a string so 003 and 0007 retain their leading zeros. The CVV generator creates random format fixtures; it does not recover a real code or implement an issuer service.
Issuer-side generation uses secret key material and specified inputs. AWS’s card-data generation documentation distinguishes CVV variants and their inputs. Knowing a PAN and expiry does not supply those keys. This is different from the publicly computable check digit described in the Luhn guide.
Avoid the claim “unforgeable”: a short static code can be stolen or guessed. Likewise, a matching code is not proof of identity or physical possession. CVV1, printed CVV2, chip-related iCVV and dynamic verification values are not interchangeable fields. A wallet cryptogram should not be treated as another spelling of the printed code.
Keep the four decisions distinct
| Layer | Question | What a positive result does not establish |
|---|---|---|
| Input format | Is this a string of the expected ASCII-digit length? | Whether the code matches an account |
| Provider verification | What code-check result was returned? | Whether the entire payment succeeded |
| Payment state | Was the authorization or capture successful? | Whether every risk signal was positive |
| Merchant handling | What should this order do next? | That a single code-check flag is sufficient |
Provider-specific check states may include a match, mismatch, unavailable or unchecked result. For example, Stripe’s card-check fields are separate from the charge status. Preserve an unavailable or missing result as such; do not relabel it “passed” or apply a universal accept/reject rule from this article.
Reproduce the JSON log blind spot
A previous example searched text for cvc:123. That pattern misses the closing quote in a JSON key such as "cvc":"123". It also misses a nested JSON security-code field. This test preserves the failure as a regression example:
test('The former log regex misses JSON; the typed event omits payloads', () => {
const oldPattern = /\b(cvv2?|cvc2?|cid|security[_-]?code)\b\s*[:=]\s*["']?\d{3,4}/i;
assert.equal(oldPattern.test('cvc:123'), true);
assert.equal(oldPattern.test('{"cvc":"123"}'), false);
assert.equal(oldPattern.test('{"payment":{"security_code":"0007"}}'), false);
const event = paymentEvent({ network: 'amex', outcome: 'declined',
cvc: '123', payment: { security_code: '0007' } }, profile);
assert.deepEqual(event, { event: 'payment_result', network: 'amex', outcome: 'declined' });
assert.equal(JSON.stringify(event).includes('0007'), false);
});Instead of logging an arbitrary request and hoping a regex removes everything, the example constructs a small event with known scalar values:
export function paymentEvent(input, profile) {
const outcomes = ['accepted', 'declined', 'pending', 'invalid'];
if (!input || typeof input.network !== 'string' ||
!Object.hasOwn(profile.networks, input.network) || !outcomes.includes(input.outcome)) {
throw new TypeError('Expected a known network and event outcome');
}
// Do not spread a request, provider response or nested error into a log.
return { event: 'payment_result', network: input.network, outcome: input.outcome };
}Additional fields, including nested request and error objects, are omitted. Even the allowed fields reject unexpected objects and unknown strings. This function protects this particular event schema. It does not sanitize every logger, browser recorder, proxy, crash reporter or existing log archive in an application. Test those collection points separately, including errors before your own handler runs.
Run the input and logging cases
Extract the offline security-code examples and run with Node.js 22 or later:
node --test guide-examples.test.mjs
node guide-demo.mjs cvv
| Case | Input / condition | Expected result |
|---|---|---|
| cvv-leading-zero | '003'; expected length 3 | true |
| cvv-to-cid | '003'; expected length 4 | false |
| cid-leading-zero | '0007'; expected length 4 | true |
| cid-to-cvv | '0007'; expected length 3 | false |
| cvv-number | 3; expected length 3 | false |
| cvv-newline | '123\n'; expected length 3 | false |
| cvv-nested-log | Nested security code and extra cvc field | {"event":"payment_result","network":"amex","outcome":"declined"} |
The Amex fixture scenarios extend the leading-zero cases to network changes. Do not silently truncate a four-digit input when switching to a three-digit profile.
Saved cards do not justify retaining the code
For merchants, PCI SSC prohibits keeping the code after authorization, even encrypted or with customer permission. Its card-on-file FAQ addresses recurring use directly. Save the provider reference and the metadata needed for your product, not the submitted code.
A returning buyer’s click and an agreed off-session recurring charge are different initiation contexts. A provider may collect fresh verification for an appropriate flow; that is not a reason to retain a previously submitted code. The PCI developer guide traces storage boundaries. The PAN structure guide explains why the printed code is not part of the account-number anatomy.