From 6ee5e65c1955fadb1d6274aa9ce79c13085de447 Mon Sep 17 00:00:00 2001 From: selul Date: Thu, 12 Nov 2026 01:51:49 +0200 Subject: [PATCH 1/5] fix: normalize table rendering inputs --- classes/Visualizer/Gutenberg/Block.php | 9 +- classes/Visualizer/Module.php | 25 ++++- js/render-datatables.js | 15 +-- tests/js/render-datatables-settings.test.js | 100 ++++++++++++++++++++ tests/test-chart-data-sanitization.php | 40 ++++++++ 5 files changed, 180 insertions(+), 9 deletions(-) create mode 100644 tests/js/render-datatables-settings.test.js create mode 100644 tests/test-chart-data-sanitization.php diff --git a/classes/Visualizer/Gutenberg/Block.php b/classes/Visualizer/Gutenberg/Block.php index 5a152351..d8acb490 100644 --- a/classes/Visualizer/Gutenberg/Block.php +++ b/classes/Visualizer/Gutenberg/Block.php @@ -327,7 +327,14 @@ public function get_visualizer_data( $post ) { $data['visualizer-settings'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $data['visualizer-settings'], $post_id, $data['visualizer-chart-type'] ); // handle data filter hooks - $data['visualizer-data'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, Visualizer_Module::decode_content( html_entity_decode( get_post_field( 'post_content', $post_id, 'raw' ) ) ), $post_id, $data['visualizer-chart-type'] ); + $data['visualizer-data'] = Visualizer_Module::sanitize_chart_data( + apply_filters( + Visualizer_Plugin::FILTER_GET_CHART_DATA, + Visualizer_Module::decode_content( html_entity_decode( get_post_field( 'post_content', $post_id, 'raw' ) ) ), + $post_id, + $data['visualizer-chart-type'] + ) + ); // we are going to format only for tabular charts, because we are not sure of the effect on others. // this is to solve the case where boolean data shows up as all-ticks on gutenberg. diff --git a/classes/Visualizer/Module.php b/classes/Visualizer/Module.php index ff9fa2c3..49f9240b 100644 --- a/classes/Visualizer/Module.php +++ b/classes/Visualizer/Module.php @@ -912,9 +912,30 @@ function ( $matches ) { $altered = $data; } if ( $run_filter ) { - return apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, $altered, $chart->ID, $type ); + $altered = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, $altered, $chart->ID, $type ); } - return $altered; + + return self::sanitize_chart_data( $altered ); + } + + /** + * Sanitize chart data before passing it to HTML-capable renderers. + * + * @param mixed $data Chart data. + * @return mixed Sanitized chart data. + */ + public static function sanitize_chart_data( $data ) { + // Preserve normal text and supported formatting while removing active + // markup from imports, scheduled remote sources, and filtered data. + return map_deep( + $data, + static function ( $value ) { + if ( ! is_string( $value ) || ! preg_match( '/<\s*\/?\s*[a-zA-Z!][^>]*>/s', $value ) ) { + return $value; + } + return wp_kses_post( $value ); + } + ); } /** diff --git a/js/render-datatables.js b/js/render-datatables.js index 3a210694..1cb43fc7 100644 --- a/js/render-datatables.js +++ b/js/render-datatables.js @@ -108,6 +108,9 @@ var select = { info: false }; + var nestedSettings = { + select: select + }; // we cannot use { select } below because https://github.com/Codeinwp/visualizer/issues/357 $.extend( settings, { info: false } ); // jshint ignore:line @@ -163,15 +166,15 @@ // if the setting name has an '_' this means it is a sub-setting e.g. select_items means { select: { items: ... } }. var array = i.split('_'); - if(array.length === 2){ - i = eval( array[0] ); // jshint ignore:line - i[ array[1] ] = valoo; - additional[ array[0] ] = i; + if(array.length === 2 && Object.prototype.hasOwnProperty.call(nestedSettings, array[0])){ + var nestedSetting = nestedSettings[ array[0] ]; + nestedSetting[ array[1] ] = valoo; + additional[ array[0] ] = nestedSetting; if(array[0] === 'select' && array[1] === 'info' ){ // enable main info or the selection info will not show. $.extend( settings, {info: true} ); } - } else { + } else if(array.length === 1) { settings[i] = valoo; } } @@ -450,4 +453,4 @@ $.fn.dataTable.render.moment = function ( from, to, locale ) { })); -/* jshint ignore:end */ \ No newline at end of file +/* jshint ignore:end */ diff --git a/tests/js/render-datatables-settings.test.js b/tests/js/render-datatables-settings.test.js new file mode 100644 index 00000000..394e56a4 --- /dev/null +++ b/tests/js/render-datatables-settings.test.js @@ -0,0 +1,100 @@ +const assert = require( 'node:assert/strict' ); +const path = require( 'path' ); +const { afterEach, beforeEach, describe, it } = require( 'node:test' ); + +describe( 'DataTables nested settings', () => { + let handlers; + let capturedSettings; + let alertCalls; + + beforeEach( () => { + handlers = {}; + capturedSettings = null; + alertCalls = 0; + + global.window = {}; + global.document = { + getElementById: () => ( {} ), + }; + global.alert = () => { + alertCalls++; + }; + + const collection = { + length: 0, + hasClass: () => false, + children: () => ( { length: 0 } ), + find: () => ( { length: 0 } ), + empty() { + return this; + }, + append() { + return this; + }, + css: () => '400px', + addClass() { + return this; + }, + remove() { + return this; + }, + on( event, callback ) { + handlers[ event ] = callback; + return this; + }, + trigger() { + return this; + }, + DataTable( settings ) { + capturedSettings = settings; + return this; + }, + }; + + const jquery = () => collection; + jquery.extend = ( target, ...sources ) => Object.assign( target, ...sources ); + jquery.fn = { + dataTable: { + render: { + number: () => null, + }, + }, + }; + global.jQuery = jquery; + + const renderer = path.resolve( __dirname, '../../js/render-datatables.js' ); + delete require.cache[ renderer ]; + require( renderer ); + } ); + + afterEach( () => { + delete global.alert; + delete global.document; + delete global.jQuery; + delete global.window; + } ); + + function renderWithSettings( settings ) { + handlers[ 'visualizer:render:specificchart:start' ]( {}, { + id: 'chart', + chart: { + library: 'datatables', + settings, + series: [ { label: 'Value', type: 'string' } ], + data: [ [ 'Example' ] ], + }, + v: { page_type: 'frontend' }, + } ); + } + + it( 'does not execute an unsupported nested setting name', () => { + assert.doesNotThrow( () => renderWithSettings( { 'alert(1)_x': 'value' } ) ); + assert.equal( alertCalls, 0 ); + } ); + + it( 'continues to apply the supported select nested setting', () => { + renderWithSettings( { select_info: 'true' } ); + assert.equal( capturedSettings.select.info, true ); + assert.equal( capturedSettings.info, true ); + } ); +} ); diff --git a/tests/test-chart-data-sanitization.php b/tests/test-chart-data-sanitization.php new file mode 100644 index 00000000..a43c21b4 --- /dev/null +++ b/tests/test-chart-data-sanitization.php @@ -0,0 +1,40 @@ + 123, + 'post_content' => serialize( + array( + array( + 'Revenue', + '', + '', + 'Research & Development', + '3 < 5', + ), + ) + ), + ); + + $result = Visualizer_Module::get_chart_data( $chart, 'table', false ); + + $this->assertSame( 'Revenue', $result[0][0] ); + $this->assertStringNotContainsString( 'onerror', $result[0][1] ); + $this->assertStringNotContainsString( 'assertSame( 'Research & Development', $result[0][3] ); + $this->assertSame( '3 < 5', $result[0][4] ); + } +} From 396d4693045b905e6d8bb90a330375e84767a321 Mon Sep 17 00:00:00 2001 From: selul Date: Thu, 12 Nov 2026 12:40:17 +0200 Subject: [PATCH 2/5] fix: scope chart data access boundaries --- classes/Visualizer/Module/Chart.php | 11 +-- classes/Visualizer/Plugin.php | 1 + classes/Visualizer/Source/Json.php | 7 +- package-lock.json | 100 ++++++++++++++++++++-------- package.json | 4 +- tests/test-ajax.php | 56 ++++++++++++++++ tests/test-remote-fetch.php | 53 +++++++++++++++ 7 files changed, 196 insertions(+), 36 deletions(-) diff --git a/classes/Visualizer/Module/Chart.php b/classes/Visualizer/Module/Chart.php index bbe126e0..a49654af 100644 --- a/classes/Visualizer/Module/Chart.php +++ b/classes/Visualizer/Module/Chart.php @@ -138,16 +138,17 @@ public function setJsonSchedule() { ); if ( Visualizer_Module::is_pro() ) { - $is_woocommerce_report = filter_input( - INPUT_POST, - 'is_woocommerce_report', - FILTER_VALIDATE_BOOLEAN - ); + $is_woocommerce_report = isset( $_POST['is_woocommerce_report'] ) ? filter_var( wp_unslash( $_POST['is_woocommerce_report'] ), FILTER_VALIDATE_BOOLEAN ) : false; if ( $is_woocommerce_report ) { + if ( ! current_user_can( 'view_woocommerce_reports' ) ) { + wp_send_json_error( array( 'msg' => esc_html__( 'You do not have permission to access WooCommerce reports.', 'visualizer' ) ), 403 ); + } update_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, get_current_user_id() ); } else { delete_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE ); + delete_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER ); } } diff --git a/classes/Visualizer/Plugin.php b/classes/Visualizer/Plugin.php index 162672c0..8d632e2b 100644 --- a/classes/Visualizer/Plugin.php +++ b/classes/Visualizer/Plugin.php @@ -106,6 +106,7 @@ class Visualizer_Plugin { const CF_CHART_CACHE = 'visualizer-chart-cache'; const CF_JSON_WOOCOMMERCE_SOURCE = 'visualizer-woocommerce-source'; const CF_IS_WOOCOMMERCE_SOURCE = 'visualizer-is-woocommerce-source'; + const CF_WOOCOMMERCE_REPORT_USER = 'visualizer-woocommerce-report-user'; /** * Name of the option for WordPress DB. diff --git a/classes/Visualizer/Source/Json.php b/classes/Visualizer/Source/Json.php index 0da21be8..ba819ad8 100644 --- a/classes/Visualizer/Source/Json.php +++ b/classes/Visualizer/Source/Json.php @@ -457,8 +457,13 @@ function ( $headers ) { } } - // Check if this is a WooCommerce endpoint request and add verification token. + // Check if this is an authorized WooCommerce endpoint request and add a verification token. + $can_fetch_woocommerce_reports = false; if ( $this->is_woocommerce_request( $url ) ) { + $can_fetch_woocommerce_reports = current_user_can( 'view_woocommerce_reports' ); + $can_fetch_woocommerce_reports = apply_filters( 'visualizer_can_fetch_woocommerce_reports', $can_fetch_woocommerce_reports, $url ); + } + if ( ! empty( $can_fetch_woocommerce_reports ) ) { // Generate a unique token for this specific request. $token = wp_generate_password( 32, false ); set_transient( 'visualizer_wc_token_' . $token, time(), 60 ); diff --git a/package-lock.json b/package-lock.json index fd175637..176e26aa 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "visualizer", - "version": "3.11.15", + "version": "4.0.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "visualizer", - "version": "3.11.15", + "version": "4.0.10", "license": "GPL-2.0+", "dependencies": { "@chakra-ui/react": "^3.34.0", @@ -16,12 +16,11 @@ "@uiw/react-codemirror": "^4.23.6", "d3": "^7.9.0", "deep-filter": "^1.0.2", - "handsontable": "^13.0.0", "is-plain-object": "^2.0.4", - "merge": "^1.2.1", + "merge": "^2.1.1", "react-google-charts": "^3.0.8", "topojson-client": "^3.1.0", - "uuid": "^8.3.2" + "uuid": "^11.1.1" }, "devDependencies": { "@semantic-release/changelog": "^5.0.1", @@ -7633,6 +7632,7 @@ "resolved": "https://registry.npmjs.org/@types/pikaday/-/pikaday-1.7.4.tgz", "integrity": "sha512-0KsHVyw5pTG829nqG4IRu7m+BFQlFEBdbE/1i3S5182HeKUKv1uEW0gyEmkJVp5i4IV+9pyh23O83+KpRkSQbw==", "license": "MIT", + "peer": true, "dependencies": { "moment": ">=2.14.0" } @@ -12718,6 +12718,7 @@ "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-8.1.1.tgz", "integrity": "sha512-QD46ppGintwPGuL1KqmwhR0O+N2cZUg8JG/VzwI2e28sM9TqHjQB10lI4QAaMHVbLzwVLLAwEglpKPViWX+5NQ==", "license": "MIT", + "peer": true, "engines": { "node": "*" } @@ -13369,6 +13370,7 @@ "integrity": "sha512-BwqQ/AgmKJ8jcMEjaSnfMybnKMgGTrtDKowfTP3pX4jwVy0kNjRsT/AP6h+wC3+3NC+X8X15VWBnTCQlX+wQFg==", "license": "Apache-2.0", "optional": true, + "peer": true, "dependencies": { "regexp-to-ast": "0.4.0" } @@ -15879,7 +15881,8 @@ "version": "2.5.9", "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.5.9.tgz", "integrity": "sha512-i6mvVmWN4xo9LrhCOZrDgSs9noW6nOahbrmzjRbPF36YPyj5Ue5lgok0MHDWkG7xzpWFO2OYttXdzM7rJxHvNA==", - "license": "(MPL-2.0 OR Apache-2.0)" + "license": "(MPL-2.0 OR Apache-2.0)", + "peer": true }, "node_modules/domutils": { "version": "3.1.0", @@ -19108,6 +19111,7 @@ "resolved": "https://registry.npmjs.org/handsontable/-/handsontable-13.1.0.tgz", "integrity": "sha512-KqJtS3rJeOWsFWCffnDlM8fcLMTqmW+Vbc7OCVM4X7dYDpfefgFerjNLIxLfT9xohcQoUOS1jcvXwV8dwSppVQ==", "license": "SEE LICENSE IN LICENSE.txt", + "peer": true, "dependencies": { "@types/pikaday": "1.7.4", "core-js": "^3.31.1", @@ -19567,6 +19571,7 @@ "integrity": "sha512-mpVF5zOyNpksZzgTaCQyRAzdC/X43+taz5x1n7zNbs/PUUv0AuLmsy2yfihCr+vihUzN/pk+gXBbOfNpXKOpgA==", "license": "GPL-3.0-only", "optional": true, + "peer": true, "dependencies": { "chevrotain": "^6.5.0", "tiny-emitter": "^2.1.0" @@ -23120,9 +23125,9 @@ } }, "node_modules/merge": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/merge/-/merge-1.2.1.tgz", - "integrity": "sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/merge/-/merge-2.1.1.tgz", + "integrity": "sha512-jz+Cfrg9GWOZbQAnDQ4hlVnQky+341Yk5ru8bZSe6sIDTCIg8n9i/u7hSQGSVOF3C7lH6mGtqjkiT9G4wFLL0w==", "license": "MIT" }, "node_modules/merge-deep": { @@ -23465,6 +23470,7 @@ "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", "license": "MIT", + "peer": true, "engines": { "node": "*" } @@ -26857,6 +26863,7 @@ "resolved": "https://registry.npmjs.org/numbro/-/numbro-2.1.2.tgz", "integrity": "sha512-7w833BxZmKGLE9HI0aREtNVRVH6WTYUUlWf4qgA5gKNhPQ4F/MRZ14sc0v8eoLORprk9ZTVwYaLwj8N3Zgxwiw==", "license": "MIT", + "peer": true, "dependencies": { "bignumber.js": "^8.0.1" }, @@ -28167,7 +28174,8 @@ "version": "1.8.2", "resolved": "https://registry.npmjs.org/pikaday/-/pikaday-1.8.2.tgz", "integrity": "sha512-TNtsE+34BIax3WtkB/qqu5uepV1McKYEgvL3kWzU7aqPCpMEN6rBF3AOwu4WCwAealWlBGobXny/9kJb49C1ew==", - "license": "(0BSD OR MIT)" + "license": "(0BSD OR MIT)", + "peer": true }, "node_modules/pinkie": { "version": "2.0.4", @@ -29835,7 +29843,8 @@ "resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.4.0.tgz", "integrity": "sha512-4qf/7IsIKfSNHQXSwial1IFmfM1Cc/whNBQqRwe0V2stPe7KmN1U0tWQiIx6JiirgSrisjE0eECdNf7Tav1Ntw==", "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", @@ -31337,6 +31346,17 @@ "websocket-driver": "^0.7.4" } }, + "node_modules/sockjs/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "deprecated": "uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).", + "dev": true, + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/socks": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.1.tgz", @@ -32872,7 +32892,8 @@ "resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.1.0.tgz", "integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==", "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/tmp": { "version": "0.2.1", @@ -33684,12 +33705,16 @@ } }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.1.tgz", + "integrity": "sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "license": "MIT", "bin": { - "uuid": "dist/bin/uuid" + "uuid": "dist/esm/bin/uuid" } }, "node_modules/v8-compile-cache": { @@ -40280,6 +40305,7 @@ "version": "1.7.4", "resolved": "https://registry.npmjs.org/@types/pikaday/-/pikaday-1.7.4.tgz", "integrity": "sha512-0KsHVyw5pTG829nqG4IRu7m+BFQlFEBdbE/1i3S5182HeKUKv1uEW0gyEmkJVp5i4IV+9pyh23O83+KpRkSQbw==", + "peer": true, "requires": { "moment": ">=2.14.0" } @@ -44064,7 +44090,8 @@ "bignumber.js": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-8.1.1.tgz", - "integrity": "sha512-QD46ppGintwPGuL1KqmwhR0O+N2cZUg8JG/VzwI2e28sM9TqHjQB10lI4QAaMHVbLzwVLLAwEglpKPViWX+5NQ==" + "integrity": "sha512-QD46ppGintwPGuL1KqmwhR0O+N2cZUg8JG/VzwI2e28sM9TqHjQB10lI4QAaMHVbLzwVLLAwEglpKPViWX+5NQ==", + "peer": true }, "binary-extensions": { "version": "2.2.0", @@ -44547,6 +44574,7 @@ "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-6.5.0.tgz", "integrity": "sha512-BwqQ/AgmKJ8jcMEjaSnfMybnKMgGTrtDKowfTP3pX4jwVy0kNjRsT/AP6h+wC3+3NC+X8X15VWBnTCQlX+wQFg==", "optional": true, + "peer": true, "requires": { "regexp-to-ast": "0.4.0" } @@ -46370,7 +46398,8 @@ "dompurify": { "version": "2.5.9", "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.5.9.tgz", - "integrity": "sha512-i6mvVmWN4xo9LrhCOZrDgSs9noW6nOahbrmzjRbPF36YPyj5Ue5lgok0MHDWkG7xzpWFO2OYttXdzM7rJxHvNA==" + "integrity": "sha512-i6mvVmWN4xo9LrhCOZrDgSs9noW6nOahbrmzjRbPF36YPyj5Ue5lgok0MHDWkG7xzpWFO2OYttXdzM7rJxHvNA==", + "peer": true }, "domutils": { "version": "3.1.0", @@ -48731,6 +48760,7 @@ "version": "13.1.0", "resolved": "https://registry.npmjs.org/handsontable/-/handsontable-13.1.0.tgz", "integrity": "sha512-KqJtS3rJeOWsFWCffnDlM8fcLMTqmW+Vbc7OCVM4X7dYDpfefgFerjNLIxLfT9xohcQoUOS1jcvXwV8dwSppVQ==", + "peer": true, "requires": { "@types/pikaday": "1.7.4", "core-js": "^3.31.1", @@ -49061,6 +49091,7 @@ "resolved": "https://registry.npmjs.org/hyperformula/-/hyperformula-2.7.1.tgz", "integrity": "sha512-mpVF5zOyNpksZzgTaCQyRAzdC/X43+taz5x1n7zNbs/PUUv0AuLmsy2yfihCr+vihUzN/pk+gXBbOfNpXKOpgA==", "optional": true, + "peer": true, "requires": { "chevrotain": "^6.5.0", "tiny-emitter": "^2.1.0" @@ -51711,9 +51742,9 @@ } }, "merge": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/merge/-/merge-1.2.1.tgz", - "integrity": "sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ==" + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/merge/-/merge-2.1.1.tgz", + "integrity": "sha512-jz+Cfrg9GWOZbQAnDQ4hlVnQky+341Yk5ru8bZSe6sIDTCIg8n9i/u7hSQGSVOF3C7lH6mGtqjkiT9G4wFLL0w==" }, "merge-deep": { "version": "3.0.3", @@ -51968,7 +51999,8 @@ "moment": { "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "peer": true }, "mrmime": { "version": "2.0.0", @@ -54413,6 +54445,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/numbro/-/numbro-2.1.2.tgz", "integrity": "sha512-7w833BxZmKGLE9HI0aREtNVRVH6WTYUUlWf4qgA5gKNhPQ4F/MRZ14sc0v8eoLORprk9ZTVwYaLwj8N3Zgxwiw==", + "peer": true, "requires": { "bignumber.js": "^8.0.1" } @@ -55413,7 +55446,8 @@ "pikaday": { "version": "1.8.2", "resolved": "https://registry.npmjs.org/pikaday/-/pikaday-1.8.2.tgz", - "integrity": "sha512-TNtsE+34BIax3WtkB/qqu5uepV1McKYEgvL3kWzU7aqPCpMEN6rBF3AOwu4WCwAealWlBGobXny/9kJb49C1ew==" + "integrity": "sha512-TNtsE+34BIax3WtkB/qqu5uepV1McKYEgvL3kWzU7aqPCpMEN6rBF3AOwu4WCwAealWlBGobXny/9kJb49C1ew==", + "peer": true }, "pinkie": { "version": "2.0.4", @@ -56557,7 +56591,8 @@ "version": "0.4.0", "resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.4.0.tgz", "integrity": "sha512-4qf/7IsIKfSNHQXSwial1IFmfM1Cc/whNBQqRwe0V2stPe7KmN1U0tWQiIx6JiirgSrisjE0eECdNf7Tav1Ntw==", - "optional": true + "optional": true, + "peer": true }, "regexp.prototype.flags": { "version": "1.5.2", @@ -57644,6 +57679,14 @@ "faye-websocket": "^0.11.3", "uuid": "^8.3.2", "websocket-driver": "^0.7.4" + }, + "dependencies": { + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true + } } }, "socks": { @@ -58835,7 +58878,8 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.1.0.tgz", "integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==", - "optional": true + "optional": true, + "peer": true }, "tmp": { "version": "0.2.1", @@ -59434,9 +59478,9 @@ "dev": true }, "uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.1.tgz", + "integrity": "sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ==" }, "v8-compile-cache": { "version": "2.4.0", diff --git a/package.json b/package.json index 64f7d057..afe1b8bf 100755 --- a/package.json +++ b/package.json @@ -50,10 +50,10 @@ "d3": "^7.9.0", "deep-filter": "^1.0.2", "is-plain-object": "^2.0.4", - "merge": "^1.2.1", + "merge": "^2.1.1", "react-google-charts": "^3.0.8", "topojson-client": "^3.1.0", - "uuid": "^8.3.2" + "uuid": "^11.1.1" }, "devDependencies": { "@semantic-release/changelog": "^5.0.1", diff --git a/tests/test-ajax.php b/tests/test-ajax.php index 20a0ed8c..61e7dc18 100644 --- a/tests/test-ajax.php +++ b/tests/test-ajax.php @@ -1122,6 +1122,62 @@ public function test_json_schedule_denied_for_chart_user_cannot_edit() { $this->assertSame( '', get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true ) ); } + /** + * A chart editor without report access cannot schedule a WooCommerce report import. + * + * @group ajax + */ + public function test_woocommerce_json_schedule_denied_without_report_capability() { + $this->enable_pro(); + $chart_id = $this->create_chart_for_user( $this->contibutor_user_id ); + wp_set_current_user( $this->contibutor_user_id ); + $_POST = array( + 'chart' => $chart_id, + 'time' => 12, + 'is_woocommerce_report' => 'true', + 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE . Visualizer_Plugin::VERSION ), + ); + + try { + $this->_handleAjax( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE ); + } catch ( WPAjaxDieContinueException $e ) { + // Expected after the JSON response. + } + + $response = json_decode( $this->_last_response ); + $this->assertFalse( $response->success ); + $this->assertSame( '', get_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, true ) ); + } + + /** + * A report-capable chart editor can authorize future scheduled imports. + * + * @group ajax + */ + public function test_woocommerce_json_schedule_records_authorizing_user() { + $this->enable_pro(); + $chart_id = $this->create_chart_for_user( $this->admin_user_id ); + wp_set_current_user( $this->admin_user_id ); + wp_get_current_user()->add_cap( 'view_woocommerce_reports' ); + $this->assertTrue( current_user_can( 'view_woocommerce_reports' ) ); + $_POST = array( + 'chart' => $chart_id, + 'time' => 12, + 'is_woocommerce_report' => 'true', + 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE . Visualizer_Plugin::VERSION ), + ); + + try { + $this->_handleAjax( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE ); + } catch ( WPAjaxDieContinueException $e ) { + // Expected after the JSON response. + } + + $response = json_decode( $this->_last_response ); + $this->assertTrue( $response->success, $this->_last_response ); + $this->assertSame( $this->admin_user_id, (int) get_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, true ) ); + } + /** * A user cannot replace another user's JSON chart data. */ diff --git a/tests/test-remote-fetch.php b/tests/test-remote-fetch.php index 308ffc40..06f7931c 100644 --- a/tests/test-remote-fetch.php +++ b/tests/test-remote-fetch.php @@ -680,6 +680,59 @@ public function test_download_blocks_non_public_destination() { $this->assertSame( 0, $requests ); } + /** + * Chart editors without WooCommerce report access must not receive the internal token. + */ + public function test_json_source_does_not_mint_woocommerce_token_for_contributor() { + $user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); + wp_set_current_user( $user_id ); + + $headers = $this->capture_woocommerce_request_headers(); + + $this->assertArrayNotHasKey( 'X-Visualizer-Token', $headers ); + } + + /** + * Shop users with report access retain the WooCommerce chart source feature. + */ + public function test_json_source_mints_woocommerce_token_for_authorized_user() { + $user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); + $user = new WP_User( $user_id ); + $user->add_cap( 'view_woocommerce_reports' ); + wp_set_current_user( $user_id ); + + $headers = $this->capture_woocommerce_request_headers(); + + $this->assertArrayHasKey( 'X-Visualizer-Token', $headers ); + $this->assertNotSame( '', $headers['X-Visualizer-Token'] ); + delete_transient( 'visualizer_wc_token_' . $headers['X-Visualizer-Token'] ); + } + + /** + * Captures the headers generated for a same-site WooCommerce reports request. + * + * @return array + */ + private function capture_woocommerce_request_headers() { + $headers = array(); + $filter = function ( $preempt, $args ) use ( &$headers ) { + $headers = $args['headers']; + return $this->response( 200, array(), '[{"total_sales":"10.00"}]' ); + }; + add_filter( 'pre_http_request', $filter, 10, 2 ); + + $source = new Visualizer_Source_Json( + array( + 'url' => home_url( '/wp-json/wc/v3/reports/sales' ), + 'root' => 'root', + ) + ); + $source->fetchRoots(); + + remove_filter( 'pre_http_request', $filter, 10 ); + return $headers; + } + /** * Builds a WordPress HTTP response fixture. * From 6f437694858ca28ff116ca57050ff794c6ef163e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Fri, 13 Nov 2026 13:30:19 +0200 Subject: [PATCH 3/5] test: cover chart data sanitization in the block editor --- tests/test-chart-data-sanitization.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test-chart-data-sanitization.php b/tests/test-chart-data-sanitization.php index a43c21b4..0c4897cd 100644 --- a/tests/test-chart-data-sanitization.php +++ b/tests/test-chart-data-sanitization.php @@ -37,4 +37,29 @@ public function test_chart_data_removes_active_markup() { $this->assertSame( 'Research & Development', $result[0][3] ); $this->assertSame( '3 < 5', $result[0][4] ); } + + /** + * The block editor reads chart data through its own path, which gets the same sanitization. + */ + public function test_block_editor_chart_data_removes_active_markup() { + $author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); + // Stored as an administrator would, so post content filtering leaves the serialized data intact. + wp_set_current_user( $author_id ); + $chart_id = self::factory()->post->create( + array( + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, + 'post_status' => 'publish', + 'post_author' => $author_id, + 'post_content' => wp_slash( serialize( array( array( 'Revenue', '' ) ) ) ), + ) + ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, 'line' ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array() ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, array( array( 'label' => 'Label', 'type' => 'string' ) ) ); + + $result = Visualizer_Gutenberg_Block::get_instance()->get_visualizer_data( array( 'id' => $chart_id ) ); + + $this->assertSame( 'Revenue', $result['visualizer-data'][0][0] ); + $this->assertStringNotContainsString( ' Date: Sat, 14 Nov 2026 02:34:35 +0200 Subject: [PATCH 4/5] fix: apply the chart cell boundary to previews and keep report data on failed refreshes Normalize every tag opening in rendered cells, sanitize import and query previews, and keep exports and the data editor on the stored values. Record the user who sets a JSON endpoint as its report user, and keep the stored data when a WooCommerce report fetch fails. --- classes/Visualizer/Module.php | 14 +- classes/Visualizer/Module/Chart.php | 29 ++++- classes/Visualizer/Render/Layout.php | 2 +- classes/Visualizer/Source/Json.php | 7 +- classes/Visualizer/Source/Query.php | 2 +- js/render-datatables.js | 2 +- tests/test-ajax.php | 172 +++++++++++++++++++++++-- tests/test-chart-data-sanitization.php | 92 +++++++++++-- tests/test-remote-fetch.php | 93 +++++++++++++ 9 files changed, 381 insertions(+), 32 deletions(-) diff --git a/classes/Visualizer/Module.php b/classes/Visualizer/Module.php index 49f9240b..8fbb8977 100644 --- a/classes/Visualizer/Module.php +++ b/classes/Visualizer/Module.php @@ -190,7 +190,7 @@ public function _getDataAs( $chart_id, $type ) { $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ); $rows = array(); $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ); - $data = self::get_chart_data( $chart, $type, false ); + $data = self::get_chart_data( $chart, $type, false, 'print' === $type ); if ( ! empty( $series ) ) { $row = array(); foreach ( $series as $array ) { @@ -880,8 +880,14 @@ public static function maybe_decode_content( $value ) { /** * Gets the chart content after common manipulations. + * + * @param WP_Post|object $chart The chart post. + * @param string $type The chart type passed to the data filter. + * @param bool $run_filter Whether to run the chart data filter. + * @param bool $sanitize Whether to prepare the cells for HTML-capable renderers; exports and editors need the stored values. + * @return mixed The chart data. */ - public static function get_chart_data( $chart, $type, $run_filter = true ) { + public static function get_chart_data( $chart, $type, $run_filter = true, $sanitize = true ) { // change HTML entities $post_content = html_entity_decode( htmlentities( $chart->post_content ) ); $post_content = preg_replace_callback( @@ -915,7 +921,7 @@ function ( $matches ) { $altered = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, $altered, $chart->ID, $type ); } - return self::sanitize_chart_data( $altered ); + return $sanitize ? self::sanitize_chart_data( $altered ) : $altered; } /** @@ -930,7 +936,7 @@ public static function sanitize_chart_data( $data ) { return map_deep( $data, static function ( $value ) { - if ( ! is_string( $value ) || ! preg_match( '/<\s*\/?\s*[a-zA-Z!][^>]*>/s', $value ) ) { + if ( ! is_string( $value ) || ! preg_match( '/<\s*\/?\s*[a-zA-Z!]/', $value ) ) { return $value; } return wp_kses_post( $value ); diff --git a/classes/Visualizer/Module/Chart.php b/classes/Visualizer/Module/Chart.php index a49654af..c8f951e7 100644 --- a/classes/Visualizer/Module/Chart.php +++ b/classes/Visualizer/Module/Chart.php @@ -70,6 +70,26 @@ public function __construct( Visualizer_Plugin $plugin ) { $this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' ); $this->_addFilter( 'visualizer_get_sidebar', 'getSidebar', 10, 2 ); + + $this->_addAction( 'added_post_meta', 'recordJsonSourceUser', null, 10, 3 ); + $this->_addAction( 'updated_post_meta', 'recordJsonSourceUser', null, 10, 3 ); + } + + /** + * Records the user who set a chart's JSON endpoint as its WooCommerce report user. + * + * A scheduled refresh of that endpoint then uses this user's report access, + * not the access of whoever authorized an earlier endpoint. + * + * @param int $meta_id The meta ID. + * @param int $object_id The post ID. + * @param string $meta_key The meta key. + * @return void + */ + public function recordJsonSourceUser( $meta_id, $object_id, $meta_key ) { + if ( Visualizer_Plugin::CF_JSON_URL === $meta_key ) { + update_post_meta( $object_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, get_current_user_id() ); + } } /** @@ -148,7 +168,6 @@ public function setJsonSchedule() { update_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, get_current_user_id() ); } else { delete_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE ); - delete_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER ); } } @@ -221,7 +240,7 @@ public function getJsonData() { wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) ); } - $data = Visualizer_Render_Layout::show( 'editor-table', $data, $chart_id, 'viz-json-table', false, false ); + $data = Visualizer_Render_Layout::show( 'editor-table', self::sanitize_chart_data( $data ), $chart_id, 'viz-json-table', false, false ); wp_send_json_success( array( 'table' => $data, 'root' => $params['root'], 'url' => $params['url'], 'paging' => $source->getPaginationElements() ) ); } @@ -305,7 +324,7 @@ public function setJsonData() { $render = new Visualizer_Render_Page_Update(); $render->id = $chart->ID; - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ); + $render->data = json_encode( self::sanitize_chart_data( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ) ); $render->series = json_encode( $source->getSeries() ); $render->render(); @@ -1421,7 +1440,7 @@ public function uploadData() { } $render->id = $chart->ID; - $render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ); + $render->data = json_encode( self::sanitize_chart_data( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ) ); $render->series = json_encode( $source->getSeries() ); $render->settings = json_encode( $settings ); } else { @@ -1683,7 +1702,7 @@ public function saveQuery() { 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ), ) ); - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ); + $render->data = json_encode( self::sanitize_chart_data( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ) ); $render->series = json_encode( $source->getSeries() ); $render->id = $chart_id; } else { diff --git a/classes/Visualizer/Render/Layout.php b/classes/Visualizer/Render/Layout.php index 18e0aeb8..33a27edb 100644 --- a/classes/Visualizer/Render/Layout.php +++ b/classes/Visualizer/Render/Layout.php @@ -436,7 +436,7 @@ public static function _renderEditorTable( $args ) { } $chart = get_post( $chart_id ); $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); - $data = Visualizer_Module::get_chart_data( $chart, $type ); + $data = Visualizer_Module::get_chart_data( $chart, $type, true, ! $editable_data ); } else { $headers = array_keys( $data[0] ); } diff --git a/classes/Visualizer/Source/Json.php b/classes/Visualizer/Source/Json.php index ba819ad8..43147ae1 100644 --- a/classes/Visualizer/Source/Json.php +++ b/classes/Visualizer/Source/Json.php @@ -207,6 +207,7 @@ public function getPaginationElements() { * @since ? * * @access public + * @return bool False when a WooCommerce report request failed, true otherwise. */ public function fetch() { $url = $this->_url; @@ -285,7 +286,7 @@ public function fetch() { do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'JSON endpoint data parsed.', 'debug', __FILE__, __LINE__ ); - return true; + return empty( $this->_error ); } /** @@ -399,6 +400,10 @@ private function getJSON( $url = null ) { if ( is_wp_error( $response ) || ! in_array( intval( $response['response']['code'] ), array( 200, 201 ), true ) ) { $error_code = is_wp_error( $response ) ? $response->get_error_code() : (string) wp_remote_retrieve_response_code( $response ); do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Error while fetching JSON endpoint: %s', $error_code ), 'error', __FILE__, __LINE__ ); + if ( $this->is_woocommerce_request( $url ) ) { + // Report access can be missing for this request, so keep the stored chart data. + $this->_error = esc_html__( 'Unable to fetch the WooCommerce report. The user who saved this chart needs access to WooCommerce reports.', 'visualizer' ); + } return null; } diff --git a/classes/Visualizer/Source/Query.php b/classes/Visualizer/Source/Query.php index b08798c8..b72a142a 100644 --- a/classes/Visualizer/Source/Query.php +++ b/classes/Visualizer/Source/Query.php @@ -256,7 +256,7 @@ private function get_col_type( $col_num ) { * @return string */ private function html( $headers, $results ) { - return Visualizer_Render_Layout::show( 'db-wizard-results', $headers, $results ); + return Visualizer_Render_Layout::show( 'db-wizard-results', Visualizer_Module::sanitize_chart_data( $headers ), Visualizer_Module::sanitize_chart_data( $results ) ); } /** diff --git a/js/render-datatables.js b/js/render-datatables.js index 1cb43fc7..923156d0 100644 --- a/js/render-datatables.js +++ b/js/render-datatables.js @@ -138,7 +138,7 @@ } } - // remove this so that the eval does not fail. + // internal_title is the chart's admin label, not a DataTables option. delete chart.settings['internal_title']; var additional = []; diff --git a/tests/test-ajax.php b/tests/test-ajax.php index 61e7dc18..5d92294d 100644 --- a/tests/test-ajax.php +++ b/tests/test-ajax.php @@ -1124,8 +1124,6 @@ public function test_json_schedule_denied_for_chart_user_cannot_edit() { /** * A chart editor without report access cannot schedule a WooCommerce report import. - * - * @group ajax */ public function test_woocommerce_json_schedule_denied_without_report_capability() { $this->enable_pro(); @@ -1151,8 +1149,6 @@ public function test_woocommerce_json_schedule_denied_without_report_capability( /** * A report-capable chart editor can authorize future scheduled imports. - * - * @group ajax */ public function test_woocommerce_json_schedule_records_authorizing_user() { $this->enable_pro(); @@ -1178,6 +1174,158 @@ public function test_woocommerce_json_schedule_records_authorizing_user() { $this->assertSame( $this->admin_user_id, (int) get_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, true ) ); } + /** + * Switching a chart to another JSON source keeps the recorded report user. + */ + public function test_json_schedule_for_other_source_keeps_report_user() { + $this->enable_pro(); + $chart_id = $this->create_chart_for_user( $this->admin_user_id ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, $this->admin_user_id ); + wp_set_current_user( $this->admin_user_id ); + $_POST = array( + 'chart' => $chart_id, + 'time' => 12, + 'is_woocommerce_report' => 'false', + 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE . Visualizer_Plugin::VERSION ), + ); + + try { + $this->_handleAjax( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE ); + } catch ( WPAjaxDieContinueException $e ) { + // Expected after the JSON response. + } + + $this->assertSame( '', get_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ) ); + $this->assertSame( $this->admin_user_id, (int) get_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, true ) ); + } + + /** + * Saving a new JSON endpoint makes the saving user the chart's report user. + */ + public function test_json_source_change_records_saving_user() { + $chart_id = $this->create_chart_for_user( $this->admin_user_id ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, 'https://example.com/old.json' ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, $this->admin_user_id ); + $editor_id = $this->factory->user->create( array( 'role' => 'editor' ) ); + wp_set_current_user( $editor_id ); + + $this->handle_json_set_data( $chart_id, array( 'url' => 'https://example.com/new.json' ) ); + + $this->assertSame( 'https://example.com/new.json', get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, true ) ); + $this->assertSame( $editor_id, (int) get_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, true ) ); + } + + /** + * The JSON import preview table carries no event attributes from the endpoint. + */ + public function test_json_preview_removes_event_attributes() { + $chart_id = $this->create_chart_for_user( $this->admin_user_id ); + wp_set_current_user( $this->admin_user_id ); + $filter = $this->mock_json_endpoint( array( array( 'name' => '' ) ) ); + + $_GET['security'] = wp_create_nonce( Visualizer_Plugin::ACTION_JSON_GET_DATA . Visualizer_Plugin::VERSION ); + $_POST['params'] = array( + 'url' => 'https://example.com/data.json', + 'method' => 'GET', + 'chart' => $chart_id, + 'root' => 'root', + ); + try { + $this->_handleAjax( Visualizer_Plugin::ACTION_JSON_GET_DATA ); + } catch ( WPAjaxDieContinueException $e ) { + // Expected after the JSON response. + } finally { + remove_filter( 'pre_http_request', $filter ); + } + + $response = json_decode( $this->_last_response ); + $this->assertTrue( $response->success, $this->_last_response ); + $this->assertStringContainsString( 'data->table ); + $this->assertStringNotContainsString( 'onerror', $response->data->table ); + } + + /** + * The preview rendered after saving a JSON import carries no event attributes. + */ + public function test_json_save_preview_removes_event_attributes() { + $chart_id = $this->create_chart_for_user( $this->admin_user_id ); + wp_set_current_user( $this->admin_user_id ); + + $this->handle_json_set_data( + $chart_id, + array( + 'header' => array( 'name' ), + 'type' => array( 'name' => 'string' ), + ), + array( array( 'name' => '' ) ) + ); + + $this->assertStringContainsString( 'canvas.data', $this->_last_response ); + $this->assertStringNotContainsString( 'onerror', $this->_last_response ); + } + + /** + * The preview rendered after a CSV upload carries no event attributes. + */ + public function test_csv_upload_preview_removes_event_attributes() { + $chart_id = $this->create_chart_for_user( $this->admin_user_id ); + wp_set_current_user( $this->admin_user_id ); + $file = wp_tempnam( 'visualizer.csv' ); + file_put_contents( $file, "Name,Value\nstring,number\n\"\",1\n" ); + $_FILES = array( + 'local_data' => array( + 'tmp_name' => $file, + 'name' => 'data.csv', + 'error' => 0, + ), + ); + $_GET = array( + 'nonce' => wp_create_nonce( 'visualizer-upload-data' ), + 'chart' => $chart_id, + ); + + try { + $this->_handleAjax( Visualizer_Plugin::ACTION_UPLOAD_DATA ); + } catch ( WPAjaxDieContinueException $e ) { + // Expected once the update page has rendered. + } catch ( WPAjaxDieStopException $e ) { + // Expected when the handler stops after rendering. + } finally { + unlink( $file ); + } + + $this->assertStringContainsString( 'canvas.data', $this->_last_response ); + $this->assertStringNotContainsString( 'onerror', $this->_last_response ); + } + + /** + * The database query preview table carries no event attributes from the results. + */ + public function test_query_preview_removes_event_attributes() { + $this->_setRole( 'administrator' ); + $this->enable_pro(); + $post_id = $this->factory->post->create( array( 'post_title' => '' ) ); + $this->assertStringContainsString( 'onerror', get_post_field( 'post_title', $post_id ) ); + + global $wpdb; + $_GET['security'] = wp_create_nonce( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION ); + $_POST['params'] = array( + 'query' => 'SELECT post_title FROM ' . $wpdb->prefix . 'posts WHERE ID = ' . $post_id, + 'chart_id' => 1, + ); + try { + $this->_handleAjax( Visualizer_Plugin::ACTION_FETCH_DB_DATA ); + } catch ( WPAjaxDieContinueException $e ) { + // Expected after the JSON response. + } + + $response = json_decode( $this->_last_response ); + $this->assertTrue( $response->success, $this->_last_response ); + $this->assertStringContainsString( 'data->table ); + $this->assertStringNotContainsString( 'onerror', $response->data->table ); + } + /** * A user cannot replace another user's JSON chart data. */ @@ -1207,13 +1355,14 @@ public function test_json_set_data_denied_for_chart_user_cannot_edit() { /** * Mock the JSON endpoint so the set-data handler does not hit the network. * + * @param array> $rows The rows the endpoint returns. * @return callable The filter callback, for removal. */ - private function mock_json_endpoint() { - $filter = function () { + private function mock_json_endpoint( array $rows = array( array( 'name' => 'a', 'value' => 1 ) ) ) { + $filter = function () use ( $rows ) { return array( 'headers' => array(), - 'body' => wp_json_encode( array( array( 'name' => 'a', 'value' => 1 ) ) ), + 'body' => wp_json_encode( $rows ), 'response' => array( 'code' => 200, 'message' => '' ), 'cookies' => array(), 'filename' => null, @@ -1226,10 +1375,11 @@ private function mock_json_endpoint() { /** * Run the JSON set-data handler as the current user. * - * @param int $chart_id The chart being saved. - * @param array $post The POST fields to send on top of the defaults. + * @param int $chart_id The chart being saved. + * @param array $post The POST fields to send on top of the defaults. + * @param array> $rows The rows the endpoint returns. */ - private function handle_json_set_data( $chart_id, array $post ) { + private function handle_json_set_data( $chart_id, array $post, array $rows = array( array( 'name' => 'a', 'value' => 1 ) ) ) { $_GET = array( 'chart' => $chart_id, 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_DATA . Visualizer_Plugin::VERSION ), @@ -1246,7 +1396,7 @@ private function handle_json_set_data( $chart_id, array $post ) { $post ); - $filter = $this->mock_json_endpoint(); + $filter = $this->mock_json_endpoint( $rows ); try { $this->_handleAjax( Visualizer_Plugin::ACTION_JSON_SET_DATA ); } catch ( WPAjaxDieContinueException $e ) { diff --git a/tests/test-chart-data-sanitization.php b/tests/test-chart-data-sanitization.php index 0c4897cd..a9ddc067 100644 --- a/tests/test-chart-data-sanitization.php +++ b/tests/test-chart-data-sanitization.php @@ -24,6 +24,7 @@ public function test_chart_data_removes_active_markup() { '', 'Research & Development', '3 < 5', + 'assertStringNotContainsString( 'assertSame( 'Research & Development', $result[0][3] ); $this->assertSame( '3 < 5', $result[0][4] ); + $this->assertStringNotContainsString( ' 123, + 'post_content' => serialize( array( array( 'Revenue' ) ) ), + ); + $filter = array( $this, 'add_script_cell' ); + add_filter( Visualizer_Plugin::FILTER_GET_CHART_DATA, $filter ); + + $result = Visualizer_Module::get_chart_data( $chart, 'table' ); + + remove_filter( Visualizer_Plugin::FILTER_GET_CHART_DATA, $filter ); + $this->assertSame( 'Revenue', $result[0][0] ); + $this->assertStringNotContainsString( 'create_chart( array( array( 'Revenue', '' ) ) ); + $filter = array( $this, 'add_script_cell' ); + add_filter( Visualizer_Plugin::FILTER_GET_CHART_DATA, $filter ); + + $result = Visualizer_Gutenberg_Block::get_instance()->get_visualizer_data( array( 'id' => $chart_id ) ); + + remove_filter( Visualizer_Plugin::FILTER_GET_CHART_DATA, $filter ); + $this->assertSame( 'Revenue', $result['visualizer-data'][0][0] ); + $this->assertStringNotContainsString( 'assertStringNotContainsString( 'create_chart( array( array( 'Q1Q4', '' ) ) ); + $module = Visualizer_Plugin::instance()->getModule( Visualizer_Module_Chart::NAME ); + + $csv = $module->_getDataAs( $chart_id, 'csv' ); + $this->assertStringContainsString( 'Q1Q4', $csv['string'] ); + + $print = $module->_getDataAs( $chart_id, 'print' ); + $this->assertStringNotContainsString( 'onerror', $print['csv'] ); + + $editor = Visualizer_Render_Layout::show( 'editor-table', null, $chart_id, 'viz-html-table', false, true ); + $this->assertStringContainsString( esc_attr( 'Q1Q4' ), $editor ); + } + + /** + * Appends a row with a script cell. + * + * @param array> $data The chart data. + * @return array> + */ + public function add_script_cell( $data ) { + $data[] = array( '' ); + return $data; + } + + /** + * Creates a line chart with the given rows, stored as an administrator would. + * + * @param array> $rows The chart rows. + * @return int The chart ID. + */ + private function create_chart( $rows ) { $author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); - // Stored as an administrator would, so post content filtering leaves the serialized data intact. + // Post content filtering leaves the serialized data intact for an administrator. wp_set_current_user( $author_id ); $chart_id = self::factory()->post->create( array( 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, 'post_status' => 'publish', 'post_author' => $author_id, - 'post_content' => wp_slash( serialize( array( array( 'Revenue', '' ) ) ) ), + 'post_content' => wp_slash( serialize( $rows ) ), ) ); update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, 'line' ); update_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array() ); - update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, array( array( 'label' => 'Label', 'type' => 'string' ) ) ); - - $result = Visualizer_Gutenberg_Block::get_instance()->get_visualizer_data( array( 'id' => $chart_id ) ); - - $this->assertSame( 'Revenue', $result['visualizer-data'][0][0] ); - $this->assertStringNotContainsString( ' 'Label', + 'type' => 'string', + ), + array( + 'label' => 'Value', + 'type' => 'string', + ), + ) + ); + return $chart_id; } } diff --git a/tests/test-remote-fetch.php b/tests/test-remote-fetch.php index 06f7931c..d487c130 100644 --- a/tests/test-remote-fetch.php +++ b/tests/test-remote-fetch.php @@ -708,6 +708,99 @@ public function test_json_source_mints_woocommerce_token_for_authorized_user() { delete_transient( 'visualizer_wc_token_' . $headers['X-Visualizer-Token'] ); } + /** + * The report access filter can grant the token to a user without the capability. + */ + public function test_report_access_filter_can_grant_token() { + $user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); + wp_set_current_user( $user_id ); + add_filter( 'visualizer_can_fetch_woocommerce_reports', '__return_true' ); + + $headers = $this->capture_woocommerce_request_headers(); + + remove_filter( 'visualizer_can_fetch_woocommerce_reports', '__return_true' ); + $this->assertArrayHasKey( 'X-Visualizer-Token', $headers ); + delete_transient( 'visualizer_wc_token_' . $headers['X-Visualizer-Token'] ); + } + + /** + * The report access filter can withhold the token from a user with the capability. + */ + public function test_report_access_filter_can_withhold_token() { + $user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); + $user = new WP_User( $user_id ); + $user->add_cap( 'view_woocommerce_reports' ); + wp_set_current_user( $user_id ); + add_filter( 'visualizer_can_fetch_woocommerce_reports', '__return_false' ); + + $headers = $this->capture_woocommerce_request_headers(); + + remove_filter( 'visualizer_can_fetch_woocommerce_reports', '__return_false' ); + $this->assertArrayNotHasKey( 'X-Visualizer-Token', $headers ); + } + + /** + * A failed WooCommerce report fetch is reported as a failure. + */ + public function test_failed_woocommerce_fetch_returns_false() { + $filter = function () { + return $this->response( 401, array(), '{"code":"woocommerce_rest_cannot_view"}' ); + }; + add_filter( 'pre_http_request', $filter ); + + $source = new Visualizer_Source_Json( + array( + 'url' => home_url( '/wp-json/wc/v3/reports/sales' ), + 'root' => 'root', + ) + ); + $result = $source->fetch(); + + remove_filter( 'pre_http_request', $filter ); + $this->assertFalse( $result ); + $this->assertNotEmpty( $source->get_error() ); + } + + /** + * A visitor's live refresh of a WooCommerce report chart keeps the stored data when the fetch fails. + */ + public function test_visitor_refresh_keeps_stored_woocommerce_data() { + $admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); + wp_set_current_user( $admin_id ); + $content = serialize( array( array( '10.00' ) ) ); + $chart_id = self::factory()->post->create( + array( + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, + 'post_status' => 'publish', + 'post_content' => wp_slash( $content ), + ) + ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, 'Visualizer_Source_Json' ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, home_url( '/wp-json/wc/v3/reports/sales' ) ); + update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_ROOT, 'root' ); + update_post_meta( + $chart_id, + Visualizer_Plugin::CF_SERIES, + array( + array( + 'label' => 'total_sales', + 'type' => 'number', + ), + ) + ); + wp_set_current_user( 0 ); + $filter = function () { + return $this->response( 401, array(), '{"code":"woocommerce_rest_cannot_view"}' ); + }; + add_filter( 'pre_http_request', $filter ); + + apply_filters( 'visualizer_schedule_refresh_chart', get_post( $chart_id ), $chart_id, false ); + + remove_filter( 'pre_http_request', $filter ); + $this->assertSame( $content, get_post_field( 'post_content', $chart_id, 'raw' ) ); + $this->assertNotEmpty( get_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, true ) ); + } + /** * Captures the headers generated for a same-site WooCommerce reports request. * From 765ab3b2a93a5b3bdc4e6f8315632983d0ad8257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Sat, 14 Nov 2026 03:46:30 +0200 Subject: [PATCH 5/5] fix: keep stored values in editing paths and escape editor output Return stored rows to the AI builder and the chart ability, escape the text editor and preview headers, check refresh errors after the last read, and record the report user only when a user saves a different endpoint. Copies of a chart do not carry the original report user. --- classes/Visualizer/Module.php | 17 +++ classes/Visualizer/Module/AIBuilder.php | 4 +- classes/Visualizer/Module/Abilities.php | 4 +- classes/Visualizer/Module/Chart.php | 28 +--- classes/Visualizer/Module/Setup.php | 4 +- classes/Visualizer/Render/Layout.php | 8 +- tests/test-ajax.php | 165 ++++++++++++++++++++++++ tests/test-chart-data-sanitization.php | 26 ++++ tests/test-remote-fetch.php | 44 +++++++ 9 files changed, 268 insertions(+), 32 deletions(-) diff --git a/classes/Visualizer/Module.php b/classes/Visualizer/Module.php index 8fbb8977..d00b2517 100644 --- a/classes/Visualizer/Module.php +++ b/classes/Visualizer/Module.php @@ -924,6 +924,23 @@ function ( $matches ) { return $sanitize ? self::sanitize_chart_data( $altered ) : $altered; } + /** + * Saves a chart's JSON endpoint, recording the user who changes it as the WooCommerce report user. + * + * A scheduled refresh of the endpoint then uses this user's report access, + * not the access of whoever authorized an earlier endpoint. + * + * @param int $chart_id The chart ID. + * @param string $url The JSON endpoint. + * @return void + */ + public static function update_json_url( $chart_id, $url ) { + if ( get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, true ) !== $url ) { + update_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, get_current_user_id() ); + } + update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, $url ); + } + /** * Sanitize chart data before passing it to HTML-capable renderers. * diff --git a/classes/Visualizer/Module/AIBuilder.php b/classes/Visualizer/Module/AIBuilder.php index c97be184..931e7814 100644 --- a/classes/Visualizer/Module/AIBuilder.php +++ b/classes/Visualizer/Module/AIBuilder.php @@ -195,7 +195,7 @@ public function fetchChart(): void { $this->_verify_chart_access( $chart_id ); $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ); - $data = Visualizer_Module::get_chart_data( $chart, '', false ); + $data = Visualizer_Module::get_chart_data( $chart, '', false, false ); $code = get_post_meta( $chart_id, self::CF_D3_CODE, true ); $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ); $title = ( is_array( $settings ) && ! empty( $settings['backend-title'] ) ) @@ -360,7 +360,7 @@ public function uploadData(): void { $source = new Visualizer_Source_Json( $params ); // Store config for sync - update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, $params['url'] ); + Visualizer_Module::update_json_url( $chart_id, $params['url'] ); update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] ); if ( ! empty( $_POST['json_schedule'] ) ) { update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, intval( $_POST['json_schedule'] ) ); diff --git a/classes/Visualizer/Module/Abilities.php b/classes/Visualizer/Module/Abilities.php index 95c2cb43..87aefe17 100644 --- a/classes/Visualizer/Module/Abilities.php +++ b/classes/Visualizer/Module/Abilities.php @@ -598,7 +598,7 @@ public function executeGetChart( $input = array() ) { $type = (string) get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type ); - $data = self::get_chart_data( $chart, $type ); + $data = self::get_chart_data( $chart, $type, true, false ); $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type ); if ( ! is_array( $settings ) ) { @@ -1048,7 +1048,7 @@ private function setJsonSource( $chart, $input, $hours, $dry_run ) { $this->clearSourceMeta( $chart->ID, true ); update_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ); $this->persistSource( $chart->ID, $source ); - update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, $params['url'] ); + self::update_json_url( $chart->ID, $params['url'] ); update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] ); $headers = array( 'method' => $params['method'] ); diff --git a/classes/Visualizer/Module/Chart.php b/classes/Visualizer/Module/Chart.php index c8f951e7..34d615ab 100644 --- a/classes/Visualizer/Module/Chart.php +++ b/classes/Visualizer/Module/Chart.php @@ -70,26 +70,6 @@ public function __construct( Visualizer_Plugin $plugin ) { $this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' ); $this->_addFilter( 'visualizer_get_sidebar', 'getSidebar', 10, 2 ); - - $this->_addAction( 'added_post_meta', 'recordJsonSourceUser', null, 10, 3 ); - $this->_addAction( 'updated_post_meta', 'recordJsonSourceUser', null, 10, 3 ); - } - - /** - * Records the user who set a chart's JSON endpoint as its WooCommerce report user. - * - * A scheduled refresh of that endpoint then uses this user's report access, - * not the access of whoever authorized an earlier endpoint. - * - * @param int $meta_id The meta ID. - * @param int $object_id The post ID. - * @param string $meta_key The meta key. - * @return void - */ - public function recordJsonSourceUser( $meta_id, $object_id, $meta_key ) { - if ( Visualizer_Plugin::CF_JSON_URL === $meta_key ) { - update_post_meta( $object_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, get_current_user_id() ); - } } /** @@ -273,7 +253,7 @@ public function setJsonData() { update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); - update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, $params['url'] ); + self::update_json_url( $chart->ID, $params['url'] ); update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] ); delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_HEADERS ); @@ -651,7 +631,8 @@ public function renderChartPages() { $post_meta = get_post_meta( $parent_chart_id ); $chart_id = $new_chart_id; foreach ( $post_meta as $key => $value ) { - if ( strpos( $key, 'visualizer-' ) !== false ) { + // A copy refreshes reports with its own author's access. + if ( strpos( $key, 'visualizer-' ) !== false && Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER !== $key ) { add_post_meta( $new_chart_id, $key, self::maybe_decode_content( $value[0] ) ); } } @@ -1495,7 +1476,8 @@ public function cloneChart() { } else { $post_meta = get_post_meta( $chart_id ); foreach ( $post_meta as $key => $value ) { - if ( strpos( $key, 'visualizer-' ) !== false ) { + // A copy refreshes reports with its own author's access. + if ( strpos( $key, 'visualizer-' ) !== false && Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER !== $key ) { add_post_meta( $new_chart_id, $key, self::maybe_decode_content( $value[0] ) ); } } diff --git a/classes/Visualizer/Module/Setup.php b/classes/Visualizer/Module/Setup.php index 00a3fbca..3f530b35 100644 --- a/classes/Visualizer/Module/Setup.php +++ b/classes/Visualizer/Module/Setup.php @@ -384,6 +384,8 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) { return $chart; } + // Editable-table charts fetch again here, so check the error after this read. + $content = $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ); $error = $source->get_error(); if ( empty( $error ) ) { $this->disableRevisionsTemporarily(); @@ -406,7 +408,7 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) { wp_update_post( array( 'ID' => $chart_id, - 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ), + 'post_content' => $content, ) ); diff --git a/classes/Visualizer/Render/Layout.php b/classes/Visualizer/Render/Layout.php index 33a27edb..ed9b5b21 100644 --- a/classes/Visualizer/Render/Layout.php +++ b/classes/Visualizer/Render/Layout.php @@ -411,7 +411,7 @@ public static function _renderTextEditor( $args ) { } ?>
- +
'; } else { - echo '' . $header . ''; + echo '' . esc_html( $header ) . ''; } } ?> @@ -479,8 +479,8 @@ public static function _renderEditorTable( $args ) { if ( $editable_data ) { echo ''; - echo ''; + echo '