Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/wp-rest-api-log/admin/class-wp-rest-api-log-admin.php
+++ b/wp-rest-api-log/admin/class-wp-rest-api-log-admin.php
@@ -7,6 +7,13 @@
class WP_REST_API_Log_Admin {
/**
+ * Hook suffix for the hidden log entry view page, set in admin_menu().
+ *
+ * @var string|false
+ */
+ static public $view_entry_hook = false;
+
+ /**
* Wire up WordPress hooks and filters.
*
* @return void
@@ -34,7 +41,7 @@
*/
static public function admin_menu() {
- add_submenu_page(
+ self::$view_entry_hook = add_submenu_page(
'',
__( 'REST API Log Entries', 'wp-rest-api-log' ),
'',
@@ -43,6 +50,13 @@
array( __CLASS__, 'display_log_entry')
);
+ // The view entry page has no parent menu, so WordPress core never resolves
+ // a page title for it. Set one early to avoid a null value being passed to
+ // strip_tags() in wp-admin/admin-header.php.
+ if ( ! empty( self::$view_entry_hook ) ) {
+ add_action( 'load-' . self::$view_entry_hook, array( __CLASS__, 'set_view_entry_title' ) );
+ }
+
global $submenu;
if ( ! empty( $submenu['tools.php'] ) ) {
foreach ( $submenu['tools.php'] as &$item ) {
@@ -107,6 +121,17 @@
}
/**
+ * Sets the global $title for the log entry view page before WordPress
+ * core computes the admin page title.
+ *
+ * @return void
+ */
+ static public function set_view_entry_title() {
+ global $title;
+ $title = __( 'REST API Log Entry', 'wp-rest-api-log' );
+ }
+
+ /**
* Displays the log entry template
*
* @return void
@@ -164,17 +189,17 @@
/**
- * Adjusts the title tag when viewing a log entry
+ * Adjusts the title tag when viewing a log entry.
+ *
+ * No longer needs a special case for the log entry view screen:
+ * set_view_entry_title() already sets the correct $title for that
+ * screen, so core's own title-building logic handles it.
*
* @param string $admin_title
* @param string $title
* @return string
*/
static public function admin_title( $admin_title, $title ) {
- $screen = get_current_screen();
- if ( ! empty( $screen ) && 'tools_page_wp-rest-api-log-view-entry' === $screen->id ) {
- $admin_title = __( 'REST API Log Entry', 'wp-rest-api-log' ) . $admin_title;
- }
return $admin_title;
}
--- a/wp-rest-api-log/admin/partials/wp-rest-api-log-display-entries-ajax-wait.php
+++ b/wp-rest-api-log/admin/partials/wp-rest-api-log-display-entries-ajax-wait.php
@@ -0,0 +1 @@
+<img class="ajax-wait collapsed" src="<?php echo plugin_dir_url( dirname( __FILE__ ) ) . 'images/ajax-wait.svg'; ?>" />
No newline at end of file
--- a/wp-rest-api-log/admin/partials/wp-rest-api-log-display-entries-table-row.php
+++ b/wp-rest-api-log/admin/partials/wp-rest-api-log-display-entries-table-row.php
@@ -0,0 +1,66 @@
+<?php
+global $wp_rest_api_log_display_entry;
+$e = $wp_rest_api_log_display_entry;
+?>
+<tr class="entry-row entry-row-<?php echo esc_attr( $e->id ); ?>" data-id="<?php echo esc_attr( $e->id ); ?>">
+ <td class="time">
+ <?php include plugin_dir_path( __FILE__ ) . 'wp-rest-api-log-display-entries-ajax-wait.php'; ?>
+ <?php echo esc_html( mysql2date( get_option( 'date_format'), $e->time ) ); ?> <?php echo esc_html( mysql2date( 'H:i:s', $e->time ) ); ?>
+
+ <div class="row-actions">
+ <span class="view permalink">
+ <a href="<?php echo esc_url( $e->permalink ); ?>" class="permalink"><?php _e( 'Permalink ') ?></a>
+ </span>
+ </div>
+
+ </td>
+ <td class-"method"><?php echo esc_html( $e->method ); ?></td>
+ <td class-"route"><?php echo esc_html( $e->route ); ?></td>
+ <td class-"status"><?php echo esc_html( $e->status ); ?></td>
+ <td class-"elasped-time"><?php echo esc_html( number_format( $e->milliseconds ) ); ?></td>
+ <td class-"response-body-length"><?php echo esc_html( number_format( $e->response_body_length ) ); ?></td>
+ <td class-"ip-address"><?php echo esc_html( $e->ip_address ); ?></td>
+</tr>
+<tr class="entry-details entry-details-<?php echo esc_attr( $e->id ); ?> collapsed">
+
+ <td colspan="7">
+
+ <div class="postbox request-headers">
+ <h3 class=""><span>Request Headers</span></h3>
+
+ <div class="inside collapsed"><pre><code></code></pre></div>
+
+ </div>
+
+ <div class="postbox querystring-parameters">
+ <h3 class=""><span>Query Parameters</span></h3>
+
+ <div class="inside visible"><pre><code></code></pre></div>
+
+ </div>
+
+ <div class="postbox body-parameters">
+ <h3 class=""><span>Body Parameters</span></h3>
+
+ <div class="inside visible"><pre><code></code></pre></div>
+
+ </div>
+
+ <div class="postbox response-headers">
+ <h3 class=""><span>Response Headers</span></h3>
+
+ <div class="inside collapsed"><pre><code></code></pre></div>
+
+ </div>
+
+ <div class="postbox response-body">
+ <h3 class=""><span>Response</span></h3>
+
+ <div class="inside visible"><pre><code></code></pre></div>
+
+ </div>
+
+ </td>
+
+</tr>
+
--- a/wp-rest-api-log/admin/partials/wp-rest-api-log-display-entries-table.php
+++ b/wp-rest-api-log/admin/partials/wp-rest-api-log-display-entries-table.php
@@ -0,0 +1,28 @@
+<?php
+global $wp_rest_api_log_display_entries;
+global $wp_rest_api_log_display_entry;
+?><table class="log-entries wp-list-table widefat fixed items">
+
+<thead>
+ <tr>
+ <th>Date</th>
+ <th>Method</th>
+ <th>Route</th>
+ <th>Status</th>
+ <th>Elapsed Time</th>
+ <th>Response Length</th>
+ <th>IP Address</th>
+ </tr>
+</thead>
+
+<tbody class="tbody">
+ <?php
+ if ( ! empty( $wp_rest_api_log_display_entries ) ) {
+ foreach ( $wp_rest_api_log_display_entries as $wp_rest_api_log_display_entry ) {
+ require plugin_dir_path( __FILE__ ) . 'wp-rest-api-log-display-entries-table-row.php';
+ }
+ }
+ ?>
+</tbody>
+
+</table>
--- a/wp-rest-api-log/admin/partials/wp-rest-api-log-display-entries.php
+++ b/wp-rest-api-log/admin/partials/wp-rest-api-log-display-entries.php
@@ -0,0 +1,63 @@
+<?php ?>
+
+<div class="wrap wp-rest-api-log-wrap">
+
+ <h2>WP REST API Log</h2>
+
+ <div class="search-form">
+
+ <form method="get" action="<?php echo site_url( rest_get_url_prefix() . '/wp-rest-api-log/entries' ); ?>">
+
+ <div class="search-params">
+
+ <div class="search-param">
+ Date:
+ <input type="text" name="from" value="" class="from datetimepicker clear-on-reset" />
+ to
+ <input type="text" name="from" value="" class="to datetimepicker clear-on-reset" />
+ </div>
+
+ <div class="search-param">
+ Method:
+ <select name="method" class="method clear-on-reset">
+ <option></option>
+ <option>GET</option>
+ <option>POST</option>
+ <option>PUT</option>
+ <option>PATCH</option>
+ <option>DELETE</option>
+ </select>
+ </div>
+
+ <div class="search-param">
+ Route: <input type="text" name="route" value="" class="route clear-on-reset clear-on-reset" />
+ </div>
+
+ <div class="search-param">
+ Param: <input type="text" name="param_name" value="" class="param_name clear-on-reset" /> : <input type="text" name="param_value" value="" class="param_value clear-on-reset" />
+ </div>
+
+ <div class="search-param-buttons">
+ <input type="submit" value="<?php _e( 'Search '); ?>" class="button-primary" />
+ <button type="submit" class="button button-reset"><?php _e( 'Reset' ); ?></button>
+ <?php include plugin_dir_path( __FILE__ ) . 'wp-rest-api-log-display-entries-ajax-wait.php'; ?>
+ </div>
+
+ </div><!-- .search-params -->
+
+ </form>
+
+ </div>
+
+ <div class="table-wrap">
+ <?php require_once plugin_dir_path( __FILE__ ) . 'wp-rest-api-log-display-entries-table.php'; ?>
+ </div>
+
+
+ <p class="no-matches collapsed">
+ No matching log entries
+ </p>
+
+</div>
+
+
--- a/wp-rest-api-log/includes/class-wp-rest-api-log-post-type.php
+++ b/wp-rest-api-log/includes/class-wp-rest-api-log-post-type.php
@@ -21,17 +21,17 @@
static public function get_post_type_labels() {
$labels = array(
- 'name' => esc_html__( 'REST API Log Entries', 'ms-research' ),
- 'singular_name' => esc_html__( 'REST API Log Entry', 'ms-research' ),
- 'add_new' => esc_html__( 'Add New REST API Log Entries', 'ms-research' ),
- 'add_new_item' => esc_html__( 'Add New REST API Log Entry', 'ms-research' ),
- 'new_item' => esc_html__( 'New REST API Log Entry', 'ms-research' ),
- 'edit_item' => esc_html__( 'Edit Publication Page', 'ms-research' ),
- 'view_item' => esc_html__( 'View REST API Log Entry', 'ms-research' ),
- 'all_items' => esc_html__( 'All REST API Log Entries', 'ms-research' ),
- 'search_items' => esc_html__( 'Search Entries', 'ms-research' ),
- 'not_found' => esc_html__( 'No REST API Log Entries found', 'ms-research' ),
- 'not_found_in_trash' => esc_html__( 'No REST API Log Entries found in Trash', 'ms-research' ),
+ 'name' => esc_html__( 'REST API Log Entries', 'wp-rest-api-log' ),
+ 'singular_name' => esc_html__( 'REST API Log Entry', 'wp-rest-api-log' ),
+ 'add_new' => esc_html__( 'Add New REST API Log Entries', 'wp-rest-api-log' ),
+ 'add_new_item' => esc_html__( 'Add New REST API Log Entry', 'wp-rest-api-log' ),
+ 'new_item' => esc_html__( 'New REST API Log Entry', 'wp-rest-api-log' ),
+ 'edit_item' => esc_html__( 'Edit REST API Log Entry', 'wp-rest-api-log' ),
+ 'view_item' => esc_html__( 'View REST API Log Entry', 'wp-rest-api-log' ),
+ 'all_items' => esc_html__( 'All REST API Log Entries', 'wp-rest-api-log' ),
+ 'search_items' => esc_html__( 'Search Entries', 'wp-rest-api-log' ),
+ 'not_found' => esc_html__( 'No REST API Log Entries found', 'wp-rest-api-log' ),
+ 'not_found_in_trash' => esc_html__( 'No REST API Log Entries found in Trash', 'wp-rest-api-log' ),
);
return apply_filters( WP_REST_API_Log_Common::PLUGIN_NAME . '-post-type-labels', $labels );
@@ -42,8 +42,7 @@
$args = array(
'labels' => self::get_post_type_labels(),
- 'show_in_rest' => true,
- 'rest_base' => WP_REST_API_Log_DB::POST_TYPE, // allows the CPT to show up in the native API
+ 'show_in_rest' => false,
'hierarchical' => false,
'public' => false,
'show_ui' => true,
--- a/wp-rest-api-log/includes/class-wp-rest-api-log-request-response-base.php
+++ b/wp-rest-api-log/includes/class-wp-rest-api-log-request-response-base.php
@@ -124,9 +124,8 @@
if ( is_array( $entry->request->$field ) ) {
array_walk_recursive(
$entry->request->$field,
- function ( &$v, &$k ) {
+ function ( &$v ) {
$v = esc_html( $v );
- $k = esc_html( $k );
}
);
} else {
@@ -139,9 +138,8 @@
if ( is_array( $entry->response->$field ) ) {
array_walk_recursive(
$entry->response->$field,
- function ( &$v, &$k ) {
+ function ( &$v ) {
$v = esc_html( $v );
- $k = esc_html( $k );
}
);
} else {
--- a/wp-rest-api-log/wp-rest-api-log.php
+++ b/wp-rest-api-log/wp-rest-api-log.php
@@ -4,7 +4,7 @@
* Description: Logs requests and responses for the REST API
* Author: Pete Nelson
* Author URI: https://petenelson.io
- * Version: 1.7.1
+ * Version: 1.7.2
* Plugin URI: https://github.com/petenelson/wp-rest-api-log
* Text Domain: wp-rest-api-log
* Domain Path: /languages
@@ -18,7 +18,7 @@
}
if ( ! defined( 'WP_REST_API_LOG_VERSION' ) ) {
- define( 'WP_REST_API_LOG_VERSION', '1.7.1' );
+ define( 'WP_REST_API_LOG_VERSION', '1.7.2' );
}
if ( ! defined( 'WP_REST_API_LOG_ROOT' ) ) {