Skip to content

Developer notes

Overview · Installation · Configuration · Usage · Custom add-on forms · Developer notes · FAQ

CS-Cart has an antibot service (Tygh::$app['antibot'], Tygh\Web\Antibot) with replaceable drivers, the rule schema security/antibot_rules (which POST requests are checked under which scenario) and the template common/image_verification.tpl that forms include. Captcha Pro uses all three instead of a parallel mechanism:

  • init.php extends the service with Tygh\Addons\KvCaptchaPro\Antibot (a subclass of the core class) and its driver Driver (IAntibotDriver, IErrorableAntibotDriver), only while the add-on is enabled, licensed and Google reCAPTCHA has no keys. The driver cannot be replaced by another add-on afterwards.
  • The subclass reads the form settings of the add-on instead of Image verification: Use for, never writes session flags (every submission is checked, so cached pages stay identical for all guests) and skips signed-in users per the settings.
  • schemas/security/antibot_rules.post.php adds rules core does not ship (auth.recover_password, product_reviews.add, products.product_notifications) and makes every rule end the request on failure: rules that “redirect” without a URL get a real target and terminate_process becomes a denial. Without this, a failed check on auth.login without redirect_url still ran the sign-in controller.
  • The template override common/image_verification.tpl renders the widget while Captcha Pro is active and otherwise the reCAPTCHA template or the unchanged core content.
  • The admin and vendor panel sign-in (not covered by core) is checked in controllers/backend/auth.pre.php.
  • Custom forms (1.1.0, Custom): Forms::catalog() = the built-in forms + the custom forms (stored in kv_cp_custom, registered with fn_kv_captcha_pro_register_form() in the request, added by the hook kv_captcha_pro_get_forms); a custom form never replaces a built-in one. antibot_rules.post.php adds a POST rule (scenario = form id, redirect back on failure) for every registered dispatch that has no rule yet; controller.* patterns are matched against the current request. The core frontend init controller runs these rules like its own, so the check happens before the add-on’s controller.
  1. Allow-list: the visitor IP (IpList::visitorIp(): REMOTE_ADDR; forwarded headers only from loopback, private or configured proxies, X-Forwarded-For walked from the right) against the allowed addresses.
  2. Rate limit: fixed window per form and IP (kv_cp_rate, one atomic INSERT … ON DUPLICATE KEY UPDATE; the IP is stored only as an HMAC).
  3. Honeypot: the hidden field kv_cp_website must be empty.
  4. Ticket: kv_captcha_pro.ticket (storefront) or auth.kv_cp_ticket (panels) returns a signed ticket base64url(JSON {v, f, ts, n, d, c}) . "." . HMAC; no session, no database write. The browser finds a nonce so that SHA-256(ticket ":" nonce) starts with d zero bits (12/15/18, +3 when the visitor used half the attempts). The server checks the signature (key derived from the install secret and crypt_key), form, storefront, age (minimum time, 30-minute lifetime), the work, and single use (kv_cp_used).
  5. Provider: Turnstile (challenges.cloudflare.com/turnstile/v0/siteverify, action must equal the form, idempotency_key) or hCaptcha (api.hcaptcha.com/siteverify, sitekey). In provider mode the ticket carries the time check and, with the built-in fallback, the work; a provider outage or a widget that cannot load (kv_cp_fallback=1) is accepted only with a solved ticket.

Outcomes are counted per day in kv_cp_stats.

The widget markup and the script settings depend only on the add-on settings. Tickets come from a non-cacheable dispatch; checks write only own tables on POST. No ?:storage_data writes.

