Skip to content

Commit cb4d9d9

Browse files
committed
Add nonce verification for admin list
1 parent bb690c1 commit cb4d9d9

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

plugins/wpgraphql-logging/src/Admin/View/List/ListTable.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public function __construct(
6060
* @psalm-suppress PossiblyInvalidCast
6161
*/
6262
public function prepare_items(): void {
63+
if ( array_key_exists( 'orderby', $_REQUEST ) || array_key_exists( 'order', $_REQUEST ) ) {
64+
check_admin_referer( 'wpgraphql-logging-sort' );
65+
}
66+
6367
$this->process_bulk_action();
6468
$this->_column_headers =
6569
apply_filters(

plugins/wpgraphql-logging/src/Admin/View/Templates/WPGraphQLLoggerList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<hr class="wp-header-end">
2323

2424
<form method="post">
25+
<?php wp_nonce_field( 'wpgraphql-logging-sort', 'wpgraphql-logging-sort-nonce' ); ?>
2526
<?php
2627
$list_table->prepare_items();
2728
$list_table->display();

plugins/wpgraphql-logging/src/Admin/ViewLogsPage.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ public function enqueue_admin_scripts( string $hook_suffix ): void {
134134
'jQuery(document).ready(function($){ $(".wpgraphql-logging-datepicker").datetimepicker({ dateFormat: "yy-mm-dd", timeFormat: "HH:mm:ss" }); });'
135135
);
136136

137+
// Add nonce to sorting links.
138+
wp_add_inline_script(
139+
'jquery',
140+
'jQuery(document).ready(function($){
141+
var nonce = $("#wpgraphql-logging-sort-nonce").val();
142+
if ( nonce ) {
143+
$("th.sortable a").each(function(){
144+
this.href = this.href + "&_wpnonce=" + nonce;
145+
});
146+
}
147+
});'
148+
);
149+
137150
// Allow other plugins to enqueue their own scripts/styles.
138151
do_action( 'wpgraphql_logging_view_logs_admin_enqueue_scripts', $hook_suffix );
139152
}

0 commit comments

Comments
 (0)