Skip to content

Commit 764d913

Browse files
author
James Amner
committed
[FIX] Fixes around escaping and sanitzing.
1 parent ce05793 commit 764d913

4 files changed

Lines changed: 33 additions & 31 deletions

File tree

admin/class-jerc-admin.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private function getFilteredQuery()
151151
foreach ($filters as $key => $value) {
152152

153153
if ($key !== 'time_from' && $key !== 'time_to') {
154-
$q .= ' AND ' . $key . ' = \'' . $value . '\'';
154+
$q .= ' AND ' . esc_sql($key) . ' = \'' . esc_sql($value) . '\'';
155155
}
156156
}
157157

@@ -184,7 +184,7 @@ private function getData($paging = true)
184184
$q = $this->getFilteredQuery();
185185

186186
if ($paging) {
187-
$q .= ' LIMIT ' . (isset($_REQUEST['paged']) ? 10 * $_REQUEST['paged'] : 0) . ', 10';
187+
$q .= ' LIMIT ' . esc_sql(intval(isset($_REQUEST['paged']) ? 10 * $_REQUEST['paged'] : 0)) . ', 10';
188188
}
189189
global $wpdb;
190190
return $wpdb->get_results($q);
@@ -237,8 +237,8 @@ private function getFilters()
237237
{
238238
$filters = array();
239239
foreach ($this->getFilterKeys() as $key) {
240-
if (isset($_REQUEST[$key]) && $_REQUEST[$key] !== '') {
241-
$filters[$key] = $_REQUEST[$key];
240+
if (isset($_REQUEST[$key]) && ($_REQUEST[$key] !== '') && is_string($_REQUEST[$key])) {
241+
$filters[$key] = sanitize_text_field($_REQUEST[$key]);
242242
}
243243
}
244244
return $filters;
@@ -332,7 +332,7 @@ private function displayPagination()
332332
number_format_i18n($this->getCount())
333333
) . '</span>';
334334

335-
$current = isset($_REQUEST['paged']) ? $_REQUEST['paged'] : 1;
335+
$current = intval(isset($_REQUEST['paged']) ? $_REQUEST['paged'] : 1);
336336
$total_pages = floor($this->getCount() / 10);
337337

338338
$current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
@@ -425,6 +425,6 @@ private function displayPagination()
425425
$page_class = ' no-pages';
426426
}
427427

428-
echo "<div class='tablenav-pages{$page_class}'>$output</div>";
428+
echo wp_kses_post("<div class='tablenav-pages{$page_class}'>$output</div>");
429429
}
430430
}

admin/partials/jerc-admin-display.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,37 @@
1717
<div class="wrap">
1818
<h1>Javascript Error Reporting</h1>
1919
<form>
20-
<input type='hidden' name='page' value='<?php echo $this->name; ?>'>
20+
<input type='hidden' name='page' value='<?php echo esc_attr($this->name); ?>'>
2121
<div class="tablenav top">
2222

2323
<div class="alignleft">
2424
<label for="date-from-select" class="">Between:</label>
25-
<input type='datetime-local' name="time_from" id="date-from-select" value='<?php echo isset($_REQUEST['time_from']) ? $_REQUEST['time_from'] : ''; ?>'></input>
25+
<input type='datetime-local' name="time_from" id="date-from-select" value='<?php echo esc_attr(isset($_REQUEST['time_from']) ? $_REQUEST['time_from'] : ''); ?>'></input>
2626
<label for="date-to-select" class=""> : </label>
27-
<input type='datetime-local' name="time_to" id="date-to-select" value='<?php echo isset($_REQUEST['time_to']) ? $_REQUEST['time_to'] : ''; ?>'></input>
27+
<input type='datetime-local' name="time_to" id="date-to-select" value='<?php echo esc_attr(isset($_REQUEST['time_to']) ? $_REQUEST['time_to'] : ''); ?>'></input>
2828
<input type="submit" id="doaction" class="button action" value="Filter">
2929

3030