See Custom add-on forms for the admin pages, fn_kv_captcha_pro_register_form($id, $label, $defaults), fn_kv_captcha_pro_unregister_form($id), the hook kv_captcha_pro_get_forms(&$forms), the template attribute data-kv-captcha and the JavaScript API Tygh.kvCaptchaPro.attach|ready|reset.

  • Storefront script: _.kv_cp.custom lists the custom forms that are not off on the storefront (form, mode check|limit, dispatches, selector); static per storefront, so cached pages stay identical. At ce.commoninit the script adds the widget to forms with data-kv-captcha, forms matching a selector and forms that post to a registered dispatch (dispatch[x.y] button, dispatch field or action URL), before their buttons.
  • Scan (Scanner): tokenizer pass over the active add-ons’ controllers/frontend/*.php (modes compared with $mode inside if (... REQUEST_METHOD ... 'POST' ...) conditions and blocks), regex pass over their storefront templates (POST forms, image_verification.tpl scenarios), the merged antibot rules (scenarios without a Captcha Pro form) and the runtime log. Add-ons without <supplier> (shipped with CS-Cart) are hidden unless asked for. Limits: 400 files and 512 KB per file per add-on.
  • Runtime log (Seen): written only on storefront POST requests while Captcha Pro is active: POSTs to add-on controllers that have no rule and are not custom forms (init.post), and unknown scenarios submitted through the service. Dispatch / scenario, owning add-on and a counter; no visitor data; the newest 300 rows are kept.
Table Content
kv_cp_forms form, company_id, status (A check, L rate limit only, D off), attempts, window_min
kv_cp_rate bucket (HMAC of storefront, form, IP), hits, window_start, expires_at
kv_cp_used SHA-256 of used tickets until they expire
kv_cp_stats day, company_id, form, outcome, hits
kv_cp_custom (1.1.0) form, label, dispatches (one per line), selector, addon, source (A admin, D developer, S scan), default status / attempts / window_min, guests, hash, created_at, updated_at
kv_cp_seen (1.1.0) kind (P POST dispatch, S scenario), name, addon, hits, ignored, first_seen, last_seen

index.php?dispatch=kv_captcha_pro.ticket&form=<form> and admin.php|vendor.php?dispatch=auth.kv_cp_ticket (JSON). Templates: storefront override common/image_verification.tpl, index:scripts / index:styles (.post); admin auth:login_form (.post), index:styles, addons:tabs_content, addons:manage. Controllers: frontend init.post, kv_captcha_pro; backend auth.pre, auth.post, kv_captcha_pro. Schemas: security/antibot_rules, menu/menu, permissions/admin, gdpr/klaro_config (Turnstile/hCaptcha listed as strictly necessary in the GDPR add-on’s consent dialog). PHP hook offered to other add-ons: kv_captcha_pro_get_forms (1.1.0). Admin pages: kv_captcha_pro.manage, kv_captcha_pro.custom, kv_captcha_pro.scan.

To protect a form of your own add-on, the shortest way since 1.1.0 is fn_kv_captcha_pro_register_form() (see Custom add-on forms). The CS-Cart way keeps working: include common/image_verification.tpl with your scenario in the form, add a rule in your schemas/security/antibot_rules.post.php and register the scenario with the settings_variants_image_verification_use_for hook: it then appears on the Spam protection page.

Tygh\Addons\KvCaptchaPro\License\Client (generated) verifies the license. Gate: Config::isActive(), which decides whether Captcha Pro takes over the antibot service, renders the widget, issues tickets and checks the panel sign-in.

Google reCAPTCHA as a provider (use the built-in add-on), Friendly Captcha / ALTCHA widgets, per-country rules, IP reputation lists, custom forms of the admin and vendor panels (custom forms are storefront forms), a scheduled scan (the scan runs when the page is opened).

Path Purpose
app/addons/kv_captcha_pro/addon.xml Settings, tables
init.php, func.php Service extension, install secret, ticket responder, settings status
Tygh/Addons/KvCaptchaPro/Antibot.php, Driver.php Antibot service subclass and driver
Ticket.php, ProviderVerifier.php, RateLimiter.php, IpList.php Checks
Forms.php, Stats.php, Coexist.php, Config.php, Bootstrap.php, Admin.php Form settings, statistics, Google reCAPTCHA, settings, view data, admin page
Custom.php, Dispatch.php, Scanner.php, Seen.php Custom forms, dispatch patterns, unprotected-forms scan, runtime log (1.1.0)
License/, controllers/backend/kv_captcha_pro_license.php License check (generated)
Upgrade/Synchronizer.php Self-healing upgrades (generated)
controllers/, schemas/ Endpoints, admin page, rules, menu, permissions, consent
var/themes_repository/responsive/templates/addons/kv_captcha_pro/ Widget, template override, scripts
design/backend/templates/addons/kv_captcha_pro/ Admin page, settings status, panel sign-in widget
js/addons/kv_captcha_pro/func.js Widget script: SHA-256 proof of work, provider loading, form hold and resend, auto-attach of custom forms, Tygh.kvCaptchaPro API