@@ -393,7 +393,7 @@ public function nunil_set_screen(): void {
393
393
if ( ! is_null ( $ current_screen ) ) {
394
394
// Get the active tab from the $_GET param.
395
395
$ default_tab = null ;
396
- $ tab = isset ( $ _GET ['tab ' ] ) ? sanitize_text_field ( wp_unslash ( $ _GET ['tab ' ] ) ) : $ default_tab ;
396
+ $ tab = isset ( $ _GET ['tab ' ] ) ? Utils:: sanitize_text ( $ _GET ['tab ' ] ) : $ default_tab ;
397
397
398
398
$ help_tabs = new \NUNIL \Nunil_Admin_Help_Tabs ( $ current_screen );
399
399
@@ -869,7 +869,7 @@ public function register_base_rule(): void {
869
869
* Sanitize the settings
870
870
*
871
871
* @throws \NUNIL\Nunil_Exception Main option is not an array.
872
- * @param array<string|array<string>> $input Contains the settings.
872
+ * @param array<string|int| array<int| string>> $input Contains the settings.
873
873
* @return array<mixed>
874
874
*/
875
875
public function sanitize_options ( $ input ) {
@@ -1022,7 +1022,12 @@ public function sanitize_options( $input ) {
1022
1022
1023
1023
unset( $ options ['endpoints ' ] );
1024
1024
if ( isset ( $ input ['endpoints ' ] ) && is_array ( $ input ['endpoints ' ] ) ) {
1025
- $ new_input ['endpoints ' ] = array_map ( 'esc_url_raw ' , $ input ['endpoints ' ], $ protocols = array ( array ( 'https ' ) ) );
1025
+ $ new_input ['endpoints ' ] = array_map (
1026
+ function ( $ url ) {
1027
+ return esc_url_raw ( strval ( $ url ), array ( 'https ' ) );
1028
+ },
1029
+ $ input ['endpoints ' ]
1030
+ );
1026
1031
}
1027
1032
1028
1033
if ( isset ( $ input ['max_response_header_size ' ] ) ) {
@@ -1106,6 +1111,12 @@ public function sanitize_base_rule( $input ) {
1106
1111
if ( is_array ( $ options ) ) {
1107
1112
$ new_input = array_merge ( $ options , $ new_input );
1108
1113
}
1114
+ $ new_input = array_map (
1115
+ function ( $ a ) {
1116
+ return Utils::sanitize_text ( $ a , false );
1117
+ },
1118
+ $ new_input
1119
+ );
1109
1120
return $ new_input ;
1110
1121
}
1111
1122
@@ -1784,26 +1795,25 @@ public function print_endpoints(): void {
1784
1795
);
1785
1796
1786
1797
print ( '<ol class="nunil-endpoints-list" id="nunil-endpoints-list"> ' );
1787
- if ( is_array ( $ endpoints ) ) {
1788
- // Add a line for each url.
1789
- foreach ( $ endpoints as $ index => $ endpoint ) {
1790
- printf (
1791
- '<li> ' .
1792
- '<button class="nunil-btn nunil-btn-del-endpoint" ' .
1793
- 'id="no-unsafe-inline[del-endpoint][%d]" name="no-unsafe-inline[del-endpoint][%d]"> ' .
1794
- '<span class="dashicons dashicons-remove"> </span></button> ' .
1795
- '<span class="nunil-endpoint-string txt-active">%s</span> ' .
1796
- '<input class="nunil-hidden-endpoint" type="hidden" id="no-unsafe-inline[endpoints][%d]" ' .
1797
- 'name="no-unsafe-inline[endpoints][%d]" value="%s" /> ' .
1798
- '</li> ' ,
1799
- esc_html ( $ index ),
1800
- esc_html ( $ index ),
1801
- esc_html ( $ endpoint ),
1802
- esc_html ( $ index ),
1803
- esc_html ( $ index ),
1804
- esc_html ( $ endpoint )
1805
- );
1806
- }
1798
+ // Add a line for each url.
1799
+ foreach ( $ endpoints as $ index => $ endpoint ) {
1800
+ $ endp_txt = strval ( Utils::cast_strval ( $ endpoint ) );
1801
+ printf (
1802
+ '<li> ' .
1803
+ '<button class="nunil-btn nunil-btn-del-endpoint" ' .
1804
+ 'id="no-unsafe-inline[del-endpoint][%d]" name="no-unsafe-inline[del-endpoint][%d]"> ' .
1805
+ '<span class="dashicons dashicons-remove"> </span></button> ' .
1806
+ '<span class="nunil-endpoint-string txt-active">%s</span> ' .
1807
+ '<input class="nunil-hidden-endpoint" type="hidden" id="no-unsafe-inline[endpoints][%d]" ' .
1808
+ 'name="no-unsafe-inline[endpoints][%d]" value="%s" /> ' .
1809
+ '</li> ' ,
1810
+ esc_html ( $ index ),
1811
+ esc_html ( $ index ),
1812
+ esc_html ( $ endp_txt ),
1813
+ esc_html ( $ index ),
1814
+ esc_html ( $ index ),
1815
+ esc_html ( $ endp_txt )
1816
+ );
1807
1817
}
1808
1818
print ( '</ol> ' );
1809
1819
}
@@ -1990,7 +2000,7 @@ public function nunil_manage_options(): void {
1990
2000
1991
2001
// Get the active tab from the $_GET param.
1992
2002
$ default_tab = null ;
1993
- $ tab = isset ( $ _GET ['tab ' ] ) ? sanitize_text_field ( wp_unslash ( $ _GET ['tab ' ] ) ) : $ default_tab ;
2003
+ $ tab = isset ( $ _GET ['tab ' ] ) ? Utils:: sanitize_text ( $ _GET ['tab ' ], false ) : $ default_tab ;
1994
2004
1995
2005
?>
1996
2006
<div class="wrap">
@@ -2093,7 +2103,7 @@ public function nunil_manage_options(): void {
2093
2103
* @return mixed
2094
2104
*/
2095
2105
public function save_screen_options ( $ status , $ option , $ value ) {
2096
- $ this_page = isset ( $ _REQUEST ['page ' ] ) ? sanitize_text_field ( wp_unslash ( $ _REQUEST ['page ' ] ) ) : '' ;
2106
+ $ this_page = isset ( $ _REQUEST ['page ' ] ) ? Utils:: sanitize_text ( $ _REQUEST ['page ' ], false ) : '' ;
2097
2107
switch ( $ this_page ) {
2098
2108
case 'no-unsafe-inline ' :
2099
2109
return $ value ;
@@ -2191,7 +2201,7 @@ public function show_admin_notice(): void {
2191
2201
2192
2202
if ( $ notice && is_array ( $ notice ) ) {
2193
2203
$ type = $ notice ['type ' ];
2194
- $ message = $ notice ['message ' ];
2204
+ $ message = Utils:: sanitize_text ( $ notice ['message ' ], false ) ;
2195
2205
2196
2206
$ allowed_html_in_notice = array (
2197
2207
'br ' => array (),
@@ -2222,7 +2232,7 @@ public function show_admin_notice(): void {
2222
2232
public function trigger_clustering (): void {
2223
2233
if ( ! (
2224
2234
isset ( $ _REQUEST ['nonce ' ] )
2225
- && wp_verify_nonce ( sanitize_key ( $ _REQUEST ['nonce ' ] ), 'nunil_trigger_clustering_nonce ' )
2235
+ && wp_verify_nonce ( sanitize_key ( strval ( Utils:: cast_strval ( $ _REQUEST ['nonce ' ] ) ) ), 'nunil_trigger_clustering_nonce ' )
2226
2236
) ) {
2227
2237
exit ( esc_html__ ( 'Nope! Security check failed! ' , 'no-unsafe-inline ' ) );
2228
2238
}
@@ -2231,10 +2241,10 @@ public function trigger_clustering(): void {
2231
2241
2232
2242
$ result = $ obj ->cluster_by_dbscan ();
2233
2243
2234
- if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && strtolower ( sanitize_text_field ( wp_unslash ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) ) ) === 'xmlhttprequest ' ) {
2244
+ if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && Utils:: sanitize_text ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) === 'xmlhttprequest ' ) {
2235
2245
echo wp_json_encode ( $ result );
2236
2246
} elseif ( isset ( $ _SERVER ['HTTP_REFERER ' ] ) ) {
2237
- header ( 'Location: ' . esc_url_raw ( wp_unslash ( $ _SERVER ['HTTP_REFERER ' ] ) ) );
2247
+ header ( 'Location: ' . esc_url_raw ( wp_unslash ( strval ( Utils:: cast_strval ( $ _SERVER ['HTTP_REFERER ' ] ) ) ) ) );
2238
2248
}
2239
2249
2240
2250
wp_die ();
@@ -2249,7 +2259,7 @@ public function trigger_clustering(): void {
2249
2259
public function clean_database (): void {
2250
2260
if ( ! (
2251
2261
isset ( $ _REQUEST ['nonce ' ] )
2252
- && wp_verify_nonce ( sanitize_key ( $ _REQUEST ['nonce ' ] ), 'nunil_trigger_clean_database ' )
2262
+ && wp_verify_nonce ( sanitize_key ( strval ( Utils:: cast_strval ( $ _REQUEST ['nonce ' ] ) ) ), 'nunil_trigger_clean_database ' )
2253
2263
) ) {
2254
2264
exit ( esc_html__ ( 'Nope! Security check failed! ' , 'no-unsafe-inline ' ) );
2255
2265
}
@@ -2282,10 +2292,10 @@ public function clean_database(): void {
2282
2292
'report ' => $ result_string ,
2283
2293
);
2284
2294
2285
- if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && strtolower ( sanitize_text_field ( wp_unslash ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) ) ) === 'xmlhttprequest ' ) {
2295
+ if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && Utils:: sanitize_text ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) === 'xmlhttprequest ' ) {
2286
2296
echo wp_json_encode ( $ result );
2287
2297
} elseif ( isset ( $ _SERVER ['HTTP_REFERER ' ] ) ) {
2288
- header ( 'Location: ' . esc_url_raw ( wp_unslash ( $ _SERVER ['HTTP_REFERER ' ] ) ) );
2298
+ header ( 'Location: ' . esc_url_raw ( wp_unslash ( strval ( Utils:: cast_strval ( $ _SERVER ['HTTP_REFERER ' ] ) ) ) ) );
2289
2299
}
2290
2300
2291
2301
wp_die ();
@@ -2300,7 +2310,7 @@ public function clean_database(): void {
2300
2310
public function prune_database (): void {
2301
2311
if ( ! (
2302
2312
isset ( $ _REQUEST ['nonce ' ] )
2303
- && wp_verify_nonce ( sanitize_key ( $ _REQUEST ['nonce ' ] ), 'nunil_trigger_prune_database ' )
2313
+ && wp_verify_nonce ( sanitize_key ( strval ( Utils:: cast_strval ( $ _REQUEST ['nonce ' ] ) ) ), 'nunil_trigger_prune_database ' )
2304
2314
) ) {
2305
2315
exit ( esc_html__ ( 'Nope! Security check failed! ' , 'no-unsafe-inline ' ) );
2306
2316
}
@@ -2321,10 +2331,10 @@ public function prune_database(): void {
2321
2331
'report ' => $ result_string ,
2322
2332
);
2323
2333
2324
- if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && strtolower ( sanitize_text_field ( wp_unslash ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) ) ) === 'xmlhttprequest ' ) {
2334
+ if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && Utils:: sanitize_text ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) === 'xmlhttprequest ' ) {
2325
2335
echo wp_json_encode ( $ result );
2326
2336
} elseif ( isset ( $ _SERVER ['HTTP_REFERER ' ] ) ) {
2327
- header ( 'Location: ' . esc_url_raw ( wp_unslash ( $ _SERVER ['HTTP_REFERER ' ] ) ) );
2337
+ header ( 'Location: ' . esc_url_raw ( wp_unslash ( strval ( Utils:: cast_strval ( $ _SERVER ['HTTP_REFERER ' ] ) ) ) ) );
2328
2338
}
2329
2339
2330
2340
wp_die ();
@@ -2345,10 +2355,10 @@ public function update_summary_tables(): void {
2345
2355
$ result ['inline ' ] = DB ::get_database_summary_data ( 'inline_scripts ' );
2346
2356
$ result ['events ' ] = DB ::get_database_summary_data ( 'event_handlers ' );
2347
2357
2348
- if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && strtolower ( sanitize_text_field ( wp_unslash ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) ) ) === 'xmlhttprequest ' ) {
2358
+ if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && Utils:: sanitize_text ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) === 'xmlhttprequest ' ) {
2349
2359
echo wp_json_encode ( $ result );
2350
2360
} elseif ( isset ( $ _SERVER ['HTTP_REFERER ' ] ) ) {
2351
- header ( 'Location: ' . esc_url_raw ( wp_unslash ( $ _SERVER ['HTTP_REFERER ' ] ) ) );
2361
+ header ( 'Location: ' . esc_url_raw ( wp_unslash ( strval ( Utils:: cast_strval ( $ _SERVER ['HTTP_REFERER ' ] ) ) ) ) );
2352
2362
}
2353
2363
2354
2364
wp_die ();
@@ -2526,7 +2536,7 @@ public static function output_summary_eventhandlers_table() {
2526
2536
public function test_classifier (): void {
2527
2537
if ( ! (
2528
2538
isset ( $ _REQUEST ['nonce ' ] )
2529
- && wp_verify_nonce ( sanitize_key ( $ _REQUEST ['nonce ' ] ), 'nunil_test_classifier_nonce ' )
2539
+ && wp_verify_nonce ( sanitize_key ( strval ( Utils:: cast_strval ( $ _REQUEST ['nonce ' ] ) ) ), 'nunil_test_classifier_nonce ' )
2530
2540
) ) {
2531
2541
exit ( esc_html__ ( 'Nope! Security check failed! ' , 'no-unsafe-inline ' ) );
2532
2542
}
@@ -2537,10 +2547,10 @@ public function test_classifier(): void {
2537
2547
'type ' => 'success ' ,
2538
2548
'report ' => $ result_string ,
2539
2549
);
2540
- if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && strtolower ( sanitize_text_field ( wp_unslash ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) ) ) === 'xmlhttprequest ' ) {
2550
+ if ( ! empty ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) && Utils:: sanitize_text ( $ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ) === 'xmlhttprequest ' ) {
2541
2551
echo wp_json_encode ( $ result );
2542
2552
} elseif ( isset ( $ _SERVER ['HTTP_REFERER ' ] ) ) {
2543
- header ( 'Location: ' . esc_url_raw ( wp_unslash ( $ _SERVER ['HTTP_REFERER ' ] ) ) );
2553
+ header ( 'Location: ' . esc_url_raw ( wp_unslash ( strval ( Utils:: cast_strval ( $ _SERVER ['HTTP_REFERER ' ] ) ) ) ) );
2544
2554
}
2545
2555
2546
2556
wp_die ();
0 commit comments