Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions classes/Visualizer/Module/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public function getCharts() {
*
* @return array The array of chart data.
*/
private function _getChartArray( ?WP_Post $chart = null ) {
private function _getChartArray( $chart = null ) {
if ( is_null( $chart ) ) {
$chart = $this->_chart;
}
Expand Down Expand Up @@ -1139,7 +1139,11 @@ public function uploadData() {
$can_die = ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE );

// validate nonce
if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) {
if (
! isset( $_GET['nonce'] ) ||
! wp_verify_nonce( $_GET['nonce'], 'visualizer-upload-data' ) ||
! current_user_can( 'edit_posts' )
) {
if ( ! $can_die ) {
return;
}
Expand All @@ -1150,7 +1154,12 @@ public function uploadData() {
// check chart, if chart exists
// do not use filter_input as it does not work for phpunit test cases, use filter_var instead
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
if (
! $chart_id ||
! ( $chart = get_post( $chart_id ) ) ||
$chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ||
! current_user_can( 'edit_post', $chart_id )
) {
if ( ! $can_die ) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions classes/Visualizer/Render/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public static function _renderSimpleEditorScreen( $args ) {
add_query_arg(
array(
'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
'nonce' => wp_create_nonce(),
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
'chart' => $chart_id,
),
admin_url( 'admin-ajax.php' )
Expand Down Expand Up @@ -726,7 +726,7 @@ public static function _renderTabBasic( $args ) {
add_query_arg(
array(
'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
'nonce' => wp_create_nonce(),
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
'chart' => $chart_id,
),
admin_url( 'admin-ajax.php' )
Expand Down
2 changes: 1 addition & 1 deletion classes/Visualizer/Render/Page/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Visualizer_Render_Page_Types extends Visualizer_Render_Page {
*/
protected function _toHTML() {
echo '<form method="post" id="viz-types-form">';
echo '<input type="hidden" name="nonce" value="', wp_create_nonce(), '">';
echo '<input type="hidden" name="nonce" value="', wp_create_nonce( 'visualizer-upload-data' ), '">';
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nonce is created with the action 'visualizer-upload-data', but the corresponding verification in _handleTypesPage (classes/Visualizer/Module/Chart.php:956) calls wp_verify_nonce without providing an action parameter. This mismatch will cause nonce verification to fail. Either use a different action that matches what _handleTypesPage expects (no action), or update _handleTypesPage to verify with the same action parameter.

Suggested change
echo '<input type="hidden" name="nonce" value="', wp_create_nonce( 'visualizer-upload-data' ), '">';
echo '<input type="hidden" name="nonce" value="', wp_create_nonce(), '">';

Copilot uses AI. Check for mistakes.
parent::_toHTML();
echo '</form>';
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function test_url_import( $url, $content, $series ) {
'remote_data' => $url,
);
$_GET = array(
'nonce' => wp_create_nonce(),
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
'chart' => $this->chart,
);
// swallow the output
Expand Down Expand Up @@ -163,7 +163,7 @@ public function test_file_import( $file, $content, $series ) {
),
);
$_GET = array(
'nonce' => wp_create_nonce(),
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
'chart' => $this->chart,
);
// swallow the output
Expand Down
6 changes: 3 additions & 3 deletions tests/test-revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function test_chart_edit_cancel( $file_orig, $file_new ) {
),
);
$_GET = array(
'nonce' => wp_create_nonce(),
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
'chart' => $this->chart,
'tab' => 'type',
);
Expand Down Expand Up @@ -151,7 +151,7 @@ public function test_chart_edit_again( $file_orig, $file_new ) {
),
);
$_GET = array(
'nonce' => wp_create_nonce(),
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
'chart' => $this->chart,
'tab' => 'type',
);
Expand Down Expand Up @@ -218,7 +218,7 @@ public function test_chart_edit_save( $file_orig, $file_new ) {
),
);
$_GET = array(
'nonce' => wp_create_nonce(),
'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
'chart' => $this->chart,
'tab' => 'type',
);
Expand Down
Loading