On this page
A campaign link should take a shopper to a product or offer—not add an item to their cart merely because the URL was requested. Before a sale, check add-to-cart link GET request security across email, ads, social previews, and redirects. This guide explains the risk and provides a practical test checklist.
This article could not verify the text of RFC 9110 or your ecommerce platform’s documentation in this environment. Check both when implementing or auditing platform-specific behavior.
Key Takeaways
- HTTP defines GET as a safe method: the client does not request a state-changing action by using it.
- Crawlers, link previews, prefetchers, and security scanners can request campaign URLs without a shopper choosing to add anything.
- Make campaign links open a read-only page, then require a deliberate action that sends a POST request to modify the cart.
- Use CSRF protections appropriate to the cart’s authentication and session model. POST alone is not a CSRF defense.
- Test the entire redirect chain and the resulting cart state in an isolated environment before launching a campaign.
Why a GET request must not add to a cart
The safe-method distinction in RFC 9110 describes what the client requests: with GET, the client asks to retrieve a representation, not to change application state. A server may still have incidental effects, such as writing access logs. Adding a product to a cart, however, is an application action with consequences for the shopper and should not be triggered by GET.
That distinction matters because automated systems routinely visit links. An email security scanner might follow a campaign link before delivery; a messaging application might fetch it to build a preview; or a browser might prefetch a destination. None of these requests necessarily represents a shopper’s decision to add an item.
A state-changing GET can produce unexpected cart contents, confusing promotions, and abandoned carts. The same principle applies even if the cart is associated with a guest session rather than a signed-in account.
Advertisement
Compare a product link with a cart action
The following request shapes are illustrative; they are not requests to a running store. shop.example represents an isolated test store, and sku-123 is a fictional product.
Read-only campaign destination:
GET /products/sku-123 HTTP/1.1
Host: shop.example
This request may display the product and an Add to cart button. It should not add the product simply because the page was fetched. A campaign URL can carry attribution parameters, but those parameters should not make the page visit mutate the cart.
Unsafe design:
GET /cart/add?sku=sku-123 HTTP/1.1
Host: shop.example
If this endpoint adds the item, any authorized session or guest-cart context attached to an automated request could be affected. The URL’s path does not determine safety; what the server actually does does.
Safer action:
POST /cart/items HTTP/1.1
Host: shop.example
Content-Type: application/x-www-form-urlencoded
sku=sku-123&csrf_token=SESSION_BOUND_TOKEN
Here, SESSION_BOUND_TOKEN is a placeholder, not a usable token. A real form or client must obtain and submit a token through the application’s CSRF protection mechanism where that mechanism applies. The server must validate it before changing the cart.
A POST request is appropriate for an action, but it does not by itself prove that a shopper intended it. Automated clients can also send POST requests, and a cross-site request may reach an endpoint if its protections are inadequate.
Build a safer campaign flow
- Link to a read-only landing page. Show the product, offer, price, and a clearly labeled Add to cart button. Do not add items through page-load JavaScript or a redirect.
- Submit the cart change deliberately. Use a form or an application request initiated by the shopper’s button click. Have the server accept the mutation through POST rather than GET.
- Validate on the server. Check the product identifier, quantity, availability, applicable price and promotion, and the shopper’s or guest’s authority to modify that cart. Do not trust price or discount values supplied by the browser.
- Apply CSRF defenses where relevant. When a browser automatically attaches session credentials, protect the state-changing request with your platform’s CSRF mechanism. Validate the token server-side and handle missing or invalid tokens without changing the cart. Consider origin checks and appropriately configured SameSite cookies as additional layers, not universal replacements for CSRF protection.
- Handle success and failure clearly. Show validation errors without silently adding an item. After a successful form submission, a redirect to the cart or product page can reduce accidental resubmission on refresh; it does not make the original action safe or eliminate duplicate requests.
Guest carts also need careful design: a session cookie can identify a guest cart even when no account is signed in. Tailor CSRF and authorization checks to how that cart is identified and modified. CSRF protection does not address every threat, including malicious scripts running in your own site’s origin.
Advertisement
Pre-sale test checklist
Use a staging store or another authorized, isolated environment with test products and dedicated test sessions. Coordinate checks against production with the store owner; do not run state-changing tests on real shoppers’ carts.
- Inventory the links. Collect the exact destinations used in emails, ads, QR codes, affiliates, and social posts, including tracking parameters and short links.
- Follow each redirect chain. Check the initial URL and every destination, including mobile and signed-in variations. A harmless-looking campaign URL can redirect to a state-changing endpoint.
- Start with a known cart state. Record the test cart’s contents, request the campaign URL without clicking Add to cart, and check the cart again. Repeat with an existing session and a fresh guest session.
- Check automated visits. In the authorized environment, simulate a preview or scanner fetching the link. Where your tools execute scripts or follow redirects, include that behavior in the test. Confirm the cart remains unchanged.
- Test the intended action. Click Add to cart and confirm the expected item and quantity appear. Check invalid products, unavailable items, and invalid quantities without relying on browser-side validation alone.
- Test CSRF handling. Where session-based CSRF protection applies, confirm that missing or invalid tokens are rejected without a cart change. Test a cross-site form submission from a second controlled origin as well; browser cookie rules may affect the result, so test the actual supported configurations.
- Check retries and refreshes. Submit the action, refresh the resulting page, and test duplicate submissions. Decide whether multiple additions are expected and whether the application needs duplicate-request handling.
- Fix or disable unsafe legacy links. Replace them with landing-page links, update campaign assets, and retest redirects. Coordinate with platform vendors or extensions if the behavior comes from code you cannot change directly.
Also verify that HEAD requests do not trigger the action: HEAD is a safe method too. Inspect server-side cart state rather than relying only on what a page displays.
Common Mistakes
- Assuming a link is safe because it looks like a product URL. Inspect its final destination and server behavior, including scripts and redirects.
- Changing GET to POST but skipping CSRF validation. Method choice and CSRF defenses address different parts of the problem.
- Relying on a confirmation page that automatically submits. A page-load action can still be triggered by an automated visitor.
- Testing only an empty guest cart. Existing sessions, signed-in users, and different redirect paths can behave differently.
- Treating one passing test as a guarantee. Test actual campaign URLs and supported browser/session configurations, then monitor for unexpected cart activity during the sale.
Conclusion
Make campaign links retrieve pages, not modify carts. Pair a deliberate POST action with server-side validation and appropriate CSRF defenses, then test the complete campaign journey in an authorized environment before traffic arrives.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.