From 16b62dab7bebeae6e6c4d1427d7cb23bf41712e9 Mon Sep 17 00:00:00 2001 From: Kamal Khan Date: Wed, 16 Dec 2020 14:40:39 +0500 Subject: [PATCH] Sanitize and escape data --- src/admin.php | 4 ++-- src/ajax.php | 8 ++++---- src/metabox.php | 2 +- views/active-stars.php | 2 +- views/admin/content.php | 2 +- views/admin/fields/checkbox.php | 4 ++-- views/admin/fields/code.php | 4 ++-- views/admin/fields/number.php | 8 ++++---- views/admin/fields/radio.php | 4 ++-- views/admin/fields/select.php | 6 +++--- views/admin/fields/text.php | 2 +- views/admin/fields/textarea.php | 4 ++-- views/admin/index.php | 8 ++++---- views/inactive-stars.php | 2 +- views/legend.php | 10 +++++----- views/markup.php | 2 +- views/metabox/content.php | 8 ++++---- views/star.php | 2 +- 18 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/admin.php b/src/admin.php index 711a28f..f137ec8 100644 --- a/src/admin.php +++ b/src/admin.php @@ -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]; } diff --git a/src/ajax.php b/src/ajax.php index 2b1ab59..6c55fc0 100644 --- a/src/ajax.php +++ b/src/ajax.php @@ -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); @@ -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); diff --git a/src/metabox.php b/src/metabox.php index 12b1429..05269bd 100644 --- a/src/metabox.php +++ b/src/metabox.php @@ -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')]) diff --git a/views/active-stars.php b/views/active-stars.php index b6a8c49..5a6d4ce 100644 --- a/views/active-stars.php +++ b/views/active-stars.php @@ -1,4 +1,4 @@ -
+
diff --git a/views/admin/content.php b/views/admin/content.php index 3c23cbb..2b92180 100644 --- a/views/admin/content.php +++ b/views/admin/content.php @@ -5,7 +5,7 @@ } ?> -
+ diff --git a/views/admin/fields/checkbox.php b/views/admin/fields/checkbox.php index 81848ff..fe91ef9 100644 --- a/views/admin/fields/checkbox.php +++ b/views/admin/fields/checkbox.php @@ -6,7 +6,7 @@ ?> diff --git a/views/admin/fields/code.php b/views/admin/fields/code.php index d92798b..0b8c060 100644 --- a/views/admin/fields/code.php +++ b/views/admin/fields/code.php @@ -5,5 +5,5 @@ } ?> - + diff --git a/views/admin/fields/number.php b/views/admin/fields/number.php index 076d2c0..95f6c82 100644 --- a/views/admin/fields/number.php +++ b/views/admin/fields/number.php @@ -5,8 +5,8 @@ } ?> - - - + + + style="width: 5rem;"> diff --git a/views/admin/fields/radio.php b/views/admin/fields/radio.php index 9e1ac26..f159ca8 100644 --- a/views/admin/fields/radio.php +++ b/views/admin/fields/radio.php @@ -6,8 +6,8 @@ ?> diff --git a/views/admin/fields/select.php b/views/admin/fields/select.php index b7b5e92..7fee145 100644 --- a/views/admin/fields/select.php +++ b/views/admin/fields/select.php @@ -5,13 +5,13 @@ } ?> - diff --git a/views/admin/fields/text.php b/views/admin/fields/text.php index 70ea55e..09aa32b 100644 --- a/views/admin/fields/text.php +++ b/views/admin/fields/text.php @@ -5,5 +5,5 @@ } ?> - diff --git a/views/admin/fields/textarea.php b/views/admin/fields/textarea.php index 7017b2c..027b73b 100644 --- a/views/admin/fields/textarea.php +++ b/views/admin/fields/textarea.php @@ -5,5 +5,5 @@ } ?> - + diff --git a/views/admin/index.php b/views/admin/index.php index 3f36bc5..719c00b 100644 --- a/views/admin/index.php +++ b/views/admin/index.php @@ -9,22 +9,22 @@

- + - +