Skip to content

Commit

Permalink
Sanitize and escape data
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalkhan committed Dec 16, 2020
1 parent bf6e5ac commit 16b62da
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function get_admin_tabs()
{
$tabs = apply_plugin_filters('admin_tabs', []);
$keys = array_keys($tabs);
$active = (isset($_GET['tab']) && $_GET['tab']) ? $_GET['tab'] : reset($keys);
$active = apply_plugin_filters('active_admin_tab', $active);
$tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : reset($keys);
$active = apply_plugin_filters('active_admin_tab', $tab);

return [$tabs, $active];
}
Expand Down
8 changes: 4 additions & 4 deletions src/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function ajax()
]));
}

$id = $_POST['id'];
$slug = $_POST['slug'];
$id = sanitize_text_field($_POST['id']);
$slug = sanitize_text_field($_POST['slug']);

if (! apply_plugin_filters('can_vote', true, $id, $slug)) {
header('Content-Type: application/json; charset=utf-8', true, 401);
Expand All @@ -55,9 +55,9 @@ function ajax()
]));
}

$best = $_POST['best'] ?: get_option(prefix('stars'));
$best = isset($_POST['best']) ? sanitize_text_field($_POST['best']): get_option(prefix('stars'));
$best = max((int) $best, 1);
$score = $_POST['score'];
$score = sanitize_text_field($_POST['score']);
$score = min(max((int) $score, 1), $best);

do_plugin_action('vote', $score, $best, $id, $slug);
Expand Down
2 changes: 1 addition & 1 deletion src/metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function metabox_content($content, $post)
function save_default_metabox($id)
{
if (isset($_POST[meta_prefix('status')])) {
update_post_meta($id, meta_prefix('status'), $_POST[meta_prefix('status')]);
update_post_meta($id, meta_prefix('status'), sanitize_text_field($_POST[meta_prefix('status')]));
}

if (isset($_POST[meta_prefix('reset')])
Expand Down
2 changes: 1 addition & 1 deletion views/active-stars.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="kksr-stars-active" style="width: <?= $width ?>px;">
<div class="kksr-stars-active" style="width: <?= esc_attr($width) ?>px;">
<?php for ($i = 1; $i <= $best; $i++) : ?>
<div class="kksr-star">
<?= \Bhittani\StarRating\view('active-star') ?>
Expand Down
2 changes: 1 addition & 1 deletion views/admin/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}
?>

<form method="POST" action="options.php?tab=<?= $active; ?>" style="margin: 2rem;">
<form method="POST" action="options.php?tab=<?= esc_attr($active); ?>" style="margin: 2rem;">
<?php submit_button(); ?>
<?php settings_fields($slug); ?>
<?php do_settings_sections($slug); ?>
Expand Down
4 changes: 2 additions & 2 deletions views/admin/fields/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
?>

<label>
<input type="checkbox" name="<?= $name ?>" value="<?= $value ?>"
<input type="checkbox" name="<?= esc_attr($name) ?>" value="<?= esc_attr($value) ?>"
<?= $checked ? 'checked="checked"' : '' ?>>
<?= $label ?>
<?= esc_html($label) ?>
</label>
4 changes: 2 additions & 2 deletions views/admin/fields/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
}
?>

<textarea rows="15" cols="50" name="<?= $name ?>"
style="font-family: monospace; padding: .5rem;"><?= $value ?></textarea>
<textarea rows="15" cols="50" name="<?= esc_attr($name) ?>"
style="font-family: monospace; padding: .5rem;"><?= esc_textarea($value) ?></textarea>
8 changes: 4 additions & 4 deletions views/admin/fields/number.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
}
?>

<input type="number" name="<?= $name ?>" value="<?= $value ?>"
<?= isset($min) ? "min=\"{$min}\"" : '' ?>
<?= isset($max) ? "max=\"{$max}\"" : '' ?>
<?= isset($step) ? "step=\"{$step}\"" : '' ?>
<input type="number" name="<?= esc_attr($name) ?>" value="<?= esc_attr($value) ?>"
<?= isset($min) ? ('min="'. esc_attr($min).'"') : '' ?>
<?= isset($max) ? ('max="'. esc_attr($max).'"') : '' ?>
<?= isset($step) ? ('step="'. esc_attr($step).'"') : '' ?>
style="width: 5rem;">
4 changes: 2 additions & 2 deletions views/admin/fields/radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
?>

<label>
<input type="radio" name="<?= $name ?>" value="<?= $value ?>"
<input type="radio" name="<?= esc_attr($name) ?>" value="<?= esc_attr($value) ?>"
<?= $checked ? 'checked="checked"' : '' ?>>

<?= $label ?>
<?= esc_html($label) ?>
</label>
6 changes: 3 additions & 3 deletions views/admin/fields/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
}
?>

<select name="<?= $name ?><?= (isset($multiple) && $multiple) ? '[]' : '' ?>"
<select name="<?= esc_attr($name) ?><?= (isset($multiple) && $multiple) ? '[]' : '' ?>"
style="min-width: 15rem; padding: .5rem;"
<?= (isset($multiple) && $multiple) ? 'multiple="multiple"' : '' ?>>
<?php foreach ($options as $option) : ?>
<option value="<?= $option['value'] ?>"
<option value="<?= esc_attr($option['value']) ?>"
<?= $option['selected'] ? 'selected="selected"' : '' ?>>
<?= $option['label'] ?>
<?= esc_html($option['label']) ?>
</option>
<?php endforeach; ?>
</select>
2 changes: 1 addition & 1 deletion views/admin/fields/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
}
?>

<input name="<?= $name ?>" value="<?= $value ?>"
<input name="<?= esc_attr($name) ?>" value="<?= esc_attr($value) ?>"
style="width: 15rem;">
4 changes: 2 additions & 2 deletions views/admin/fields/textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
}
?>

