• Resolved David Aguilera

    (@davilera)


    Wordfence produces a Syntax error exception after an AJAX request returns a 404 error.

    Steps to reproduce

    1. Install Wordfence and use default setup.
    2. Create a tiny plugin with the following AJAX callback:

    function davilera_get_post() {
      // Let's assume we looked for the specified post, but we couldn't find it.
      header( 'HTTP/1.1 404 Not Found' );
      wp_send_json( "Post $post_id not found." );
    }
    add_action( 'wp_ajax_davilera_get_post', 'davilera_get_post' );
    

    3. Go to your browser, open the developer tools, and execute the following JavaScript snippet:

    jQuery.ajax({
      url: ajaxurl,
      data: {
        action: 'davilera_get_post',
        postID: 999999
      }
    });
    

    Expected results

    The AJAX request fails (404 error), nothing weird happens.

    Actual results

    The AJAX request fails as expected, but this results in an uncaught JS Syntax error:

    Uncaught Error: Syntax error, unrecognized expression: "Post 999999 not found."

    Discussion

    Looking at the stack trace, the problem occurs in Wordfence’s script admin.ajaxWatcher.js line 17:

    var responseDOM = $(jqXHR.responseText);

    Why do you assume responseText will be a jQuery selector/node? In this example, the AJAX response is a simple string, but it could be anything else.

    Thanks for addressing this issue!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi David,
    Thanks for the detailed report you provided here, I appreciate your time.

    I have passed this one to our dev team (internal reference number: #FB6322), as I’m not sure when the appropriate update to this file will take place, you can uncheck both “Front” and “AdminPanel” checkboxes in (Wordfence > Firewall > Monitor Background Requests for False Positives) to avoid this problem.

    Thanks.

    Thread Starter David Aguilera

    (@davilera)

    I appreciate your help! How can I check the progress on #FB6322? Is there a link I can access?

    I’m afraid this is for internal referencing only on our system and which is not publicly accessible.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘JavaScript Syntax Error in admin.ajaxWatcher.js’ is closed to new replies.