Changeset 8636
- Timestamp:
- 04/12/2019 11:21:15 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php
r8530 r8636 4 4 use CampTix_Plugin; 5 5 use WP_Post; 6 use WordCamp\Utilities\Form_Spam_Prevention; 6 7 7 8 defined( 'WPINC' ) or die(); … … 15 16 add_action( 'wp_print_styles', __NAMESPACE__ . '\print_login_message_styles' ); 16 17 add_filter( 'camptix_require_login_please_login_message', __NAMESPACE__ . '\override_please_login_message' ); 18 add_action( 'camptix_checkout_start', __NAMESPACE__ . '\check_ip_throttling' ); 17 19 add_action( 'camptix_form_start_errors', __NAMESPACE__ . '\add_form_start_error_messages' ); 20 add_filter( 'camptix_form_attendee_info_errors', __NAMESPACE__ . '\show_throttle_notice' ); 18 21 add_action( 'transition_post_status', __NAMESPACE__ . '\ticket_sales_opened', 10, 3 ); 19 22 add_action( 'camptix_payment_result', __NAMESPACE__ . '\track_payment_results', 10, 3 ); … … 43 46 add_filter( 'camptix_stripe_checkout_image_url', __NAMESPACE__ . '\stripe_default_checkout_image_url' ); 44 47 48 // Prefix for Form_Spam_Prevention class. 49 define( 'WC_CAMPTIX_FSP_PREFIX', 'wc-camptix-fsp-prefix' ); 45 50 46 51 /** … … 921 926 922 927 /** 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 */ 931 function 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 */ 951 function 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 /** 923 964 * Modify the list of personal data eraser callbacks. 924 965 *
Note: See TracChangeset
for help on using the changeset viewer.