Skip to content

Commit c01f0ec

Browse files
lucadobrescuclaude
andcommitted
fix: harden unserialize() against PHP object injection
Add array( 'allowed_classes' => false ) to every raw unserialize() of chart post_content / fetched source content, preventing PHP object injection when combined with the broken access control write path. Sinks fixed: - classes/Visualizer/Source/Csv/Remote.php:77 (issue #596) - classes/Visualizer/Module/Chart.php:1339 (issue #596) - classes/Visualizer/Module.php:796 get_chart_data() - classes/Visualizer/Module/Utility.php:437 pie/polarArea colors - classes/Visualizer/Gutenberg/Block.php:310 block render Behavior-preserving: all sinks expect a plain array. The last three are the same sink class found in passing, hardened for defence-in-depth. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 6bad282 commit c01f0ec

5 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎classes/Visualizer/Gutenberg/Block.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function get_visualizer_data( $post ) {
307307
$data['visualizer-settings'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $data['visualizer-settings'], $post_id, $data['visualizer-chart-type'] );
308308

309309
// handle data filter hooks
310-
$data['visualizer-data'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( get_the_content( $post_id ) ) ), $post_id, $data['visualizer-chart-type'] );
310+
$data['visualizer-data'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( get_the_content( $post_id ) ), array( 'allowed_classes' => false ) ), $post_id, $data['visualizer-chart-type'] );
311311

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

‎classes/Visualizer/Module.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ function ( $matches ) {
793793
},
794794
$post_content
795795
);
796-
$data = unserialize( $post_content );
796+
$data = unserialize( $post_content, array( 'allowed_classes' => false ) );
797797
$altered = array();
798798
if ( ! empty( $data ) ) {
799799
foreach ( $data as $index => $array ) {

‎classes/Visualizer/Module/Chart.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,8 @@ public function uploadData() {
13361336
if ( $source->fetch() ) {
13371337
$content = $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
13381338
$populate = true;
1339-
if ( is_string( $content ) && is_array( unserialize( $content ) ) ) {
1340-
$json = unserialize( $content );
1339+
$json = is_string( $content ) ? unserialize( $content, array( 'allowed_classes' => false ) ) : false;
1340+
if ( is_array( $json ) ) {
13411341
// if source exists, so should data. if source exists but data is blank, do not populate the chart.
13421342
// if we populate the data even if it is empty, the chart will show "Table has no columns".
13431343
if ( array_key_exists( 'source', $json ) && ! empty( $json['source'] ) && ( ! array_key_exists( 'data', $json ) || empty( $json['data'] ) ) ) {

‎classes/Visualizer/Module/Utility.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ private static function set_defaults_chartjs( $chart, $post_status ) {
434434
case 'polarArea':
435435
// fall through.
436436
case 'pie':
437-
$data = unserialize( $chart->post_content );
437+
$data = unserialize( $chart->post_content, array( 'allowed_classes' => false ) );
438438
$name = 'slices';
439439
$max = count( $data );
440440
// fall through.

‎classes/Visualizer/Source/Csv/Remote.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private function _repopulate( $chart_id ) {
7474
// if filename is empty, extract it from chart content
7575
if ( empty( $this->_filename ) ) {
7676
$chart = get_post( $chart_id );
77-
$data = unserialize( html_entity_decode( $chart->post_content ) );
77+
$data = unserialize( html_entity_decode( $chart->post_content ), array( 'allowed_classes' => false ) );
7878
if ( ! isset( $data['source'] ) ) {
7979
return false;
8080
}

0 commit comments

Comments
 (0)