Skip to content

Commit 8ebc6f7

Browse files
Merge pull request #1249 from Codeinwp/bugfix/pro/516
Prevent unauthorized users from updating chart data
2 parents f0f4e28 + f5f9c7a commit 8ebc6f7

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public function getCharts() {
379379
*
380380
* @return array The array of chart data.
381381
*/
382-
private function _getChartArray( ?WP_Post $chart = null ) {
382+
private function _getChartArray( $chart = null ) {
383383
if ( is_null( $chart ) ) {
384384
$chart = $this->_chart;
385385
}
@@ -1141,7 +1141,11 @@ public function uploadData() {
11411141
$can_die = ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE );
11421142

11431143
// validate nonce
1144-
if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) {
1144+
if (
1145+
! isset( $_GET['nonce'] ) ||
1146+
! wp_verify_nonce( $_GET['nonce'], 'visualizer-upload-data' ) ||
1147+
! current_user_can( 'edit_posts' )
1148+
) {
11451149
if ( ! $can_die ) {
11461150
return;
11471151
}
@@ -1152,7 +1156,12 @@ public function uploadData() {
11521156
// check chart, if chart exists
11531157
// do not use filter_input as it does not work for phpunit test cases, use filter_var instead
11541158
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
1155-
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
1159+
if (
1160+
! $chart_id ||
1161+
! ( $chart = get_post( $chart_id ) ) ||
1162+
$chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ||
1163+
! current_user_can( 'edit_post', $chart_id )
1164+
) {
11561165
if ( ! $can_die ) {
11571166
return;
11581167
}

classes/Visualizer/Render/Layout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public static function _renderSimpleEditorScreen( $args ) {
360360
add_query_arg(
361361
array(
362362
'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
363-
'nonce' => wp_create_nonce(),
363+
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
364364
'chart' => $chart_id,
365365
),
366366
admin_url( 'admin-ajax.php' )
@@ -726,7 +726,7 @@ public static function _renderTabBasic( $args ) {
726726
add_query_arg(
727727
array(
728728
'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
729-
'nonce' => wp_create_nonce(),
729+
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
730730
'chart' => $chart_id,
731731
),
732732
admin_url( 'admin-ajax.php' )

classes/Visualizer/Render/Page/Types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Visualizer_Render_Page_Types extends Visualizer_Render_Page {
3939
*/
4040
protected function _toHTML() {
4141
echo '<form method="post" id="viz-types-form">';
42-
echo '<input type="hidden" name="nonce" value="', wp_create_nonce(), '">';
42+
echo '<input type="hidden" name="nonce" value="', wp_create_nonce( 'visualizer-upload-data' ), '">';
4343
parent::_toHTML();
4444
echo '</form>';
4545
}

tests/test-import.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function test_url_import( $url, $content, $series ) {
8989
'remote_data' => $url,
9090
);
9191
$_GET = array(
92-
'nonce' => wp_create_nonce(),
92+
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
9393
'chart' => $this->chart,
9494
);
9595
// swallow the output
@@ -163,7 +163,7 @@ public function test_file_import( $file, $content, $series ) {
163163
),
164164
);
165165
$_GET = array(
166-
'nonce' => wp_create_nonce(),
166+
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
167167
'chart' => $this->chart,
168168
);
169169
// swallow the output

tests/test-revisions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function test_chart_edit_cancel( $file_orig, $file_new ) {
7979
),
8080
);
8181
$_GET = array(
82-
'nonce' => wp_create_nonce(),
82+
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
8383
'chart' => $this->chart,
8484
'tab' => 'type',
8585
);
@@ -151,7 +151,7 @@ public function test_chart_edit_again( $file_orig, $file_new ) {
151151
),
152152
);
153153
$_GET = array(
154-
'nonce' => wp_create_nonce(),
154+
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
155155
'chart' => $this->chart,
156156
'tab' => 'type',
157157
);
@@ -218,7 +218,7 @@ public function test_chart_edit_save( $file_orig, $file_new ) {
218218
),
219219
);
220220
$_GET = array(
221-
'nonce' => wp_create_nonce(),
221+
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
222222
'chart' => $this->chart,
223223
'tab' => 'type',
224224
);

0 commit comments

Comments
 (0)