Skip to content

Commit feecfc6

Browse files
committed
fix SQL injection vulrn (credits xenos#1337)
1 parent 55032f1 commit feecfc6

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

api/reseller/index.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<?php
22

33
include '../../includes/connection.php';
4+
include '../../includes/functions.php';
5+
6+
7+
8+
if (!isset($_SERVER["HTTP_X_SELLIX_SIGNATURE"]) && !isset($_SERVER["HTTP_X_SHOPPY_SIGNATURE"]))
9+
{
10+
die("Request isn't coming from Sellix or Shoppy.");
11+
}
412

513
if (isset($_SERVER["HTTP_X_SELLIX_SIGNATURE"]))
614
{
@@ -20,7 +28,7 @@
2028
$lifetimeproduct = $row["sellixlifetimeproduct"];
2129

2230
$payload = file_get_contents('php://input');
23-
$header_signature = $_SERVER["HTTP_X_SELLIX_SIGNATURE"];
31+
$header_signature = sanitize($_SERVER["HTTP_X_SELLIX_SIGNATURE"]);
2432
$signature = hash_hmac('sha512', $payload, $secret);
2533
if (!hash_equals($signature, $header_signature))
2634
{ // if the sellix webhook secret the request was sent from didn't match the one set in the database
@@ -30,7 +38,7 @@
3038
$json = json_decode($payload);
3139
$data = $json->data;
3240
$custom = $data->custom_fields; // getting custom fields, the hidden fields on KeyAuth sellix embed which provide sellix the KeyAuth username
33-
$result = mysqli_query($link, "SELECT `balance` FROM `accounts` WHERE `username` = '" . $custom->username . "' AND `app` = '$name'");
41+
$result = mysqli_query($link, "SELECT `balance` FROM `accounts` WHERE `username` = '" . sanitize($custom->username) . "' AND `app` = '$name'");
3442

3543
if (mysqli_num_rows($result) == 0)
3644
{ // if reseller not found
@@ -47,9 +55,9 @@
4755
$sixmonth = $balance[4];
4856
$lifetime = $balance[5];
4957

50-
$amount = $data->quantity; // find quantity of keys purchased
58+
$amount = sanitize($data->quantity); // find quantity of keys purchased
5159
// then given the duration of keys they purchased, add to their balance
52-
switch ($data->product_id)
60+
switch (sanitize($data->product_id))
5361
{
5462
case $dayproduct:
5563
$day = $day + $amount;
@@ -69,7 +77,7 @@
6977

7078
$balance = $day . '|' . $week . '|' . $month . '|' . $threemonth . '|' . $sixmonth . '|' . $lifetime;
7179
// set balance
72-
mysqli_query($link, "UPDATE `accounts` SET `balance` = '$balance' WHERE `username` = '" . $custom->username . "'");
80+
mysqli_query($link, "UPDATE `accounts` SET `balance` = '$balance' WHERE `username` = '" . sanitize($custom->username) . "'");
7381
die("Success: Reseller Balance Increased");
7482
}
7583

@@ -92,18 +100,17 @@
92100
$lifetimeproduct = $row["shoppylifetimeproduct"];
93101

94102
$payload = file_get_contents('php://input');
95-
$header_signature = $_SERVER["HTTP_X_SHOPPY_SIGNATURE"];
103+
$header_signature = sanitize($_SERVER["HTTP_X_SHOPPY_SIGNATURE"]);
96104
$signature = hash_hmac('sha512', $payload, $secret);
97105
if (!hash_equals($signature, $header_signature))
98106
{
99107
// if the shoppy webhook secret the request was sent from didn't match the one set in the database
100108
die("Failure: authentication with shoppy secret failed");
101109
}
102-
103110
$json = json_decode($payload);
111+
$un = sanitize($json->data->order->custom_fields[0]->value);
104112

105-
$un = $json->data->order->custom_fields[0]->value;
106-
$productid = $json->data->order->product_id;
113+
$productid = sanitize($json->data->order->product_id);
107114

108115
$result = mysqli_query($link, "SELECT `balance` FROM `accounts` WHERE `username` = '$un' AND `app` = '$name'");
109116

@@ -123,7 +130,7 @@
123130
$sixmonth = $balance[4];
124131
$lifetime = $balance[5];
125132

126-
$amount = $json->data->order->quantity; // find quantity of keys purchased
133+
$amount = sanitize($json->data->order->quantity); // find quantity of keys purchased
127134
// then given the duration of keys they purchased, add to their balance
128135
switch ($productid)
129136
{

0 commit comments

Comments
 (0)