Skip to content

Developer notes

Classes in app/addons/kv_checkout_script_guard/Tygh/Addons/KvCheckoutScriptGuard/:

Class Role
Fingerprint Inventory keys, inline code fingerprints, SRI values, script extraction from HTML
Csp Policy builder (script-src only, never a nonce), CSP report parser (application/csp-report and application/reports+json), security header normalisation and diff
Catalogue Well-known script hosts with a suggested justification and “dynamic” flag
Config Settings per storefront, scope, signed page and check tokens (HMAC of the store’s crypt key)
Inventory Sources, daily counters, approvals, change log, allow-list
Alerts Alert log with de-duplication, admin notice, e-mail, webhook
Checker Scheduled check (lock, throw-away cart, headers, scripts, content hashes, baseline diff)
Storefront Headers and monitor on scoped pages, report endpoint, test cart
Evidence Evidence report data, SHA-256 fingerprint, CSV
RateLimit, ClientIp Report endpoint limit (30 per minute per network, keyed hash)
  • dispatch_before_display (storefront): on a page in scope, when the add-on is on: Content-Security-Policy-Report-Only (or Content-Security-Policy when enforced, sent as an additional header so core’s frame-ancestors header stays) with a report-uri (no report-to: Chromium ignores report-uri once report-to is present and batches Reporting API uploads for up to a minute; the endpoint still accepts Reporting API batches), and the view variable $kv_csg for the template hook index:head_scripts (post), which prints the monitor with data-no-defer, integrity and crossorigin.
  • before_dispatch / complete (+ a shutdown function): the throw-away cart of the scheduled check, only with a valid kv_csg_probe token (5 minutes, bound to the storefront) and never for a signed-in customer. While it runs, the constant KV_CSG_PROBE is defined, so other add-ons can skip tracking.
  • dispatch_before_display (admin): notice about open alerts.

Every storefront step is wrapped: on an error nothing is added to the page and the message goes to var/kv_checkout_script_guard/alerts.log. define('KV_CSG_NO_ENFORCE', true); in local_conf.php turns every enforced policy back into report-only at once.

POST index.php?dispatch=kv_checkout_script_guard.report&t=<page token>; GET answers 405. The page token (base64url payload page~company~expiry + HMAC) is valid for six hours and only for a page in scope. Body limit 32 KB, 100 items, 30 requests per minute per client network (ClientIp::rateKey(), IPv4 /32, IPv6 /64; forwarded headers only from trusted proxies). Answers: 204 accepted, 400 bad body, 403 token, 413 size, 429 rate.

Monitor body (text/plain JSON): {"s": [{"k": "e", "u": "https://host/path.js"}, {"k": "i", "h": "<sha256 hex>"}]}.

normalizeInline(): string literal contents ('..', "..", template literals) become empty, numbers become 0, white space collapses; SHA-256 of the UTF-8 result. guard.js uses the same steps (WebCrypto, or a small SHA-256 on plain HTTP); tests/parity.mjs compares both.

Table Content Kept on uninstall
?:kv_csg_sources One row per script and storefront: key, type, URL (no query), status, justification, scope, integrity, SRI, content hash, approved hash, pages, sightings, decision yes
?:kv_csg_events Sightings per day, source, page and channel (pruned after 400 days) yes
?:kv_csg_baselines One row per page and storefront: mode, dry run start, baseline headers and scripts, last check yes
?:kv_csg_alerts Alerts with diff, count, status yes
?:kv_csg_audit Change log (decisions, checks, modes, alerts, reports) yes
?:kv_csg_rate Rate limit buckets (deleted after one hour) no

Sent from cron (Alerts::flush()), never from a storefront request: alerts are queued with notified = N, and per storefront at most one digest (one e-mail, one webhook call) leaves per 15 minutes (Alerts::DIGEST_INTERVAL; last time in ?:storage_data key kv_csg_digest_<company>). The call has a 3 s connect and 5 s total timeout. POST to the HTTPS URL from the settings, Content-Type: application/json, header X-Kv-Signature: sha256=<HMAC-SHA256 of the body> (key: the add-on secret, Config::secret()), body (up to 50 alerts, count is the full number):