<textarea rows="15" cols="50" name="<?= $name ?>"
style="padding: .5rem;"><?= $value ?></textarea>
<textarea rows="15" cols="50" name="<?= esc_attr($name) ?>"
style="padding: .5rem;"><?= esc_textarea($value) ?></textarea>
8 changes: 4 additions & 4 deletions views/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
<?php settings_errors(); ?>

<h1>
<?= $label; ?>
<?= esc_html($label); ?>
<small style="
color: gray;
font-size: 80%;
margin-left: .5rem;
letter-spacing: -2px;
font-family: monospace;">
<?= $version; ?>
<?= esc_html($version); ?>
</small>
</h1>

<h2 class="nav-tab-wrapper">
<?php foreach ($tabs as $tab => $label) : ?>
<a class="nav-tab <?= $tab === $active ? 'nav-tab-active' : ''; ?>"
href="<?= admin_url('admin.php?page='.$_GET['page'].'&tab='.$tab); ?>">
<?= $label; ?>
href="<?= admin_url('admin.php?page='.sanitize_text_field($_GET['page']).'&tab='. esc_attr($tab)); ?>">
<?= esc_html($label); ?>
</a>
<?php endforeach; ?>
<div style="float: left; margin-left: 10px;">
Expand Down
2 changes: 1 addition & 1 deletion views/inactive-stars.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="kksr-stars-inactive">
<?php for ($i = 1; $i <= $best; $i++) : ?>
<div class="kksr-star" data-star="<?= $i ?>">
<div class="kksr-star" data-star="<?= esc_attr($i) ?>">
<?= \Bhittani\StarRating\view('inactive-star') ?>
</div>
<?php endfor; ?>
Expand Down
10 changes: 5 additions & 5 deletions views/legend.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<div class="kksr-legend">
<?php if ($count) : ?>
<strong class="kksr-score"><?= $score ?></strong>
<strong class="kksr-score"><?= esc_html($score) ?></strong>
<span class="kksr-muted">/</span>
<strong><?= $best ?></strong>
<strong><?= esc_html($best) ?></strong>
<span class="kksr-muted">(</span>
<strong class="kksr-count"><?= $count ?></strong>
<strong class="kksr-count"><?= esc_html($count) ?></strong>
<span class="kksr-muted">
<?= _n('vote', 'votes', $count, 'kk-star-ratings') ?>
<?= _n('vote', 'votes', esc_html($count), 'kk-star-ratings') ?>
</span>
<span class="kksr-muted">)</span>
<?php else : ?>
<span class="kksr-muted"><?= $greet ?></span>
<span class="kksr-muted"><?= esc_html($greet) ?></span>
<?php endif; ?>
</div>
2 changes: 1 addition & 1 deletion views/markup.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div style="display: none;"
class="kk-star-ratings <?= $valign ? ("kksr-valign-{$valign}") : '' ?> <?= $align ? ("kksr-align-{$align}") : '' ?> <?= $disabled ? 'kksr-disabled' : '' ?>"
class="kk-star-ratings <?= $valign ? ('kksr-valign-'. esc_attr($valign)) : '' ?> <?= $align ? ('kksr-align-'. esc_attr($align)) : '' ?> <?= $disabled ? 'kksr-disabled' : '' ?>"
data-id="<?= esc_attr($id) ?>"
data-slug="<?= esc_attr($slug) ?>">
<?= \Bhittani\StarRating\view('stars') ?>
Expand Down
8 changes: 4 additions & 4 deletions views/metabox/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class='components-base-control__field'>
<div style="margin-top: 1rem;">
<label class="components-base-control__label" style="margin-top: .75rem; margin-bottom: .25rem;">
<input type="checkbox" name="<?= $resetFieldName; ?>" value="1">
<input type="checkbox" name="<?= esc_attr($resetFieldName) ?>" value="1">
<?php _e('Reset Ratings', 'kk-star-ratings'); ?>
</label>
</div>
Expand All @@ -21,15 +21,15 @@

<div style="margin-top: 1rem;">
<label class="components-base-control__label" style="margin-top: .5rem; margin-bottom: .25rem;">
<input type="radio" name="<?= $statusFieldName; ?>" value="" <?php checked($status, ''); ?>>
<input type="radio" name="<?= esc_attr($statusFieldName) ?>" value="" <?php checked($status, ''); ?>>
<?php _e('Auto', 'kk-star-ratings'); ?>
</label>
<label class="components-base-control__label" style="margin-top: .5rem; margin-bottom: .25rem;">
<input type="radio" name="<?= $statusFieldName; ?>" value="enable" <?php checked($status, 'enable'); ?>>
<input type="radio" name="<?= esc_attr($statusFieldName) ?>" value="enable" <?php checked($status, 'enable'); ?>>
<?php _e('Enable', 'kk-star-ratings'); ?>
</label>
<label class="components-base-control__label" style="margin-top: .5rem; margin-bottom: .25rem;">
<input type="radio" name="<?= $statusFieldName; ?>" value="disable" <?php checked($status, 'disable'); ?>>
<input type="radio" name="<?= esc_attr($statusFieldName) ?>" value="disable" <?php checked($status, 'disable'); ?>>
<?php _e('Disable', 'kk-star-ratings'); ?>
</label>
</div>
Expand Down
2 changes: 1 addition & 1 deletion views/star.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="kksr-icon" style="width: <?= $size ?>px; height: <?= $size ?>px;"></div>
<div class="kksr-icon" style="width: <?= esc_attr($size) ?>px; height: <?= esc_attr($size) ?>px;"></div>

0 comments on commit 16b62da

Please sign in to comment.