Security for E-Commerce Sites
WordPress E-Commerce with WooCommerce
Chapter 7 · Security for E-Commerce Sites
WordPress Intermediate/Advanced 8 taught four mechanisms — capability checks, nonces, output escaping, and $wpdb->prepare() — as WordPress's own concrete implementations of general security principles this site already covered in depth. Nothing in this chapter is a new vulnerability class. What's new is the stakes: applied to a checkout page or an account form, the same four mechanisms stand between an attacker and real money, real payment metadata, and real customer PII — not a defaced blog post.
HTTPS: Non-Negotiable for a Store
HTTPS/TLS Fundamentals already covered why encryption in transit matters generally. For a store, it stops being a best practice and becomes a hard requirement: Chapter 5's own tokenized payment fields (Stripe Elements, PayPal) require a secure context to function at all — modern browsers block or restrict the APIs these gateways depend on over plain HTTP, and PCI-DSS itself requires TLS for any transmission of payment-related data. A store running checkout over HTTP isn't taking a small risk; in practice, its payment gateway simply won't work correctly.
XSS on Reviews & Account Fields
XSS — Cross Site Scripting's general lesson — encode output for its specific context, never trust rendered user input — applies directly to two store-specific surfaces: product reviews (user-submitted text, rendered back to every visitor of that product page) and account fields like a saved shipping address (rendered back to the customer, and often to store staff processing the order).
CSRF on Checkout & Account Actions — Nonces Again
CSRF — Cross-Site Request Forgery's general defense — a token proving a request genuinely originated from the expected page — is exactly what protects "Place order" and account-changing actions. WooCommerce's own checkout form includes a nonce field (commonly named woocommerce-process-checkout-nonce), verified server-side before an order is ever created — the same wp_nonce_field()/wp_verify_nonce() pair WordPress Intermediate/Advanced 8 already covered, doing real work at the single most consequential form on the entire site.
SQL Injection in Custom Order Queries
SQL Injections and Defences's general defense — never concatenate user input into a SQL string — applies directly the moment a store adds any custom feature that queries orders by user-supplied criteria, such as an "order lookup by email" tool.
wc_orders. Custom code querying either the older wp_posts-based order storage or the newer HPOS tables needs $wpdb->prepare() exactly the same way — the underlying storage location changed, but the injection risk from unsanitized concatenation didn't.
Broken Access Control: Viewing Another Customer's Order
A customer's own My Account → Orders page correctly shows only their own orders, because WooCommerce's own code checks that the logged-in user actually owns each order before displaying it. Custom code that adds an order-lookup feature — say, a URL like /order-status/?order_id=482 — can easily reintroduce exactly the gap WordPress Intermediate/Advanced 8's own capability-check material warned about, if it fetches order #482 and displays it without confirming the currently logged-in user actually owns order #482.
A Compromised Checkout Page Is a Fraud Vector, Not Just a Defacement
The Synthesis: Same Vulnerabilities, Store-Specific Stakes
Hands-On Exercises
A developer builds an order-status lookup page at /order-status/?order_id=N, and fetches/displays whatever order matches that ID with no further check. Explain the exploit this leaves open, and the specific fix, referencing this chapter's own comparison to WordPress Intermediate/Advanced 8.
📄 View solutionA store owner argues that since they use Stripe's tokenized checkout fields, a vulnerable plugin on their site can't put customer card data at risk. Explain why this chapter says that reasoning is incomplete.
📄 View solutionExplain why this chapter says none of the vulnerability classes it covers are new to e-commerce specifically, while also arguing this chapter is still necessary and not just a repeat of WordPress Intermediate/Advanced 8.
📄 View solutionChapter 7 Quick Reference
- HTTPS is a hard requirement for a store — Chapter 5's own payment gateways need a secure context to function at all
- XSS — escape reviews and saved account fields on output, especially since store-staff sessions often carry real order-management privileges
- CSRF — WooCommerce's own checkout form already uses a nonce; custom AJAX-based checkout additions must not bypass it
- SQL injection — any custom order query, against either legacy post-based storage or HPOS, needs
$wpdb->prepare() - Broken access control — any custom order-lookup feature must verify the requesting user actually owns that order, not just avoid linking to it
- Tokenization protects the server, not the browser — a compromised plugin can still enable client-side, "Magecart-style" card skimming even with Stripe/PayPal tokenization in place
- None of these are new vulnerability classes — what changes on a store is the real-world value of a successful exploit: fraud, PII breach, and direct revenue loss
- Next chapter: Extending WooCommerce: Hooks & Custom Functionality