Making WordPress.org

Changeset 8636


Ignore:
Timestamp:
04/12/2019 11:21:15 AM (7 years ago)
Author:
vedjain
Message:

WC Camptix: Throttle ticket purchase request to prevent junk tickets.

This patch adds throttling support to ticket purchase request to 39 per hour. This is not intended to prevent any kind of sophiscated attacks, but is just there so that we don't have to delete lots of failed tickets when a security runs any automated tests on us.

Form_Spam_Prevention provides honeypot feature as well, which we are intentionally not using here because we want don't want to be aggressive in blocking ticket purchase form.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php

    r8530 r8636  
    44use CampTix_Plugin;
    55use WP_Post;
     6use WordCamp\Utilities\Form_Spam_Prevention;
    67
    78defined( 'WPINC' ) or die();
     
    1516add_action( 'wp_print_styles',                               __NAMESPACE__ . '\print_login_message_styles'          );
    1617add_filter( 'camptix_require_login_please_login_message',    __NAMESPACE__ . '\override_please_login_message'       );
     18add_action( 'camptix_checkout_start',                        __NAMESPACE__ . '\check_ip_throttling'                 );
    1719add_action( 'camptix_form_start_errors',                     __NAMESPACE__ . '\add_form_start_error_messages'       );
     20add_filter( 'camptix_form_attendee_info_errors',             __NAMESPACE__ . '\show_throttle_notice'                );
    1821add_action( 'transition_post_status',                        __NAMESPACE__ . '\ticket_sales_opened',          10, 3 );
    1922add_action( 'camptix_payment_result',                        __NAMESPACE__ . '\track_payment_results',        10, 3 );
     
    4346add_filter( 'camptix_stripe_checkout_image_url',             __NAMESPACE__ . '\stripe_default_checkout_image_url'   );
    4447
     48// Prefix for Form_Spam_Prevention class.
     49define( 'WC_CAMPTIX_FSP_PREFIX', 'wc-camptix-fsp-prefix' );
    4550
    4651/**
     
    921926
    922927/**
     928 * Show error message if IP Address has been throttled by `Form_Spam_Prevention`.
     929 * We are not using honeypot feature provided by Form_Spam_Prevention because we do not want to be aggressive with blocking requests in ticket purchase page. We only block when we are extremely sure that its a bad actor, and even if it is a bot, we let it go if its not annoying.
     930 */
     931function show_throttle_notice() {
     932    global $camptix;
     933
     934    $fsp = new Form_Spam_Prevention( [ 'prefix' => WC_CAMPTIX_FSP_PREFIX ] );
     935
     936    if ( $fsp->is_ip_address_throttled() ) {
     937        $camptix->error( __( 'You are purchasing tickets too fast. Your IP address has been throttled for an hour since last ticket purchase.', 'wordcamporg' ) );
     938
     939        // With some payment methods, payment could have been  deducted in the frontend before making a checkout request.
     940        // Therefore its important that we disable payment methods tab if we are going to block the checkout request.
     941        add_filter( 'tix_render_payment_options', '__return_empty_string', 20 );
     942    }
     943
     944}
     945
     946/**
     947 * Checks if IP is throttled. If not then increments the score by 0.1. This does not handle any sophisticated attack, but is just there so that we do not have to delete junk tickets if a security researcher runs a test on site.
     948 *
     949 * Maximum score threshold in Form_Spam_Prevention is 4, so using 0.1 implies an IP address will be able to make 39 purchase request before getting throttled.
     950 */
     951function check_ip_throttling() {
     952    global $camptix;
     953
     954    $fsp = new Form_Spam_Prevention( [ 'prefix' => WC_CAMPTIX_FSP_PREFIX ] );
     955
     956    if ( $fsp->is_ip_address_throttled() ) {
     957        $camptix->error_flag( 'ip_address_throttled' );
     958    } else {
     959        $fsp->add_score_to_ip_address( [ 0.1 ] );
     960    }
     961}
     962
     963/**
    923964 * Modify the list of personal data eraser callbacks.
    924965 *
Note: See TracChangeset for help on using the changeset viewer.