Issues (431)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

include/classes/coin_address.class.php (11 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3
4
class CoinAddress extends Base {
5
  protected $table = 'coin_addresses';
6
7
  /**
8
   * We allow changing the database for shared accounts across pools
9
   * Load the config on construct so we can assign the DB name
10
   * @param config array MPOS configuration
11
   * @return none
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
12
   **/
13
  public function __construct($config) {
14
    $this->setConfig($config);
15
    $this->table = $this->config['db']['shared']['accounts'] . '.' . $this->table;
0 ignored issues
show
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
  }
17
18
  /**
19
   * Fetch users coin address for a currency
20
   * @param userID int UserID
21
   * @return data string Coin Address
22
   **/
23 View Code Duplication
  public function getCoinAddress($userID, $currency=NULL) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    if ($currency === NULL) $currency = $this->config['currency'];
25
    $this->debug->append("STA " . __METHOD__, 4);
26
    $stmt = $this->mysqli->prepare("
27
      SELECT coin_address
28
      FROM " . $this->getTableName() . "
29
      WHERE account_id = ? AND currency = ?
30
      ");
31
    if ( $this->checkStmt($stmt) && $stmt->bind_param('is', $userID, $currency) && $stmt->execute() && $result = $stmt->get_result()) {
32
      if ($result->num_rows == 1) {
33
        return $result->fetch_object()->coin_address;
34
      }
35
    }
36
    $this->debug->append("Unable to fetch users coin address for " . $currency);
37
    return $this->sqlError();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->sqlError(); (boolean) is incompatible with the return type documented by CoinAddress::getCoinAddress of type data.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
38
  }
39
40
  /**
41
   * Fetch users Auto Payout Threshold for a currency
42
   * @param UserID int UserID
43
   * @return mixed Float value for threshold, false on error
44
   **/
45 View Code Duplication
  public function getAPThreshold($userID, $currency=NULL) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    if ($currency === NULL) $currency = $this->config['currency'];
47
    $this->debug->append("STA " . __METHOD__, 4);
48
    $stmt = $this->mysqli->prepare("
49
      SELECT ap_threshold
50
      FROM " . $this->getTableName() . "
51
      WHERE account_id = ? AND currency = ?
52
      ");
53
    if ( $this->checkStmt($stmt) && $stmt->bind_param('is', $userID, $currency) && $stmt->execute() && $result = $stmt->get_result()) {
54
      if ($result->num_rows == 1) {
55
        return $result->fetch_object()->ap_threshold;
56
      }
57
    }
58
    $this->debug->append("Unable to fetch users auto payout threshold for " . $currency);
59
    return $this->sqlError();
60
  }
61
62
63
  /**
64
   * Check if a coin address is already set
65
   * @param address string Coin Address to check for
66
   * @return bool true or false
67
   **/
68
  public function existsCoinAddress($address) {
69
    $this->debug->append("STA " . __METHOD__, 4);
70
    return $this->getSingle($address, 'coin_address', 'coin_address', 's') === $address;
71
  }
72
73
  /**
74
   * Add a new coin address record for a user
75
   * @param userID int Account ID
76
   * @param address string Coin Address
77
   * @param currency string Currency short handle, defaults to config option
78
   * @return bool true or false
79
   **/
80
  public function add($userID, $address, $currency=NULL) {
81
    if ($currency === NULL) $currency = $this->config['currency'];
82 View Code Duplication
    if ($address != $this->getCoinAddress($userID) && $this->existsCoinAddress($address)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
      $this->setErrorMessage('Unable to update coin address, address already exists');
84
      return false;
85
    }
86
    $stmt = $this->mysqli->prepare("INSERT INTO " . $this->getTableName() . " (account_id, currency, coin_address) VALUES (?, ?, ?)");
87 View Code Duplication
    if ( $this->checkStmt($stmt) && $stmt->bind_param('iss', $userID, $currency, $address) && $stmt->execute()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
      return true;
89
    }
90
    return $this->sqlError();
91
  }
92
93
  /**
94
   * Remove a coin address record for a user
95
   * @param userID int Account ID
96
   * @param currency string Currency short handle, defaults to config option
97
   * @return bool true or false
98
   **/
99
  public function remove ($userID, $currency=NULL) {
100
    if ($currency === NULL) $currency = $this->config['currency'];
101
    $stmt = $this->mysqli->prepare("DELETE FROM " . $this->getTableName() . " WHERE account_id = ? AND currency = ?");
102 View Code Duplication
    if ( $this->checkStmt($stmt) && $stmt->bind_param('is', $userID, $currency) && $stmt->execute()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
      return true;
104
    }
105
    return $this->sqlError();
106
  }
107
108
  /**
109
   * Update a coin address record for a user and a currency
110
   * @param userID int Account ID
111
   * @param address string Coin Address
112
   * @param ap_threshold float Threshold for auto payouts for this currency
113
   * @param currency string Currency short handle, defaults to config option
114
   * @return bool true or false
115
   **/
116
  public function update($userID, $address, $ap_threshold, $currency=NULL) {
117
    if ($currency === NULL) $currency = $this->config['currency'];
118 View Code Duplication
    if ($address != $this->getCoinAddress($userID) && $this->existsCoinAddress($address)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
      $this->setErrorMessage('Unable to update coin address, address already exists');
120
      return false;
121
    }
122
    if ($this->getCoinAddress($userID) != NULL) {
123
      $stmt = $this->mysqli->prepare("UPDATE " . $this->getTableName() . " SET coin_address = ?, ap_threshold = ? WHERE account_id = ? AND currency = ?");
124 View Code Duplication
      if ( $this->checkStmt($stmt) && $stmt->bind_param('sdis', $address, $ap_threshold, $userID, $currency) && $stmt->execute()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
        return true;
126
      }
127
    } else {
128
      $stmt = $this->mysqli->prepare("INSERT INTO " . $this->getTableName() . " (coin_address, ap_threshold, account_id, currency) VALUES (?, ?, ?, ?)");
129 View Code Duplication
      if ( $this->checkStmt($stmt) && $stmt->bind_param('sdis', $address, $ap_threshold, $userID, $currency) && $stmt->execute()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
        return true;
131
      }
132
    }
133
    return $this->sqlError();
134
  }
135
}
136
137
$coin_address = new CoinAddress($config);
138
$coin_address->setDebug($debug);
139
$coin_address->setMysql($mysqli);
140
$coin_address->setErrorCodes($aErrorCodes);
141