From fc14b89683d29fcac1ff2508a0155304b7568056 Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 1 Nov 2024 11:48:52 +0900 Subject: [PATCH 1/9] [Fix] Implement Custom Sanitization for Google Ads & Enhance XSS Protection --- .../package/class-veu-promotion-alert.php | 788 ++++++++---------- 1 file changed, 364 insertions(+), 424 deletions(-) diff --git a/inc/promotion-alert/package/class-veu-promotion-alert.php b/inc/promotion-alert/package/class-veu-promotion-alert.php index e84a3341..6f2386d9 100644 --- a/inc/promotion-alert/package/class-veu-promotion-alert.php +++ b/inc/promotion-alert/package/class-veu-promotion-alert.php @@ -5,115 +5,61 @@ class VEU_Promotion_Alert { - /** - * Constructor Define - */ - public static function init() { + /** + * Constructor Define + */ + public static function init() { add_action( 'veu_package_init', array( __CLASS__, 'option_init' ) ); add_action( 'save_post', array( __CLASS__, 'save_meta_box' ) ); - // is_singular() で判定するため wp で実行 - add_action( 'wp', array( __CLASS__, 'display_alert' ) ); - add_action( 'wp_head', array( __CLASS__, 'inline_style' ), 5 ); - add_action( 'after_setup_theme', array( __CLASS__, 'content_filter' ) ); + // is_singular() で判定するため wp で実行 + add_action( 'wp', array( __CLASS__, 'display_alert' ) ); + add_action( 'wp_head', array( __CLASS__, 'inline_style' ), 5 ); + add_action( 'after_setup_theme', array( __CLASS__, 'content_filter' ) ); } - /** + /** * HTML Allowed */ - public static function kses_allowed() { - return array( - 'div' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'h1' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'h2' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'h3' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'h4' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'h5' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'h6' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'p' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'ul' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'ol' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'li' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'i' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - 'aria-hidden' => array() - ), - 'a' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - 'href' => array(), - ), - 'span' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - ), - 'button' => array( - 'id' => array(), - 'type' => array(), - 'class' => array(), - 'style' => array(), - 'href' => array(), - ), - 'img' => array( - 'id' => array(), - 'class' => array(), - 'style' => array(), - 'src' => array(), - 'alt' => array(), - ), - 'style' => array(), - '!' => array(), + public static function sanitize_alert_content($content) { + + // 1. ', + 'alert-display' => array('post' => 'display'), + ), + 'correct' => '
', + ), + array( + 'options' => array( + 'alert-content' => '', + 'alert-display' => array('post' => 'display'), + ), + 'correct' => '
', + ), ); print PHP_EOL; @@ -491,4 +534,4 @@ public function test_get_alert_content() { } -} \ No newline at end of file +} From 076f3fc8f3f0531cc70885e986594801fdca2c5f Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 1 Nov 2024 12:57:18 +0900 Subject: [PATCH 3/9] Add changelog --- readme.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.txt b/readme.txt index 9b0d14a1..278aad90 100644 --- a/readme.txt +++ b/readme.txt @@ -81,6 +81,8 @@ e.g. == Changelog == +[ Bug Fix ][ Promotion Alert ] Fixed filtering in Promotion Alert by adding data-nosnippet attribute to the div tag. + = 9.100.0 = [ Add setting ][ Category list ] Enable to specify ascending/descending order [ Specification Change ][ Twitter widget ] Added "Not recommended" to the name and added a note to the description. From 27cc5a061189e8398bb9810ef6ca0cc85974087a Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 1 Nov 2024 14:44:23 +0900 Subject: [PATCH 4/9] Undo kses_allowed --- .../package/class-veu-promotion-alert.php | 227 ++++++++++++------ 1 file changed, 158 insertions(+), 69 deletions(-) diff --git a/inc/promotion-alert/package/class-veu-promotion-alert.php b/inc/promotion-alert/package/class-veu-promotion-alert.php index 6f2386d9..b1b005e0 100644 --- a/inc/promotion-alert/package/class-veu-promotion-alert.php +++ b/inc/promotion-alert/package/class-veu-promotion-alert.php @@ -9,56 +9,127 @@ class VEU_Promotion_Alert { * Constructor Define */ public static function init() { + global $allowedposttags; + if ( isset( $allowedposttags['ins'] ) ) { + $allowedposttags['ins']['style'] = array(); + } add_action( 'veu_package_init', array( __CLASS__, 'option_init' ) ); add_action( 'save_post', array( __CLASS__, 'save_meta_box' ) ); // is_singular() で判定するため wp で実行 add_action( 'wp', array( __CLASS__, 'display_alert' ) ); add_action( 'wp_head', array( __CLASS__, 'inline_style' ), 5 ); add_action( 'after_setup_theme', array( __CLASS__, 'content_filter' ) ); + add_filter( 'wp_kses_allowed_css', array( __CLASS__, 'promotion_alert_allowed_css' ) ); + add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'modify_wp_kses_allowed_html' ), 99, 2 ); + } + + /** + * Allow data-nosnippet attribute on div tags for kses filtering. + */ + public static function modify_wp_kses_allowed_html( $allowed_tags, $context ) { + // 必要な属性やタグを追加 + if ( 'post' === $context ) { + $allowed_tags['div']['data-nosnippet'] = true; + } + return $allowed_tags; } /** * HTML Allowed */ - public static function sanitize_alert_content($content) { - - // 1. ', - 'alert-display' => array('post' => 'display'), - ), - 'correct' => '
', + 'correct' => '', ), array( 'options' => array( From 523421762f71371545cc2330a68e14def3ea180d Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 1 Nov 2024 15:35:08 +0900 Subject: [PATCH 7/9] Undo some code --- inc/promotion-alert/package/class-veu-promotion-alert.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/inc/promotion-alert/package/class-veu-promotion-alert.php b/inc/promotion-alert/package/class-veu-promotion-alert.php index 9c74e987..3334caa5 100644 --- a/inc/promotion-alert/package/class-veu-promotion-alert.php +++ b/inc/promotion-alert/package/class-veu-promotion-alert.php @@ -232,8 +232,11 @@ public static function sanitize_space( $input ) { */ public static function sanitize_setting( $input ) { - // 許可されたHTMLタグのリストを取得 - $allowed_html = self::kses_allowed(); + // 投稿タイプを取得 + $post_types = self::get_post_types(); + + // 許可されたHTMLタグ + $allowed_html = self::kses_allowed(); // サニタイズ処理 $options = array(); From 1f19eb0c95a8a21f5d4b843949e8b9731be744bd Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 1 Nov 2024 15:36:14 +0900 Subject: [PATCH 8/9] Delete error_log --- inc/promotion-alert/package/class-veu-promotion-alert.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/inc/promotion-alert/package/class-veu-promotion-alert.php b/inc/promotion-alert/package/class-veu-promotion-alert.php index 3334caa5..3034b33e 100644 --- a/inc/promotion-alert/package/class-veu-promotion-alert.php +++ b/inc/promotion-alert/package/class-veu-promotion-alert.php @@ -244,11 +244,7 @@ public static function sanitize_setting( $input ) { // alert-contentを許可リストに基づいてサニタイズ if ( ! empty( $input['alert-content'] ) ) { - // サニタイズ前のデバッグ出力 - error_log( 'Before wp_kses: ' . print_r( stripslashes( $input['alert-content'] ), true ) ); $options['alert-content'] = wp_kses( stripslashes( $input['alert-content'] ), $allowed_html ); - // サニタイズ後のデバッグ出力 - error_log( 'After wp_kses: ' . print_r( $options['alert-content'], true ) ); } else { $options['alert-content'] = ''; } From f63f50c8cf14d08a7bf5719b6198da208a139683 Mon Sep 17 00:00:00 2001 From: mtdkei Date: Tue, 5 Nov 2024 11:54:45 +0900 Subject: [PATCH 9/9] Delete unnecessary code --- .../package/class-veu-promotion-alert.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/inc/promotion-alert/package/class-veu-promotion-alert.php b/inc/promotion-alert/package/class-veu-promotion-alert.php index 3034b33e..50ea93fb 100644 --- a/inc/promotion-alert/package/class-veu-promotion-alert.php +++ b/inc/promotion-alert/package/class-veu-promotion-alert.php @@ -9,10 +9,6 @@ class VEU_Promotion_Alert { * Constructor Define */ public static function init() { - global $allowedposttags; - if ( isset( $allowedposttags['ins'] ) ) { - $allowedposttags['ins']['style'] = array(); - } add_action( 'veu_package_init', array( __CLASS__, 'option_init' ) ); add_action( 'save_post', array( __CLASS__, 'save_meta_box' ) ); // is_singular() で判定するため wp で実行 @@ -21,17 +17,6 @@ public static function init() { add_action( 'after_setup_theme', array( __CLASS__, 'content_filter' ) ); } - /** - * Allow data-nosnippet attribute on div tags for kses filtering. - */ - public static function modify_wp_kses_allowed_html( $allowed_tags, $context ) { - // 必要な属性やタグを追加 - if ( 'post' === $context ) { - $allowed_tags['div']['data-nosnippet'] = true; - } - return $allowed_tags; - } - /** * HTML Allowed */