Skip to content

Commit 4cd38fe

Browse files
release: fixes
- Added a Help panel to make it easier to contact support and find answers - Enhanced security - Updated dependencies
2 parents 59c30d4 + 25ab208 commit 4cd38fe

28 files changed

Lines changed: 1216 additions & 110 deletions

‎classes/Visualizer/Gutenberg/Block.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,14 @@ public function get_visualizer_data( $post ) {
327327
$data['visualizer-settings'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $data['visualizer-settings'], $post_id, $data['visualizer-chart-type'] );
328328

329329
// handle data filter hooks
330-
$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'] );
330+
$data['visualizer-data'] = Visualizer_Module::sanitize_chart_data(
331+
apply_filters(
332+
Visualizer_Plugin::FILTER_GET_CHART_DATA,
333+
Visualizer_Module::decode_content( html_entity_decode( get_post_field( 'post_content', $post_id, 'raw' ) ) ),
334+
$post_id,
335+
$data['visualizer-chart-type']
336+
)
337+
);
331338

332339
// we are going to format only for tabular charts, because we are not sure of the effect on others.
333340
// this is to solve the case where boolean data shows up as all-ticks on gutenberg.

‎classes/Visualizer/Module.php‎

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function _getDataAs( $chart_id, $type ) {
190190
$settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
191191
$rows = array();
192192
$series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
193-
$data = self::get_chart_data( $chart, $type, false );
193+
$data = self::get_chart_data( $chart, $type, false, 'print' === $type );
194194
if ( ! empty( $series ) ) {
195195
$row = array();
196196
foreach ( $series as $array ) {
@@ -880,8 +880,14 @@ public static function maybe_decode_content( $value ) {
880880

881881
/**
882882
* Gets the chart content after common manipulations.
883+
*
884+
* @param WP_Post|object $chart The chart post.
885+
* @param string $type The chart type passed to the data filter.
886+
* @param bool $run_filter Whether to run the chart data filter.
887+
* @param bool $sanitize Whether to prepare the cells for HTML-capable renderers; exports and editors need the stored values.
888+
* @return mixed The chart data.
883889
*/
884-
public static function get_chart_data( $chart, $type, $run_filter = true ) {
890+
public static function get_chart_data( $chart, $type, $run_filter = true, $sanitize = true ) {
885891
// change HTML entities
886892
$post_content = html_entity_decode( htmlentities( $chart->post_content ) );
887893
$post_content = preg_replace_callback(
@@ -912,9 +918,47 @@ function ( $matches ) {
912918
$altered = $data;
913919
}
914920
if ( $run_filter ) {
915-
return apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, $altered, $chart->ID, $type );
921+
$altered = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, $altered, $chart->ID, $type );
922+
}
923+
924+
return $sanitize ? self::sanitize_chart_data( $altered ) : $altered;
925+
}
926+
927+
/**
928+
* Saves a chart's JSON endpoint, recording the user who changes it as the WooCommerce report user.
929+
*
930+
* A scheduled refresh of the endpoint then uses this user's report access,
931+
* not the access of whoever authorized an earlier endpoint.
932+
*
933+
* @param int $chart_id The chart ID.
934+
* @param string $url The JSON endpoint.
935+
* @return void
936+
*/
937+
public static function update_json_url( $chart_id, $url ) {
938+
if ( get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, true ) !== $url ) {
939+
update_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, get_current_user_id() );
916940
}
917-
return $altered;
941+
update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, $url );
942+
}
943+
944+
/**
945+
* Sanitize chart data before passing it to HTML-capable renderers.
946+
*
947+
* @param mixed $data Chart data.
948+
* @return mixed Sanitized chart data.
949+
*/
950+
public static function sanitize_chart_data( $data ) {
951+
// Preserve normal text and supported formatting while removing active
952+
// markup from imports, scheduled remote sources, and filtered data.
953+
return map_deep(
954+
$data,
955+
static function ( $value ) {
956+
if ( ! is_string( $value ) || ! preg_match( '/<\s*\/?\s*[a-zA-Z!]/', $value ) ) {
957+
return $value;
958+
}
959+
return wp_kses_post( $value );
960+
}
961+
);
918962
}
919963

920964
/**

‎classes/Visualizer/Module/AIBuilder.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function fetchChart(): void {
195195
$this->_verify_chart_access( $chart_id );
196196

197197
$series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
198-
$data = Visualizer_Module::get_chart_data( $chart, '', false );
198+
$data = Visualizer_Module::get_chart_data( $chart, '', false, false );
199199
$code = get_post_meta( $chart_id, self::CF_D3_CODE, true );
200200
$settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
201201
$title = ( is_array( $settings ) && ! empty( $settings['backend-title'] ) )
@@ -360,7 +360,7 @@ public function uploadData(): void {
360360
$source = new Visualizer_Source_Json( $params );
361361

362362
// Store config for sync
363-
update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, $params['url'] );
363+
Visualizer_Module::update_json_url( $chart_id, $params['url'] );
364364
update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] );
365365
if ( ! empty( $_POST['json_schedule'] ) ) {
366366
update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, intval( $_POST['json_schedule'] ) );

‎classes/Visualizer/Module/Abilities.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ public function executeGetChart( $input = array() ) {
598598

599599
$type = (string) get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
600600
$series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
601-
$data = self::get_chart_data( $chart, $type );
601+
$data = self::get_chart_data( $chart, $type, true, false );
602602
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
603603
$settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
604604
if ( ! is_array( $settings ) ) {
@@ -1048,7 +1048,7 @@ private function setJsonSource( $chart, $input, $hours, $dry_run ) {
10481048
$this->clearSourceMeta( $chart->ID, true );
10491049
update_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true );
10501050
$this->persistSource( $chart->ID, $source );
1051-
update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, $params['url'] );
1051+
self::update_json_url( $chart->ID, $params['url'] );
10521052
update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] );
10531053

10541054
$headers = array( 'method' => $params['method'] );

‎classes/Visualizer/Module/Admin.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,8 @@ public function enqueueSettingsScripts( string $hook_suffix ): void {
11191119
}
11201120
wp_enqueue_style( 'wp-color-picker' );
11211121
wp_enqueue_script( 'wp-color-picker' );
1122+
1123+
do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'settings' );
11221124
}
11231125

11241126
/**
@@ -1409,7 +1411,7 @@ public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
14091411
$is_black_friday = apply_filters( 'themeisle_sdk_is_black_friday_sale', false );
14101412
// knowledge base link
14111413
$plugin_meta[] = sprintf(
1412-
'<a href="' . VISUALIZER_MAIN_DOC . '" target="_blank">%s</a>',
1414+
'<a href="' . esc_url( tsdk_utmify( VISUALIZER_MAIN_DOC, 'documentation', 'pluginrow' ) ) . '" target="_blank">%s</a>',
14131415
esc_html__( 'Docs', 'visualizer' )
14141416
);
14151417
if ( ! $is_black_friday ) {
@@ -1609,7 +1611,7 @@ public function add_black_friday_data( $configs ) {
16091611
$pro_product_slug = defined( 'VISUALIZER_PRO_BASEFILE' ) ? basename( dirname( VISUALIZER_PRO_BASEFILE ) ) : '';
16101612

16111613
$is_pro = 'valid' === $status;
1612-
$is_expired = 'expired' === $status || 'active-expired' === $status;
1614+
$is_expired = in_array( $status, array( 'expired', 'active_expired', 'active-expired' ), true );
16131615

16141616
if ( $is_pro ) {
16151617
// translators: %s is the discount percentage.

‎classes/Visualizer/Module/Chart.php‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ public function setJsonSchedule() {
138138
);
139139

140140
if ( Visualizer_Module::is_pro() ) {
141-
$is_woocommerce_report = filter_input(
142-
INPUT_POST,
143-
'is_woocommerce_report',
144-
FILTER_VALIDATE_BOOLEAN
145-
);
141+
$is_woocommerce_report = isset( $_POST['is_woocommerce_report'] ) ? filter_var( wp_unslash( $_POST['is_woocommerce_report'] ), FILTER_VALIDATE_BOOLEAN ) : false;
146142

147143
if ( $is_woocommerce_report ) {
144+
if ( ! current_user_can( 'view_woocommerce_reports' ) ) {
145+
wp_send_json_error( array( 'msg' => esc_html__( 'You do not have permission to access WooCommerce reports.', 'visualizer' ) ), 403 );
146+
}
148147
update_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
148+
update_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, get_current_user_id() );
149149
} else {
150150
delete_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE );
151151
}
@@ -220,7 +220,7 @@ public function getJsonData() {
220220
wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) );
221221
}
222222

223-
$data = Visualizer_Render_Layout::show( 'editor-table', $data, $chart_id, 'viz-json-table', false, false );
223+
$data = Visualizer_Render_Layout::show( 'editor-table', self::sanitize_chart_data( $data ), $chart_id, 'viz-json-table', false, false );
224224
wp_send_json_success( array( 'table' => $data, 'root' => $params['root'], 'url' => $params['url'], 'paging' => $source->getPaginationElements() ) );
225225
}
226226

@@ -253,7 +253,7 @@ public function setJsonData() {
253253
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
254254
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
255255
update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
256-
update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, $params['url'] );
256+
self::update_json_url( $chart->ID, $params['url'] );
257257
update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] );
258258

259259
delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_HEADERS );
@@ -304,7 +304,7 @@ public function setJsonData() {
304304

305305
$render = new Visualizer_Render_Page_Update();
306306
$render->id = $chart->ID;
307-
$render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
307+
$render->data = json_encode( self::sanitize_chart_data( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ) );
308308
$render->series = json_encode( $source->getSeries() );
309309
$render->render();
310310

@@ -631,7 +631,8 @@ public function renderChartPages() {
631631
$post_meta = get_post_meta( $parent_chart_id );
632632
$chart_id = $new_chart_id;
633633
foreach ( $post_meta as $key => $value ) {
634-
if ( strpos( $key, 'visualizer-' ) !== false ) {
634+
// A copy refreshes reports with its own author's access.
635+
if ( strpos( $key, 'visualizer-' ) !== false && Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER !== $key ) {
635636
add_post_meta( $new_chart_id, $key, self::maybe_decode_content( $value[0] ) );
636637
}
637638
}
@@ -1420,7 +1421,7 @@ public function uploadData() {
14201421
}
14211422

14221423
$render->id = $chart->ID;
1423-
$render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
1424+
$render->data = json_encode( self::sanitize_chart_data( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ) );
14241425
$render->series = json_encode( $source->getSeries() );
14251426
$render->settings = json_encode( $settings );
14261427
} else {
@@ -1475,7 +1476,8 @@ public function cloneChart() {
14751476
} else {
14761477
$post_meta = get_post_meta( $chart_id );
14771478
foreach ( $post_meta as $key => $value ) {
1478-
if ( strpos( $key, 'visualizer-' ) !== false ) {
1479+
// A copy refreshes reports with its own author's access.
1480+
if ( strpos( $key, 'visualizer-' ) !== false && Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER !== $key ) {
14791481
add_post_meta( $new_chart_id, $key, self::maybe_decode_content( $value[0] ) );
14801482
}
14811483
}
@@ -1682,7 +1684,7 @@ public function saveQuery() {
16821684
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
16831685
)
16841686
);
1685-
$render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
1687+
$render->data = json_encode( self::sanitize_chart_data( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ) );
16861688
$render->series = json_encode( $source->getSeries() );
16871689
$render->id = $chart_id;
16881690
} else {

‎classes/Visualizer/Module/Setup.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) {
384384
return $chart;
385385
}
386386

387+
// Editable-table charts fetch again here, so check the error after this read.
388+
$content = $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
387389
$error = $source->get_error();
388390
if ( empty( $error ) ) {
389391
$this->disableRevisionsTemporarily();
@@ -406,7 +408,7 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) {
406408
wp_update_post(
407409
array(
408410
'ID' => $chart_id,
409-
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
411+
'post_content' => $content,
410412
)
411413
);
412414

‎classes/Visualizer/Plugin.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class Visualizer_Plugin {
106106
const CF_CHART_CACHE = 'visualizer-chart-cache';
107107
const CF_JSON_WOOCOMMERCE_SOURCE = 'visualizer-woocommerce-source';
108108
const CF_IS_WOOCOMMERCE_SOURCE = 'visualizer-is-woocommerce-source';
109+
const CF_WOOCOMMERCE_REPORT_USER = 'visualizer-woocommerce-report-user';
109110

110111
/**
111112
* Name of the option for WordPress DB.

0 commit comments

Comments
 (0)