Plugin Directory

Changeset 3433652


Ignore:
Timestamp:
01/06/2026 01:22:17 PM (3 months ago)
Author:
butterflymedia
Message:

Authenticated REST API requests are now properly excluded from firewall blocking

Location:
wp-guardian/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-guardian/trunk/modules/firewall.php

    r3423816 r3433652  
    3535function wp_guardian_gatekeeper_core() {
    3636    if ( ! defined( 'DOING_CRON' ) || ! DOING_CRON ) {
     37        // Check if this is a REST API request
     38        $is_rest_request = false;
     39        if ( isset( $_SERVER['REQUEST_URI'] ) ) {
     40            $request_uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );
     41            if ( strpos( $request_uri, '/wp-json/' ) !== false ) {
     42                $is_rest_request = true;
     43            }
     44        }
     45       
    3746        $ignored_patterns = [
    3847            'admin-ajax.php',
     
    4655            }
    4756        }
     57       
     58        // If it's a REST API request and user is authenticated, skip all firewall checks
     59        if ( $is_rest_request && is_user_logged_in() ) {
     60            return;
     61        }
    4862
    4963        //
     
    120134
    121135        if ( $post_scanning && isset( $_POST ) && $should_deep_scan ) {
     136            // Skip POST scanning for authenticated REST API requests
     137            if ( $is_rest_request && is_user_logged_in() ) {
     138                return;
     139            }
     140           
    122141            $post_array = apply_filters( 'post_items', [ '<%=', '\+\/"\/\+\/', '(<|%3C|&lt;?|u003c|x3c)script', 'src=#\s', '(href|src)="javascript:', '(href|src)=javascript:', '(href|src)=`javascript:' ] );
    123142
     
    129148                }
    130149
    131                 if ( ! is_admin() && preg_match( '/' . implode( '|', $post_array ) . '/i', $value, $matches ) ) {
     150                // Skip POST scanning for authenticated users in admin or REST API
     151                if ( ( is_admin() || ( $is_rest_request && is_user_logged_in() ) ) ) {
     152                    continue;
     153                }
     154               
     155                if ( preg_match( '/' . implode( '|', $post_array ) . '/i', $value, $matches ) ) {
    132156                    wp_guardian_gatekeeper_response( $matches, $request_uri_string, $query_string_string, $user_agent_string, $referrer_string );
    133157
  • wp-guardian/trunk/modules/security-measures.php

    r3404328 r3433652  
    214214        'init',
    215215        function () {
    216             if ( ! is_admin() && ! is_user_logged_in() ) {
     216            // Skip blocking for authenticated REST API requests
     217            $is_rest_request = false;
     218            if ( isset( $_SERVER['REQUEST_URI'] ) ) {
     219                $request_uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );
     220                if ( strpos( $request_uri, '/wp-json/' ) !== false ) {
     221                    $is_rest_request = true;
     222                }
     223            }
     224           
     225            // Only block if not admin, not logged in, and not authenticated REST API request
     226            if ( ! is_admin() && ! is_user_logged_in() && ! ( $is_rest_request && is_user_logged_in() ) ) {
    217227                $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
    218228                $restricted  = [ '/\.git/', '/\.svn/', '/\.env$', '/wp-config\.php$', '/\.htaccess$', '/\.htpasswd$' ];
  • wp-guardian/trunk/readme.txt

    r3432787 r3433652  
    77Requires PHP: 7.0
    88Requires CP: 2.0
    9 Stable tag: 1.8.2
     9Stable tag: 1.8.3
    1010License: GPLv3 or later
    1111License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    4343
    4444== Changelog ==
     45
     46= 1.8.3 =
     47* Fix: Authenticated REST API requests are now properly excluded from firewall blocking
     48* Fix: POST scanning no longer blocks authenticated REST API requests when saving pages
     49* Fix: Security measures no longer interfere with authenticated REST API requests
    4550
    4651= 1.8.2 =
  • wp-guardian/trunk/wp-guardian.php

    r3432787 r3433652  
    44 * Plugin URI: https://getbutterfly.com/wordpress-plugins/wp-guardian/
    55 * Description: An easy way to harden your website's security effectively.
    6  * Version: 1.8.2
     6 * Version: 1.8.3
    77 * Author: Ciprian Popescu
    88 * Author URI: https://getbutterfly.com/
     
    3333}
    3434
    35 define( 'DTJWPG_VERSION', '1.8.2' );
     35define( 'DTJWPG_VERSION', '1.8.3' );
    3636define( 'DTJWPG_URL', __FILE__ );
    3737define( 'DTJWPG_BASENAME', plugin_basename( DTJWPG_URL ) );
Note: See TracChangeset for help on using the changeset viewer.