Plugin Directory

Changeset 3428251


Ignore:
Timestamp:
12/27/2025 01:30:40 PM (3 months ago)
Author:
butterflymedia
Message:

Add UI toggle for Obfuscated Script Cleaner aggressive filtering (off by default). Also, the Obfuscated Script Cleaner is now less aggressive: only removes detected malicious scripts, not all HTML.

Location:
wp-guardian/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-guardian/trunk/assets/templates/guardian-security-measures.php

    r3404328 r3428251  
    99        echo '<div class="error notice is-dismissible"><p>' . esc_html__( 'Security check failed. Settings not saved.', 'wp-guardian' ) . '</p></div>';
    1010    } else {
     11
    1112        $measures = [
    1213            'restrict_file_access',
     
    3132        }
    3233
     34        // Handle Obfuscated Script Cleaner aggressive filter toggle
     35        $osc_aggressive = isset( $_POST['dtjwpg_osc_aggressive_filter'] ) ? 1 : 0;
     36        update_option( 'dtjwpg_osc_aggressive_filter', $osc_aggressive );
     37
    3338        // Apply PHP execution hardening for wp-content and wp-includes
    3439        if ( isset( $_POST['dtjwpg_security_measure_prevent_php_execution'] ) && (int) $_POST['dtjwpg_security_measure_prevent_php_execution'] === 1 ) {
     
    5459            <tr>
    5560                <th scope="row">
     61                    <label for="dtjwpg_osc_aggressive_filter"><?php esc_html_e( 'Obfuscated Script Cleaner: Aggressive Filtering', 'wp-guardian' ); ?></label>
     62                </th>
     63                <td>
     64                    <input type="checkbox" value="1" id="dtjwpg_osc_aggressive_filter" name="dtjwpg_osc_aggressive_filter" <?php checked( 1, (int) get_option( 'dtjwpg_osc_aggressive_filter', 0 ) ); ?>>
     65                    <p class="description">
     66                        <?php esc_html_e( 'If enabled, all HTML will be stripped from post/page content when malicious patterns are detected. If disabled (recommended), only the detected malicious scripts will be removed and normal HTML will be preserved.', 'wp-guardian' ); ?>
     67                    </p>
     68                </td>
     69            </tr>
     70        </tbody>
     71        <tbody>
     72            <tr>
     73                <th scope="row">
    5674                    <label><?php esc_html_e( 'Restrict access to files and directories', 'wp-guardian' ); ?></label>
    5775                </th>
  • wp-guardian/trunk/modules/obfuscated-script-cleaner.php

    r3423816 r3428251  
    8484    ];
    8585
     86    // Build the SQL with the correct number of placeholders, and pass post types as variadic args (splat operator)
    8687    $placeholders = implode( ',', array_fill( 0, count( $post_types ), '%s' ) );
     88    $sql          = "SELECT ID, post_type, post_content, post_excerpt FROM {$wpdb->posts} WHERE post_type IN ($placeholders)";
     89    // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
     90    $posts = $wpdb->get_results( $wpdb->prepare( $sql, ...$post_types ) );
    8791
    88     $sql = $wpdb->prepare(
    89         "
    90         SELECT ID, post_type, post_content, post_excerpt
    91         FROM {$wpdb->posts}
    92         WHERE post_type IN ($placeholders)
    93         ",
    94         $post_types
    95     );
    96 
    97     $posts   = $wpdb->get_results( $sql );
    9892    $cleaned = 0;
    9993
     
    135129
    136130    echo '<div class="notice notice-success"><p>';
     131    // translators: %d: Number of cleaned items.
    137132    echo esc_html( sprintf( __( 'Cleaning complete. %d items cleaned.', 'wp-guardian' ), $cleaned ) );
    138133    echo '</p></div>';
     
    142137 * Filter to block malicious content on save
    143138 */
     139
     140// Add a setting to toggle aggressive filtering (off by default)
     141if ( false === get_option( 'dtjwpg_osc_aggressive_filter', false ) ) {
     142    add_option( 'dtjwpg_osc_aggressive_filter', 0 );
     143}
     144
    144145add_filter(
    145146    'content_save_pre',
    146147    function ( $content ) {
     148        $aggressive = (int) get_option( 'dtjwpg_osc_aggressive_filter', 0 );
    147149        if ( preg_match( '/_0x[a-f0-9]{3,}|urshort\.live|atob|eval/i', $content ) ) {
    148150            error_log( 'Blocked malicious content save' );
    149             return wp_strip_all_tags( $content );
     151            if ( $aggressive ) {
     152                // Strip all HTML (aggressive)
     153                return wp_strip_all_tags( $content );
     154            } else {
     155                // Only remove the detected malicious scripts, keep other HTML
     156                $patterns = [
     157                    '#<script[^>]*>.*?(_0x[a-f0-9]{3,}|urshort\.live|atob|eval).*?</script>#is',
     158                ];
     159                foreach ( $patterns as $pattern ) {
     160                    $content = preg_replace( $pattern, '', $content );
     161                }
     162                return $content;
     163            }
    150164        }
    151165        return $content;
  • wp-guardian/trunk/readme.txt

    r3423816 r3428251  
    77Requires PHP: 7.0
    88Requires CP: 2.0
    9 Stable tag: 1.7.3
     9Stable tag: 1.8.0
    1010License: GPLv3 or later
    1111License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    4343
    4444== Changelog ==
     45
     46= 1.8.0 =
     47* Add UI toggle for Obfuscated Script Cleaner aggressive filtering (off by default)
     48* Obfuscated Script Cleaner is now less aggressive: only removes detected malicious scripts, not all HTML
     49* Fix: HTML is no longer stripped from post/page content unless aggressive mode is enabled
    4550
    4651= 1.7.3 =
  • wp-guardian/trunk/wp-guardian.php

    r3423816 r3428251  
    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.7.3
     6 * Version: 1.8.0
    77 * Author: Ciprian Popescu
    88 * Author URI: https://getbutterfly.com/
     
    3333}
    3434
    35 define( 'DTJWPG_VERSION', '1.7.3' );
     35define( 'DTJWPG_VERSION', '1.8.0' );
    3636define( 'DTJWPG_URL', __FILE__ );
    3737define( 'DTJWPG_BASENAME', plugin_basename( DTJWPG_URL ) );
Note: See TracChangeset for help on using the changeset viewer.