A WordPress AJAX or admin-post handler does not check a nonce

tx0/php:ajax-handler-without-noncerecommendedwarningsecurity/authn-authzdepth fastsecurity, cwe-352

What it finds

A WordPress AJAX or admin-post handler does not check a nonce

Example from the rule's tests
<?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');}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

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.