• Resolved Zade

    (@nothin7)


    Greetings, Sensei,

    I love this plugin. Everything except for the admin_menu “icon” (nf_icon.png) which should be a simple graphic SVG to match every other admin menu item. Anyway, unfortunately, two great NF features must be disabled in order to use the WooCommerce mobile app:

    • Firewall Policies > Protect admin-ajax.php against bots
    • Login Protection > Enable bot protection

    I determined this after seeing the following entries in the Firewall Log:

    23/Sep/25 23:00:29 #5444605 MEDIUM – 73.217.86.71 POST /wp-login.php – Blocked access to the login page – [bot detection is enabled] – http://www.sapientstews.com
    23/Sep/25 23:01:28 #7850489 MEDIUM – 73.217.86.71 GET /wp-admin/admin-ajax.php – Blocked access to admin-ajax.php – [bot detection is enabled] – http://www.sapientstews.com

    I don’t have the Jetpack plugin installed (good riddance), so I’m using the “Sign in with store credentials” option when logging in via the Woo mobile app. Upon entering a username and password, I click Continue, at which point the wp-login.php block is triggered. The app then suggests creating an application password as an alternative login method, and attempting this alternative is what triggers the admin-ajax.php block.

    Would you be willing to update your bot protection logic to allow the WooCommerce mobile app?

    In case this helps, here’s how I was able to successfully protect my login page in Cloudflare while allowing mobile app logins:

    (http.request.uri.path contains "/wp-login.php" and not http.user_agent contains "WooCommerce" and not http.user_agent contains "WordPress" and not http.user_agent contains "wc-android" and not http.user_agent contains "wc-ios") or (http.request.uri.path contains "/my-account/") or (http.request.uri.path contains "/checkout/") or (http.request.uri.query contains "wc-ajax=checkout") or (http.request.uri.path contains "/contact" and not http.request.uri.path contains ".")

    Essentially my Cloudflare rule says to show a Managed Challenge if the URI Path contains “/wp-login.php” and the User Agent does not contain “WooCommerce”, “WordPress”, “wc-android”, or “wc-ios”. I’m using the mobile app on iOS, but my rules are also tested and working on Android.

    On the PHP side of things, I had to modify my login_redirect action in order to see the application password alternative:

    // Upon logging in, redirect shop_manager to Inventory, kitchen_staff to Orders, and accountant to Analytics
    function my_login_redirect( $redirect_to, $request, $user ) {
    if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
    return $redirect_to;
    }
    if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
    return $redirect_to;
    }
    $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
    if ( strpos( $user_agent, 'WooCommerce' ) !== false || strpos( $user_agent, 'WordPress' ) !== false
    || strpos( $user_agent, 'wc-android' ) !== false || strpos( $user_agent, 'wc-ios' ) !== false ) {
    return $redirect_to;
    }
    if ( isset( $user->roles ) ) {
    if ( in_array( 'shop_manager', $user->roles ) ) {
    return admin_url( 'admin.php?page=woocommerce-inventory' );
    } else if ( in_array( 'kitchen_staff', $user->roles ) ) {
    return admin_url( 'admin.php?page=wc-orders' );
    } else if ( in_array( 'accountant', $user->roles ) ) {
    return admin_url( 'admin.php?page=wc-admin&path=/analytics/overview' );
    }
    }
    return $redirect_to;
    }
    add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

    FYI, I don’t really use the WordPress or Jetpack mobile apps, but it’s possible those are also blocked.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor bruandet

    (@bruandet)

    Just like Cloudflare, you can write your own NinjaFirewall rules. You need to use the .htninja script.
    Here’s the code that should match what you need for the login page. It can be changed to replace it with (or add) admin-ajax.php:

    <?php
    /**
    * .htninja
    * https://blog.nintechnet.com/ninjafirewall-wp-edition-the-htninja-configuration-file/
    */
    if ( str_ends_with( $_SERVER['SCRIPT_NAME'], 'wp-login.php') ) {
    if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && (
    strpos( $_SERVER['HTTP_USER_AGENT'], 'WooCommerce') !== FALSE ||
    strpos( $_SERVER['HTTP_USER_AGENT'], 'WordPress') !== FALSE ||
    strpos( $_SERVER['HTTP_USER_AGENT'], 'wc-android') !== FALSE ||
    strpos( $_SERVER['HTTP_USER_AGENT'], 'wc-ios') !== FALSE
    ) ) {
    define('NFW_UWL', true);
    return 'ALLOW';
    }
    }

    Thread Starter Zade

    (@nothin7)

    Thank you for the snippet!

    I suppose it’s only the Login Protection > Enable bot protection setting that needs to be addressed, because if that works, the mobile app doesn’t need to try an alternative login method.

    According to your detailed instructions, “This option is enabled by default and I really recommend to keep it enabled.” Given that one of your default options blocks the official Woo app (which could be considered a “native” feature, since Automattic owns Woo), would you consider making this connection seamless, as part of the next NinjaFirewall plugin update?

    Plugin Contributor bruandet

    (@bruandet)

    It’s not possible to “whitelist” the app, because hackers could spoof their user-agent and bypass all NinjaFirewall protections. That’s the reason why we (and Cloudlfare) let you customise your own rules.

    According to your detailed instructions, β€œThis option is enabled by default

    It is enabled only if you enabled the login protection, which isn’t by default πŸ™‚

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

You must be logged in to reply to this topic.