Skip to content

Commit 00911c7

Browse files
sanitize sql calls and echoed outputs
1 parent 0cd6ba6 commit 00911c7

File tree

6 files changed

+117
-113
lines changed

6 files changed

+117
-113
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function kkd_pff_paystack_dashboard_table_data($column, $post_id)
239239
break;
240240
case 'payments':
241241

242-
$count_query = 'select count(*) from ' . $table . ' WHERE post_id = "' . $post_id . '" AND paid = "1"';
242+
$count_query = $wpdb->prepare("SELECT COUNT(*) FROM {$table} WHERE post_id = %d AND paid = '1'", $post_id);
243243
$num = $wpdb->get_var($count_query);
244244

245245
echo '<u><a href="' . admin_url('admin.php?page=submissions&form=' . $post_id) . '">' . $num . '</a></u>';
@@ -292,7 +292,7 @@ function kkd_pff_paystack_editor_shortcode_details($post)
292292
<p class="description">
293293
<label for="wpcf7-shortcode">Copy this shortcode and paste it into your post, page, or text widget content:</label>
294294
<span class="shortcode wp-ui-highlight">
295-
<input type="text" id="wpcf7-shortcode" onfocus="this.select();" readonly="readonly" class="large-text code" value="[pff-paystack id=&quot;<?php echo $post->ID; ?>&quot;]"></span>
295+
<input type="text" id="wpcf7-shortcode" onfocus="this.select();" readonly="readonly" class="large-text code" value="[pff-paystack id=&quot;<?php echo esc_html($post->ID); ?>&quot;]"></span>
296296
</p>
297297

298298
<?php
@@ -800,14 +800,14 @@ function kkd_pff_paystack_payment_submissions()
800800
$data = $exampleListTable->prepare_items(); ?>
801801
<div id="welcome-panel" class="welcome-panel">
802802
<div class="welcome-panel-content">
803-
<h1 style="margin: 0px;"><?php echo $obj->post_title; ?> Payments </h1>
803+
<h1 style="margin: 0px;"><?php echo esc_html($obj->post_title); ?> Payments </h1>
804804
<p class="about-description">All payments made for this form</p>
805805
<?php if ($data > 0) {
806806
?>
807807

808808
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
809809
<input type="hidden" name="action" value="kkd_pff_export_excel">
810-
<input type="hidden" name="form_id" value="<?php echo $id; ?>">
810+
<input type="hidden" name="form_id" value="<?php echo esc_html($id); ?>">
811811
<button type="submit" class="button button-primary button-hero load-customize">Export Data to Excel</button>
812812
</form>
813813
<?php
@@ -843,7 +843,9 @@ function Kkd_pff_export_excel()
843843
}
844844
$table = $wpdb->prefix . KKD_PFF_PAYSTACK_TABLE;
845845
$data = array();
846-
$alldbdata = $wpdb->get_results("SELECT * FROM $table WHERE (post_id = '" . $post_id . "' AND paid = '1') ORDER BY `id` ASC");
846+
$table = sanitize_text_field($table);
847+
848+
$alldbdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table} WHERE post_id = %d AND paid = '1' ORDER BY `id` ASC", $post_id));
847849
$i = 0;
848850

849851
if (count($alldbdata) > 0) {
@@ -970,8 +972,7 @@ public function prepare_items()
970972

971973
$table = $wpdb->prefix . KKD_PFF_PAYSTACK_TABLE;
972974
$data = array();
973-
$alldbdata = $wpdb->get_results("SELECT * FROM $table WHERE (post_id = '" . $post_id . "' AND paid = '1')");
974-
975+
$alldbdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table} WHERE post_id = %d AND paid = '1'", $post_id));
975976
foreach ($alldbdata as $key => $dbdata) {
976977
$newkey = $key + 1;
977978
if ($dbdata->txn_code_2 != "") {

includes/class-paystack-forms-activator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static function activate()
88
global $wpdb;
99
$version = get_option('kkd_db_version', '1.0');
1010
$table_name = $wpdb->prefix . KKD_PFF_PAYSTACK_TABLE;
11-
11+
$table_name = sanitize_text_field($table_name);
1212
$charset_collate = $wpdb->get_charset_collate();
1313

1414
$sql = "CREATE TABLE IF NOT EXISTS `" . $table_name . "` (
@@ -59,10 +59,12 @@ public static function activate()
5959
}
6060

6161

62-
$row = $wpdb->get_results(
63-
"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
64-
WHERE table_name = '" . $table_name . "' AND column_name = 'plan'"
62+
$query = $wpdb->prepare(
63+
"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = %s AND column_name = 'plan'",
64+
$table_name
6565
);
66+
67+
$row = $wpdb->get_results($query);
6668
if (empty($row)) {
6769
$wpdb->query("ALTER TABLE `" . $table_name . "` ADD `plan` VARCHAR(255) NOT NULL AFTER `paid`;");
6870
}

includes/paystack-invoice.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function kkd_format_metadata($data)
4040

4141
global $wpdb;
4242
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
43-
$record = $wpdb->get_results("SELECT * FROM $table WHERE (txn_code = '".$code."')");
43+
$record = $wpdb->get_results($wpdb->prepare("SELECT * FROM %s WHERE txn_code = %s", $table, $code));
4444

4545
if (array_key_exists("0", $record)) {
4646
get_header();
@@ -57,7 +57,7 @@ function kkd_format_metadata($data)
5757
<article class="post-4 page type-page status-publish hentry" id="post-4">
5858
<form action="<?php echo admin_url('admin-ajax.php'); ?>" method="post" enctype="multipart/form-data" class="j-forms retry-form" id="pf-form" novalidate="">
5959
<input type="hidden" name="action" value="kkd_pff_paystack_retry_action">
60-
<input type="hidden" name="code" value="<?php echo $code; ?>" />
60+
<input type="hidden" name="code" value="<?php echo esc_html($code);; ?>" />
6161
<div class="content">
6262

6363
<div class="divider-text gap-top-20 gap-bottom-45">
@@ -67,17 +67,17 @@ function kkd_format_metadata($data)
6767
<div class="j-row">
6868
<div class="span12 unit">
6969
<label class="label inline">Email:</label>
70-
<strong><a href="mailto:<?php echo $dbdata->email; ?>"><?php echo $dbdata->email; ?></a></strong>
70+
<strong><a href="mailto:<?php echo esc_html($dbdata->email); ?>"><?php echo esc_html($dbdata->email); ?></a></strong>
7171
</div>
7272
<div class="span12 unit">
7373
<label class="label inline">Amount:</label>
74-
<strong><?php echo $currency.number_format($dbdata->amount); ?></strong>
74+
<strong><?php echo esc_html($currency.number_format($dbdata->amount)); ?></strong>
7575
</div>
7676
<?php echo kkd_format_metadata($dbdata->metadata); ?>
7777

7878
<div class="span12 unit">
7979
<label class="label inline">Date:</label>
80-
<strong><?php echo $dbdata->created_at; ?></strong>
80+
<strong><?php echo esc_html($dbdata->created_at); ?></strong>
8181
</div>
8282
<?php if($dbdata->paid == 1) {?>
8383
<div class="span12 unit">

0 commit comments

Comments
 (0)