Harden checkout OTP: prevent dev-tools bypass, timing-safe comparison, phone pinning#9
Open
Harden checkout OTP: prevent dev-tools bypass, timing-safe comparison, phone pinning#9
Conversation
…X verification, block checkout support Co-authored-by: md-riaz <33659227+md-riaz@users.noreply.github.com>
…omment Co-authored-by: md-riaz <33659227+md-riaz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Propose architecture for WooCommerce guest OTP verification
Refactor checkout OTP to theme-agnostic architecture with session-based verification
Feb 26, 2026
…rison, SameSite cookie, wp_send_json Co-authored-by: md-riaz <33659227+md-riaz@users.noreply.github.com>
…ite comment Co-authored-by: md-riaz <33659227+md-riaz@users.noreply.github.com>
Copilot
AI
changed the title
Refactor checkout OTP to theme-agnostic architecture with session-based verification
Harden checkout OTP: prevent dev-tools bypass, timing-safe comparison, phone pinning
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The checkout OTP flow was bypassable via browser dev tools — a user could verify phone A then swap billing phone to B before placing the order. Additionally, several patterns would not pass WordPress plugin review (raw
echo json_encode, timing-vulnerable===on OTP, missingSameSitecookie attribute).Architecture change (from prior commits)
Checkout OTP rendering moved from
woocommerce_review_order_before_submit(broken in block checkout / Elementor / custom themes) to a self-contained panel viawp_footer. Verification uses a session-flag pattern: AJAX verifies OTP → sets transient flag → server-side hooks check flag on checkout submission. Works with classic, block, and any page-builder checkout.Security hardening
verified_phone_matches()compares the billing phone at order submission against the OTP-verified phone stored in the transient. Mismatch → order blocked, session cleared.Timing-safe OTP comparison —
authenticate_otp()useshash_equals()instead of===SameSite cookie — Session cookie now sets
SameSite=Laxvia PHP 7.3+ options array with positional-arg fallbackwp_send_json()— Replaced allecho wp_kses_post(json_encode(...)); wp_die(); exit;insend_otp_for_reg()andsave_and_send_otp_login()withwp_send_json()(proper Content-Type, safe termination). Also fixed null object access when user lookup fails.Nonce coverage (audit)
wc_send_otp(checkout)check_ajax_referer('alpha_sms_checkout_otp', ...)wc_send_otp(WC/WP reg)wp_verify_nonce(..., 'wc_reg_phone_action')/wp_reg_phone_actionalpha_sms_verify_checkout_otpcheck_ajax_referer('alpha_sms_checkout_otp', ...)save_and_send_otp_logincheck_ajax_referer('ajax-login-nonce', ...)validate_guest_checkout_otpvalidate_block_checkout_otpRouteException)✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.