diff --git a/.wp-env.json b/.wp-env.json index 61758738..b5510618 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -6,7 +6,8 @@ ], "themes": [], "mappings": { - "wp-content/mu-plugins/visualizer-e2e-force-lazy-render.php": "./tests/e2e/config/force-lazy-render.php" + "wp-content/mu-plugins/visualizer-e2e-force-lazy-render.php": "./tests/e2e/config/force-lazy-render.php", + "wp-content/mu-plugins/visualizer-e2e-plant-chart-settings.php": "./tests/e2e/config/plant-chart-settings.php" }, "config": { "WP_DEBUG": true, diff --git a/classes/Visualizer/Module.php b/classes/Visualizer/Module.php index 13d7cbfc..ae799391 100644 --- a/classes/Visualizer/Module.php +++ b/classes/Visualizer/Module.php @@ -650,7 +650,7 @@ protected function get_inline_custom_css( $id, $settings ) { $class_name = $id . $name; $properties = implode( ' !important; ', array_filter( $attributes ) ); if ( ! empty( $properties ) ) { - $css .= '.' . $class_name . ' {' . $properties . ' !important;}'; + $css .= wp_strip_all_tags( '.' . $class_name . ' {' . $properties . ' !important;}' ); $classes[ $name ] = $class_name; } } diff --git a/tests/e2e/config/plant-chart-settings.php b/tests/e2e/config/plant-chart-settings.php new file mode 100644 index 00000000..5222e9de --- /dev/null +++ b/tests/e2e/config/plant-chart-settings.php @@ -0,0 +1,42 @@ +\d+)', + array( + 'methods' => 'POST', + 'permission_callback' => function () { + return current_user_can( 'manage_options' ); + }, + 'callback' => function ( WP_REST_Request $request ) { + $chart_id = (int) $request['id']; + $body = $request->get_json_params(); + if ( isset( $body['settings'] ) ) { + update_post_meta( $chart_id, 'visualizer-settings', $body['settings'] ); + } + if ( isset( $body['series'] ) ) { + update_post_meta( $chart_id, 'visualizer-series', $body['series'] ); + } + if ( isset( $body['content'] ) ) { + wp_update_post( + array( + 'ID' => $chart_id, + 'post_content' => maybe_serialize( $body['content'] ), + ) + ); + } + return array( 'ok' => true ); + }, + ) + ); + } +); diff --git a/tests/e2e/specs/custom-css.spec.js b/tests/e2e/specs/custom-css.spec.js new file mode 100644 index 00000000..1b2fb22f --- /dev/null +++ b/tests/e2e/specs/custom-css.spec.js @@ -0,0 +1,51 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +let chartId; + +test.describe( 'Custom CSS sanitization', () => { + test.beforeAll( async ( { requestUtils } ) => { + const chart = await requestUtils.rest( { + method: 'POST', + path: '/wp/v2/visualizer', + data: { title: 'Custom CSS payload chart', status: 'publish' }, + } ); + chartId = chart.id; + + await requestUtils.rest( { + method: 'POST', + path: `/visualizer-e2e/v1/chart-settings/${ chartId }`, + data: { + settings: { + customcss: { + title: { + color: 'red