Developer notes
Overview · Installation · Configuration · Usage · Developer notes · FAQ
How it plugs into CS-Cart
Section titled “How it plugs into CS-Cart”No core file is changed. Everything runs through PHP hooks, controllers, schemas and template hooks.
| Where | What |
|---|---|
before_dispatch (storefront) |
The gate: a POST to a protected dispatch builds the visitor (IP, session, device, e-mail, card, cart, amount), records the attempt, decides, and either lets the request through or sets a notification and redirects (checkout, or the order page for orders.repay). Runs before the CSRF check and before any controller. |
before_dispatch (admin) |
Alarm and attack-mode notice, once per administrator session. |
place_order |
Remembers the visitor of the new order (?:kv_cts_orders; Multi-Vendor: parent and vendor orders, one group). |
change_order_status_post |
Failed status (setting) -> one failed payment per group, escalation, junk clean-up, attack mode, alarm. Paid status (fn_get_settled_order_statuses()) -> paid. Runs for payment notifications and admin changes too, so every gateway is covered. |
kv_captcha_pro_get_forms |
Registers the form kv_cts_challenge (dispatch kv_card_testing_shield.verify) in Captcha Pro 1.1+. |
checkout:final_section_customer_notes (.post), orders:repay (.post) |
The check box above the Place order / Pay button. |
index:alert_block, index:simple_dashboard_content |
Dashboard line. |
Hook arguments are identical in 4.17.2 (Ultimate) and 4.21.2 (Multi-Vendor).
Decision order
Section titled “Decision order”- Allow list -> allowed (never checked or blocked).
- Block list -> refused.
- Active block of any key (IP, session, device, e-mail, card) -> refused.
- Velocity rules: block level -> the connection (IP, session, device) and, for e-mail / card rules, that e-mail or card are blocked for the block duration; refused.
- Attack mode: guests must sign in / minimum total (refused) or need the check.
- Guest rules: minimum total (refused); check from the Nth attempt of the session.
- Velocity rules at check level, challenge list.
- A check is satisfied by a pass (session + device, N uses, M minutes; one use per attempt, atomic
UPDATE ... WHERE uses_left > 0). Returning customers (signed in, at least one paid order) skip rule and guest checks, never blocks, list checks or attack mode with “also customers”.
A continuation (the first confirmation request of an order the same session placed through the gate in the last 15 minutes, claimed atomically with followups = 0) is checked against lists and blocks only. Every other request carrying an order_id adds the order key (O); at the end of the request (shutdown function) an order still in a failed status counts one more failed payment for the current visitor and the order (core does not call the status hooks for Failed -> Failed); AJAX requests count only when the payment script assigned an error. Automatic blocks cover what the rule counted (IP rules: IP; session/device rules: session + device; e-mail, card and order rules: that key).
Monitor mode computes the same decision, logs it with monitor = Y, writes no block and refuses nothing.
The built-in check
Section titled “The built-in check”kv_card_testing_shield.ticket (POST, AJAX) returns base64url(JSON {v, t, n, d, s}) . "." . base64url(HMAC-SHA256), where s binds the ticket to the session and d is the difficulty (14 / 16 / 18 leading zero bits). The browser finds a base36 nonce so that SHA-256(ticket ":" nonce) starts with d zero bits (synchronous SHA-256 in func.js, in slices so the page stays responsive) and posts both to kv_card_testing_shield.verify. The server checks the signature (key: random install secret bound to the store’s crypt_key), age (1 s to 10 min), session, the work and single use (kv_cts_used keeps every used ticket id until the ticket would have expired). With Captcha Pro as provider the proof of work is required as well, so a Captcha Pro outage or fallback never grants a pass on its own. tests/parity.mjs checks the browser SHA-256 against Node’s crypto.
With Captcha Pro as provider, Captcha Pro’s antibot rule checks the POST to kv_card_testing_shield.verify before the controller runs; and the controller still requires the solved built-in ticket.
Client IP
Section titled “Client IP”ClientIp (generated by the Kavio Labs tooling) never trusts X-Forwarded-For or other visitor headers unless the TCP peer is a trusted proxy (Cloudflare ranges, loopback / private networks, or the merchant’s list). IPv6 addresses count per /64. Country: CF-IPCountry only when the request came from a Cloudflare edge; otherwise the imported range file.
Data model
Section titled “Data model”| Table | Content | Kept on uninstall |
|---|---|---|
kv_cts_hits |
Sliding-window counters: key type (I, S, D, E, C, K, O), keyed hash, kind (A attempt, F failure, L low-amount failure), e-mail and card hash prefixes for distinct counts, time; 48 h | no |
kv_cts_orders |
Order -> group, visitor keys, IP, BIN, total, guest, outcome (A, F, S, X), follow-up counter | yes |
kv_cts_blocks |
Active blocks per key with label (IP, masked e-mail, BIN), reason, source, end | yes |
kv_cts_passes |
Passes: id, session, device, IP key (info), uses left, end | no |
kv_cts_used |
Used ticket ids until the ticket would have expired | no |
kv_cts_lists |
Allow / check / block entries with hits and expiry | yes |
kv_cts_events |
Event log (retention setting) | yes |
kv_cts_geo |
Imported IP ranges (country / ASN) | no (re-import) |
kv_cts_state |
Install secret, rules, attack mode, alarm, import state | yes |
Identifiers are stored as HMAC-SHA256 (32 hex) of the value with the install key; the event log keeps the IP address, the country, the masked e-mail (first letter + domain) and the card BIN only. Full card numbers are never stored.
Full page cache (4.21)
Section titled “Full page cache (4.21)”Nothing is added to cacheable pages (home, categories, products, pages): the box is rendered only in checkout and order templates, which are never cached; the storefront script is static. Storefront GET requests write nothing; tickets and checks are POST only. The device cookie is set by the script on checkout pages only.
Protecting another payment request
Section titled “Protecting another payment request”Add its controller.mode to Protected requests (only POST requests are checked). When the request fails, the add-on learns it from the order status, so nothing else is needed. If a payment add-on retries a card on an existing order without changing its status, only the attempt rules (per IP, per session, e-mails, cards) apply to it.
Endpoints
Section titled “Endpoints”- Storefront:
kv_card_testing_shield.ticket,kv_card_testing_shield.verify(POST, JSON inkv_cts). - Admin:
kv_card_testing_shield.manage | events | export | rules | lists | geo_step(GET),attack | ack_alarm | unblock | block_ip | unblock_ip | update_rules | restore_rules | add_entry | delete_entries | import_entries | geo_start | geo_clear | cleanup(POST). Privileges: view / update store settings. Vendors and storefront-bound administrators are denied.
Range file format
Section titled “Range file format”CSV, one range per line: first IP,last IP,country code[,...] or first IP,last IP,AS number,AS organisation (an organisation with commas may be quoted or not). IPv4 and IPv6; header lines and ZZ rows are skipped; .gz is unpacked first. The format was written from the field list of the DB-IP Lite download pages (first IP, last IP, country code / AS number, AS organisation); their pages show no sample row, so the parser also accepts country files with extra continent columns before the code.
Not in 1.0.0
Section titled “Not in 1.0.0”Per-storefront policies (Ultimate), device fingerprinting beyond a first-party cookie, payment provider APIs (no outgoing requests at all), e-mail or webhook alerts (by design: admin notices only), a scheduled import of range files.
File map
Section titled “File map”| Path | Purpose |
|---|---|
app/addons/kv_card_testing_shield/Tygh/Addons/KvCardTestingShield/ |
Config, State, Visitor, ClientIp, Geo, Lists, Hits, Rules, Blocks, Events, Challenge, Attack, Guard, Outcomes, Maintenance, Storefront, Admin, Retention, License/, Upgrade/ |
controllers/backend/kv_card_testing_shield.php |
Admin pages |
controllers/frontend/kv_card_testing_shield.php |
Ticket and verify |
schemas/ |
Menu, permissions (admin, vendor MV, vendor ULT), setting variants |
var/themes_repository/responsive/templates/addons/kv_card_testing_shield/ |
Box and hooks |
design/backend/templates/addons/kv_card_testing_shield/ |
Admin views, dashboard line, settings overview |
js/addons/kv_card_testing_shield/func.js |
Proof of work, device cookie, button hold, Captcha Pro bridge |