3131
<?php foreach ($this->getFilters() as $key => $value) : ?>
3232
<?php if ($key !== 'time_from' && $key !== 'time_to') : ?>
33-
<input type='hidden' name='<?php echo $key; ?>' value='<?php echo $value; ?>'>
34-
<a class='button' href='<?php echo $this->removeFilterUrl($key); ?>'>
33+
<input type='hidden' name='<?php echo esc_attr($key); ?>' value='<?php echo esc_attr($value); ?>'>
34+
<a class='button' href='<?php echo esc_url($this->removeFilterUrl($key)); ?>'>
3535
<span class="dashicons dashicons-remove" style='line-height:1.4;'></span>
3636
<?php
3737
if ($key === 'userId') {
3838
if ($value == 0) {
3939
echo "Anonymous";
4040
} else {
41-
echo get_userdata($value)->user_nicename;
41+
echo wp_kses_post(get_userdata($value)->user_nicename);
4242
}
4343
} else {
44-
echo $value;
44+
echo wp_kses_post($value);
4545
}
4646
?>
4747
</a>
4848
<?php endif; ?>
4949
<?php endforeach; ?>
50-
<a class="button" href="?page=<?php echo $this->name; ?>">Reset</a>
50+
<a class="button" href="?page=<?php echo esc_attr($this->name); ?>">Reset</a>
5151
</div>
5252
<?php $this->displayPagination(); ?>
5353
<br class="clear">
@@ -74,36 +74,36 @@
7474
$user = get_userdata($row->userId);
7575
} ?>
7676
<td>
77-
<?php echo $row->timestamp; ?>
77+
<?php echo wp_kses_post($row->timestamp); ?>
7878
</td>
7979
<td>
80-
<a href='<?php echo $this->getFilterUrl('message', $row->message); ?>'>
81-
<?php echo $row->message; ?>
80+
<a href='<?php echo esc_url($this->getFilterUrl('message', $row->message)); ?>'>
81+
<?php echo wp_kses_post($row->message); ?>
8282
</a>
8383
</td>
8484
<td>
85-
<a href='<?php echo $this->getFilterUrl('script', $row->script); ?>'>
86-
<?php echo $row->script; ?>
85+
<a href='<?php echo esc_url($this->getFilterUrl('script', $row->script)); ?>'>
86+
<?php echo wp_kses_post($row->script); ?>
8787
</a>
8888
</td>
8989
<td>
90-
<a href='<?php echo $this->getFilterUrl('userId', (isset($user) ? $user->ID : 0)); ?>'>
91-
<?php echo (isset($user) ? $user->user_nicename : 'Anonymous'); ?>
90+
<a href='<?php echo esc_url($this->getFilterUrl('userId', (isset($user) ? $user->ID : 0))); ?>'>
91+
<?php echo wp_kses_post(isset($user) ? $user->user_nicename : 'Anonymous'); ?>
9292
</a>
9393
</td>
9494
<td>
95-
<a href='<?php echo $this->getFilterUrl('userIp', $row->userIp); ?>'>
96-
<?php echo $row->userIp; ?>
95+
<a href='<?php echo esc_url($this->getFilterUrl('userIp', $row->userIp)); ?>'>
96+
<?php echo wp_kses_post($row->userIp); ?>
9797
</a>
9898
</td>
9999
<td>
100-
<a href='<?php echo $this->getFilterUrl('pageUrl', $row->pageUrl); ?>'>
101-
<?php echo $row->pageUrl; ?>
100+
<a href='<?php echo esc_url($this->getFilterUrl('pageUrl', $row->pageUrl)); ?>'>
101+
<?php echo wp_kses_post($row->pageUrl); ?>
102102
</a>
103103
</td>
104104
<td>
105-
<a href='<?php echo $this->getFilterUrl('agent', $row->agent); ?>'>
106-
<?php echo $row->agent; ?>
105+
<a href='<?php echo esc_url($this->getFilterUrl('agent', $row->agent)); ?>'>
106+
<?php echo wp_kses_post($row->agent); ?>
107107
</a>
108108
</td>
109109
</tr>
@@ -113,12 +113,12 @@
113113
</form>
114114
<div class='tablenav bottom'>
115115
<div class='alignleft'>
116-
<form method='POST' action='<?php echo admin_url('admin-post.php'); ?>'>
116+
<form method='POST' action='<?php echo esc_url(admin_url('admin-post.php')); ?>'>
117117
<?php wp_nonce_field($this->action); ?>
118118
<?php foreach ($this->getFilters() as $key => $value) : ?>
119-
<input type='hidden' name='<?php echo $key; ?>' value='<?php echo $value; ?>'>
119+
<input type='hidden' name='<?php echo esc_attr($key); ?>' value='<?php echo esc_attr($value); ?>'>
120120
<?php endforeach; ?>
121-
<button class='button' type='submit' name='action' value='<?php echo $this->action; ?>'>Export CSV</button>
121+
<button class='button' type='submit' name='action' value='<?php echo esc_attr($this->action); ?>'>Export CSV</button>
122122
</form>
123123
</div>
124124
<?php $this->displayPagination(); ?>

jerc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Plugin Name: Javascript Error Reporting Client
1717
* Plugin URI: https://www.amner.me/
1818
* Description: A plugin to collect data about client javascript errors.
19-
* Version: 1.1.0
19+
* Version: 1.0.0
2020
* Author: James Amner <jdamner@me.com>
2121
* Author URI: https://www.amner.me
2222
*/

public/class-jerc-public.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public function handleAjax()
122122
global $wpdb;
123123
$table_name = $wpdb->prefix . $this->plugin_name . "_data";
124124

125+
// No need to escape SQL input;
126+
// @see https://developer.wordpress.org/reference/classes/wpdb/insert/
125127
$data = array(
126128
"message" => $request['message'],
127129
"script" => $request['script'] . ":" . $request['lineNo'] . ":" . $request['columnNo'],

0 commit comments

Comments
 (0)