Skip to content

Commit 5776780

Browse files
Fix security and sanitization issues in AJAX handler
- Add proper nonce sanitization with wp_unslash and sanitize_text_field - Add capability check (install_plugins) before allowing dismissal - Fix Neve plan default -1 handling by removing absint() to allow fallback to TPC license tier Agent-Logs-Url: https://github.com/Codeinwp/templates-patterns-collection/sessions/69fed254-eb0a-4138-aca4-b87abd12189f Co-authored-by: harshitarora-in <56164789+harshitarora-in@users.noreply.github.com>
1 parent dff96ae commit 5776780

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

includes/Admin.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,14 @@ public function dismiss_onboarding_promo_notice() {
180180
return;
181181
}
182182

183-
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'dismiss_onboarding_promo_notice' ) ) {
183+
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) );
184+
185+
if ( ! wp_verify_nonce( $nonce, 'dismiss_onboarding_promo_notice' ) ) {
186+
$this->ensure_ajax_response( $response );
187+
return;
188+
}
189+
190+
if ( ! current_user_can( 'install_plugins' ) ) {
184191
$this->ensure_ajax_response( $response );
185192
return;
186193
}
@@ -212,7 +219,7 @@ private function should_show_business_agency_promo_text() {
212219
$license_key = isset( $license_data->key ) ? strtolower( trim( (string) $license_data->key ) ) : '';
213220
$license_tier = License::get_license_tier( 0 );
214221
$raw_tier = isset( $license_data->tier ) ? absint( $license_data->tier ) : 0;
215-
$neve_plan = absint( apply_filters( 'product_neve_license_plan', -1 ) );
222+
$neve_plan = apply_filters( 'product_neve_license_plan', -1 );
216223

217224
if ( $license_key === '' || $license_key === 'free' ) {
218225
return false;
@@ -222,7 +229,8 @@ private function should_show_business_agency_promo_text() {
222229
return false;
223230
}
224231

225-
if ( in_array( $neve_plan, array( 1, 2, 3 ), true ) ) {
232+
// Check Neve plan only if it's a valid category (not -1 default)
233+
if ( -1 !== $neve_plan && in_array( $neve_plan, array( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), true ) ) {
226234
// Normalize Neve plan category to TPC tier using License::NEVE_CATEGORY_MAPPING
227235
$normalized_neve_tier = isset( License::NEVE_CATEGORY_MAPPING[ $neve_plan ] ) ? License::NEVE_CATEGORY_MAPPING[ $neve_plan ] : -1;
228236
return in_array( $normalized_neve_tier, array( 2, 3 ), true );

0 commit comments

Comments
 (0)