{"event": "checkout_script_guard.digest", "company_id": 0, "count": 1, "alerts": [{"alert_id": 12, "kind": "new_script", "page": "checkout.checkout", "title": "New script on checkout.checkout: https://example.test/a.js", "created_at": 1764100000}], "admin_url": "https://store.test/admin.php?dispatch=kv_checkout_script_guard.manage&selected_section=alerts"}

E-mails and webhooks are not sent from development hosts (localhost, *.test, *.local, private addresses); they are written to the log instead (var/kv_checkout_script_guard/alerts.log, rotated to alerts.log.1 at 1 MB).

Catalogue::match() parses the URL strictly: http(s) only, no user info, default port only, no trailing dot, no backslash, control character or encoded / . in the address; the host must be EXACTLY the catalogue host (never a prefix or a suffix), and a catalogue path matches on a segment boundary (/recaptcha and /recaptcha/api.js, not /recaptchaX/a.js). Only a recognised host gets a suggested reason and a wider “Policy allows” default (H for a provider host, P for a catalogue path such as reCAPTCHA); everything else is F (this file). Inventory::resolveScope() refuses H for public CDN hosts (Catalogue::publicCdnHosts()), also when the allow list is built.

Report quotas (Inventory::QUOTA_BROWSER 300, QUOTA_CSP 100 per storefront, counted on ?:kv_csg_sources.first_channel) apply to the public report endpoint only. The scheduled check (first_channel = check) has no quota and always alerts (Checker::checkPage() also raises new_script for scripts that are new in the diff). When a quota is full, once-seen pending entries older than one hour are evicted (Inventory::evict()), otherwise the report is dropped and the flood alert counts up. Visitor reports open at most REPORT_ALERT_CAP (40) “new script” alerts per storefront.

The inline fingerprint removes string contents on purpose; a changed URL inside an approved inline script is not detected (see Usage). Eval violations from CSP reports are only counted (Config::noteEval()), never stored as sources.

php admin.php --dispatch=kv_checkout_script_guard.cron [--force=1], or over HTTP with the store cron password. A lock (lock.factory, 15 minutes) prevents parallel runs; a second run prints busy.

Checkout Script Guard helps you collect the evidence these requirements ask for. It does not make a store compliant on its own, and it does not tell you which SAQ applies to you; ask your acquirer or payment brands.

  • PCI DSS requirement 6.4.3 (payment page scripts: each script authorised, integrity assured, an inventory with a written justification) and 11.6.1 (change- and tamper-detection for the HTTP headers and the payment page as received by the browser, evaluated at least every seven days or at the frequency set by your targeted risk analysis). Published by the PCI Security Standards Council, PCI DSS v4.0 / v4.0.1 and the SAQ A-EP; SAQ A (January 2025 revision) and FAQ 1588 describe how merchants with an embedded payment form can meet the script eligibility criterion: https://www.pcisecuritystandards.org/faq/articles/Frequently_Asked_Question/how-does-an-e-commerce-merchant-meet-the-saq-a-eligibility-criteria-for-scripts/ . The add-on’s default check interval is 7 days; you can shorten it.
  • Content Security Policy Level 3, https://www.w3.org/TR/CSP3/ : the policy only uses script-src, is sent as Content-Security-Policy-Report-Only first and as Content-Security-Policy only after the dry run. No nonce is added, because a nonce or hash makes browsers ignore 'unsafe-inline', and CS-Cart pages use inline scripts.
  • Violation reports use the legacy report-uri endpoint (application/csp-report). The W3C Reporting API (https://www.w3.org/TR/reporting-1/, report-to / Reporting-Endpoints) is understood by the endpoint (application/reports+json) but not advertised, because browsers that support report-to ignore report-uri and batch reports.
  • Subresource Integrity, https://www.w3.org/TR/SRI/ : the add-on’s own script tag carries integrity="sha384-..." and crossorigin="anonymous"; inventory entries store the SHA-384 value of each same-origin script.