CartThrob 10 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Form Authority and Protected Keys

CartThrob 10 signs every form it renders. This page explains what that means for add-on and template developers: which posted values CartThrob will never read from the request body, how a form earns the right to set them, and what to do when your tag needs to take part.

If you only write templates, the practical rules are on Upgrading to CartThrob 10. This page is the mechanism underneath.

What gets signed

When a CartThrob form tag renders (add_to_cart_form, multi_add_to_cart_form, update_cart_form, checkout_form, update_live_rates_form, add_vault_form, update_vault_form), Form_builder collects the tag’s protected parameters into a set of claims, binds them to the form’s context, and writes one hidden field, CTAUTH, containing an encrypted and HMAC-signed token. The token carries:

  • the CartThrob version of the token format and the EE site ID;
  • the action the form posts to (add_to_cart, checkout, and so on) and the form’s FRM id;
  • the context the form was rendered for: the entry_id for a catalog add-to-cart form, the authorized entry ids for a multi-add form, a fingerprint of the cart for update, checkout and live-rates forms, the member, gateway and Vault for Vault forms, plus sub_id, order_id, member_id and gateway_method for checkout;
  • the claims: every protected parameter the template fixed on the tag, such as price="12", subscription="yes", no_tax="yes", permissions="...".

The signing key is derived from the site’s encryption_key. A token is valid only for the action, form and site it was issued for.

Protected keys

The following keys are protected: the signed form decides whether each value is fixed or may come from an allowed customer choice. A separately encrypted or hand-written field grants no authority by itself. The list is FormAuthorityService::SENSITIVE_KEYS:

Key Set by Meaning
AUP, AUS, AUW allow_user_price, allow_user_shipping, allow_user_weight the customer may post a price, shipping or weight
OTF on_the_fly item has no product entry
NTX, NSH no_tax, no_shipping (tax_exempt, shipping_exempt) exemptions
PR, SHP, WGT, TX price, shipping, weight, tax fixed amounts
CLS, PER, MET, EXP, LIC, UPL class, permissions, meta:*, expiration_date, license_number, upload_directory item attributes
SUB, SM, SR, ST, SI, SIU, SO, SP, PI, STIL, STIU, SSD, SED the subscription_* parameters and subscription_plan_id subscription terms
GI, FPR, CJS, vault_id gateway and Vault context payment routing
VLT force_vault fixed save-card request, or a signed yes/no choice on checkout_form
subscription_plan_id, inventory_reduce plan forms, inventory:reduce variables plan identity, stock adjustments
RLS, NRQ, REQ validation rules, required server-side validation policy

Before 10, these travelled as EE-encrypted hidden fields and were decrypted on submit. Since 10.0.0, an encrypted value in the request body carries no authority. Request::has($key) and Request::decode($key) use the token’s fixed claim or a posted value accepted by its signed choice set. If the form opens neither, has() is false and decode() returns the default. Non-protected keys (quantity, item_options, customer fields, your own inputs) are read from the request as always.

A protected claim with a financial effect (price, shipping, weight, exemptions, subscription terms, permissions) also requires product binding: a catalog form must carry entry_id on the tag so the claim is bound to that entry. Since 10.0.1 a form with no product entry at all, such as a Subscriptions plan form or an on_the_fly form, is accepted when the posted entry_id is absent, blank or 0; posting a real entry against such a form is rejected.

What this means for your code

Extensions on the cartthrob_*_start hooks cannot lift it. AddToCartAction, CheckoutAction and the live-rates action re-validate the authority after the start hook runs, so an extension that rewrites $_POST['entry_id'] or injects a protected key changes nothing. Extensions can still change ordinary inputs.

A tag that renders a protected input needs the form to know about it. A <select name="SI"> or an encrypted hidden PR emitted by your tag is ignored on submit, because the enclosing form signed its claims before your tag rendered. Two ways in, both new in 10.0.1:

  1. Discovery. Implement CartThrob\Forms\DeclaresFormChoices on your tag class:

    public static function formChoices(array $params): array
    {
        // Return the protected key and the values a customer may choose.
        return ['SIU' => ['days', 'weeks', 'months', 'years']];
    }
    

    When a form renders, Form_builder scans the form’s own body for nested tags, calls formChoices() on any that implement the interface, and signs the returned values as a choice set. On submit, decode('SIU') returns the posted value only if it is exactly one of the signed strings, posted plain or EE-encrypted; any other value for a declared choice produces a validation error. Undeclared protected fields remain ignored. The scan sees tags inside the form pair in the same template; it does not see tags inside an {embed} or option lists built by output-stage PHP. The scan can be turned off site-wide with the cartthrob_form_choice_discovery configuration override; the options: fallback keeps working.

  2. The options: fallback. A template author can declare the same list on the form tag, options:subscription_interval_units="days|weeks|months|years", which signs the set without any tag support. An explicit form-tag list replaces the discovered selector list for that key.

A fixed parameter on the form tag always wins over a choice set for the same key. Money keys (PR, SHP, WGT, TX and the allow_user_* flags), exemptions, on_the_fly and PI can never be offered as choices; money has the allow_user_* mechanism and plan identity stays fixed.

Saving the card. save_vault_checkbox and save_vault_field_value declare a VLT choice inside checkout_form. A plain field needs options:force_vault="yes|no"; this opens both sides of the full bool_string() vocabulary (y/n, yes/no, 1/0, on/off, true/false, t/f). Save-card matching ignores case, including after decryption; other list choices still match exactly. A fixed force_vault= wins. Other forms do not open VLT, and range/any rules do not apply to this list-only choice.

Custom actions. If your add-on renders its own form through Form_builder with classname Cartthrob and one of the methods above, the token is issued for you. If you process a form with your own action, validate the token yourself:

$authority = ee('cartthrob:FormAuthorityService')->validate(
    ee()->input->post(\CartThrob\Services\FormAuthorityService::FIELD),
    'add_to_cart',               // the action the form was issued for
    (string) ee()->input->post('FRM')
);
if (!$authority) {
    // reject
}
$price = $authority->claim('PR');           // null when the template did not fix it
$bound = $authority->context('entry_id');   // '' when unbound

Never decrypt a protected key from the request and act on it. Never copy a token from one form to another; the action, form id and context will not match.