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/statscache.class.php (13 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
/**
5
 * A wrapper class used to store values transparently in memcache
6
 * Can be enabled or disabled through site configuration
7
 * Also sets a default time if no time is passed to it to enforce caching
8
 **/
9
class StatsCache {
10
  private $cache, $round;
11
12
  public function __construct($config, $debug) {
13
    $this->config = $config;
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...
14
    $this->debug = $debug;
0 ignored issues
show
The property debug 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...
15
    if (! $config['memcache']['enabled'] ) {
16
      $this->debug->append("Not storing any values in memcache");
17
    } else {
18
      if (PHP_OS == 'WINNT') {
19
        require_once(CLASS_DIR . '/memcached.class.php');
20
      }
21
      $this->cache = new Memcached();
22
      if ($config['memcache']['sasl'] === true) {
23
        $this->cache->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
0 ignored issues
show
The method setOption() does not seem to exist on object<Memcached>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
        $this->cache->setSaslAuthData($config['memcache']['sasl']['username'], $config['memcache']['sasl']['password']);
0 ignored issues
show
The method setSaslAuthData() does not seem to exist on object<Memcached>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
      }
26
    }
27
  }
28
29
  public function setRound($round_id) {
30
    $this->round = $round_id;
31
  }
32
  public function getRound() {
33
    return $this->round;
34
  }
35
36
  /**
37
   * Wrapper around memcache->set
38
   * Do not store values if memcache is disabled
39
   **/
40
  public function set($key, $value, $expiration=NULL) {
41
    if (! $this->config['memcache']['enabled']) return $value;
42 View Code Duplication
    if (empty($expiration))
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...
43
      $expiration = $this->config['memcache']['expiration'] + rand( -$this->config['memcache']['splay'], $this->config['memcache']['splay']);
44
    $this->debug->append("Storing " . $this->getRound() . '_' . $this->config['memcache']['keyprefix'] . "$key with expiration $expiration", 3);
45
    return $this->cache->set($this->getRound() . '_' . $this->config['memcache']['keyprefix'] . $key, $value, $expiration);
46
  }
47
48
  /**
49
   * Special memcache->set call bypassing any auto-expiration systems
50
   * Can be used as a static, auto-updated cache via crons
51
   **/
52
  public function setStaticCache($key, $value, $expiration=NULL) {
53
    if (! $this->config['memcache']['enabled']) return $value;
54 View Code Duplication
    if (empty($expiration))
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...
55
      $expiration = $this->config['memcache']['expiration'] + rand( -$this->config['memcache']['splay'], $this->config['memcache']['splay']);
56
    $this->debug->append("Storing " . $this->config['memcache']['keyprefix'] . "$key with expiration $expiration", 3);
57
    if ($this->cache->set($this->config['memcache']['keyprefix'] . $key, $value, $expiration))
58
      return $value;
59
    return false;
60
  }
61
62
  /**
63
   * Wrapper around memcache->get
64
   * Always return false if memcache is disabled
65
   **/
66
  public function get($key, $cache_cb = NULL, &$cas_token = NULL) {
0 ignored issues
show
The parameter $cache_cb is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $cas_token is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    if (! $this->config['memcache']['enabled']) return false;
68
    $this->debug->append("Trying to fetch key " . $this->getRound() . '_' . $this->config['memcache']['keyprefix'] . "$key from cache", 3);
69 View Code Duplication
    if ($data = $this->cache->get($this->getRound() . '_' . $this->config['memcache']['keyprefix'].$key)) {
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...
70
      $this->debug->append("Found key in cache", 3);
71
      return $data;
72
    } else {
73
      $this->debug->append("Key not found", 3);
74
    }
75
  }
76
77
  /**
78
   * As the static set call, we try to fetch static data here
79
   **/
80
  public function getStatic($key, $cache_cb = NULL, &$cas_token = NULL) {
0 ignored issues
show
The parameter $cache_cb is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $cas_token is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    if (! $this->config['memcache']['enabled']) return false;
82
    $this->debug->append("Trying to fetch key " . $this->config['memcache']['keyprefix'] . "$key from cache", 3);
83 View Code Duplication
    if ($data = $this->cache->get($this->config['memcache']['keyprefix'].$key)) {
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...
84
      $this->debug->append("Found key in cache", 3);
85
      return $data;
86
    } else {
87
      $this->debug->append("Key not found", 3);
88
    }
89
  }
90
91
  /**
92
   * Another wrapper, we want to store data in memcache and return the actual data
93
   * for further processing
94
   * @param key string Our memcache key
95
   * @param data mixed Our data to store in Memcache
96
   * @param expiration time Our expiration time, see Memcached documentation
97
   * @return data mixed Return our stored data unchanged
98
   **/
99
  public function setCache($key, $data, $expiration=NULL) {
100
    if ($this->config['memcache']['enabled']) $this->set($key, $data, $expiration);
101
    return $data;
102
  }
103
104
  /**
105
   * This method is invoked if the called method was not realised in this class
106
   **/
107
  public function __call($name, $arguments) {
108
    if (! $this->config['memcache']['enabled']) return false;
109
    //Invoke method $name of $this->cache class with array of $arguments
110
    return call_user_func_array(array($this->cache, $name), $arguments);
111
  }
112
}
113
114
$memcache = new StatsCache($config, $debug);
115
$memcache->addServer($config['memcache']['host'], $config['memcache']['port']);
0 ignored issues
show
Documentation Bug introduced by
The method addServer does not exist on object<StatsCache>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
116
// Now we can set our additional key prefix
117
if ($aTmpBlock = $block->getLast()) {
118
  $iRoundId = $aTmpBlock['id'];
119
} else {
120
  $iRoundId = 0;
121
}
122
$memcache->setRound($iRoundId);
123