A WordPress AJAX or admin-post handler does not check a nonce
What it finds
A WordPress AJAX or admin-post handler does not check a nonce
<?phpadd_action('wp_ajax_save_settings', 'save_settings');tx0 reports: the handler save_settings never checks a nonceadd_action('wp_ajax_load_settings', 'load_settings');add_action('wp_ajax_nopriv_ping', 'ping'); function save_settings(){ if (!current_user_can('manage_options')) { wp_die(); } update_option('color', sanitize_text_field($_POST['color']));} function load_settings(){ check_ajax_referer('settings'); wp_send_json(get_option('color'));} function ping(){ wp_send_json('pong');} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/php:ajax-handler-without-nonce" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/php:ajax-handler-without-nonce] reason="..."tx0 explain tx0/php:ajax-handler-without-nonce shows the same in the terminal. Found a false positive? Report it.