Skip to content

Commit

Permalink
fix: sql injection vulnerability when using filters (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite authored Mar 10, 2024
1 parent d736f91 commit cbdc188
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions endpoints/subscriptions/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,33 @@
}
}

$params = array();
$sql = "SELECT * FROM subscriptions WHERE 1=1";

if (isset($_GET['category']) && $_GET['category'] != "") {
$category = $_GET['category'];
$sql .= " AND category_id = $category";
$sql .= " AND category_id = :category";
$params[':category'] = $_GET['category'];
}

if (isset($_GET['payment']) && $_GET['payment'] != "") {
$payment = $_GET['payment'];
$sql .= " AND payment_method_id = $payment";
$sql .= " AND payment_method_id = :payment";
$params[':payment'] = $_GET['payment'];
}

if (isset($_GET['member']) && $_GET['member'] != "") {
$member = $_GET['member'];
$sql .= " AND payer_user_id = $member";
$sql .= " AND payer_user_id = :member";
$params[':member'] = $_GET['member'];
}

$sql .= " ORDER BY $sort $order, inactive ASC";


$result = $db->query($sql);
$stmt = $db->prepare($sql);

foreach ($params as $key => $value) {
$stmt->bindValue($key, $value);
}

$result = $stmt->execute();
if ($result) {
$subscriptions = array();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
Expand Down
2 changes: 1 addition & 1 deletion includes/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
$version = "v1.15.2";
$version = "v1.15.3";
?>

0 comments on commit cbdc188

Please sign in to comment.