Issues (194)

Security Analysis    no vulnerabilities found

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.

LeaderboardLadderEndpointController.php (15 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
3
// @todo Go over this ENTIRE file again as there's been major refactors since and it's likely broken!
4
5
namespace Ps2alerts\Api\Controller\Endpoint\Leaderboards;
6
7
use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
class LeaderboardLadderEndpointController extends AbstractEndpointController
12
{
13
    public function playerLadder(ServerRequestInterface $request, ResponseInterface $response, array $args)
0 ignored issues
show
The parameter $request 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 $response 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...
14
    {
15
        $redis = $this->getRedisDriver();
0 ignored issues
show
The method getRedisDriver() does not seem to exist on object<Ps2alerts\Api\Con...dderEndpointController>.

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...
16
        $metric = $args['metric'];
17
        $server = $args['server'];
18
19
        $list = "ps2alerts:api:leaderboards:players:{$metric}:listById-{$server}";
20
21
        var_dump($list);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($list); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
22
23
        $entries = $redis->get($list);
24
25
        var_dump($entries);
26
    }
27
28
    /**
29
     * Prompts the Leaderboard:Check command to resync the leaderboards
30
     *
31
     * @param  ServerRequestInterface  $request
32
     * @param  ResponseInterface $response
33
     *
34
     * @return ResponseInterface
35
     */
36
    public function update(ServerRequestInterface $request, ResponseInterface $response)
0 ignored issues
show
update uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
update uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
37
    {
38
        $config = $this->getConfig();
0 ignored issues
show
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
39
40
        // Only accept commands from internal IP
41
        $ip = $request->getClientIp();
0 ignored issues
show
The method getClientIp() does not seem to exist on object<Psr\Http\Message\ServerRequestInterface>.

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...
42
43
        if ($ip !== $_SERVER['SERVER_ADDR']) {
44
            $response->setStatusCode(404);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Psr\Http\Message\ResponseInterface as the method setStatusCode() does only exist in the following implementations of said interface: Zend\Diactoros\Response, Zend\Diactoros\Response\EmptyResponse, Zend\Diactoros\Response\HtmlResponse, Zend\Diactoros\Response\JsonResponse, Zend\Diactoros\Response\RedirectResponse, Zend\Diactoros\Response\TextResponse.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
45
            return $response;
46
        }
47
48
        $server = $_GET['server'];
49
50
        $redis = $this->getRedisDriver();
0 ignored issues
show
The method getRedisDriver() does not seem to exist on object<Ps2alerts\Api\Con...dderEndpointController>.

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...
51
        $key = "ps2alerts:api:leaderboards:status:{$server}";
52
53
        // If we have a key, change the flag to force exists so the cronjob can run
54
        if ($redis->exists($key)) {
55
            $data = json_decode($redis->get($key));
56
57
             // Ignore if already flagged as being updated
58
            if ($data->beingUpdated == 0) {
59
                $data->forceUpdate = 1;
60
                $redis->set($key, json_encode($data));
61
            }
62
        } else {
0 ignored issues
show
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
63
            // Panic.
64
        }
65
66
        $response = $response->withStatus(202);
67
        return $response;
68
    }
69
70
    /**
71
     * Returns a list of times that a server leaderboard has been updated
72
     *
73
     * @param  ServerRequestInterface  $request
74
     * @param  ResponseInterface $response
75
     *
76
     * @return ResponseInterface
77
     */
78
    public function lastUpdate(ServerRequestInterface $request, ResponseInterface $response)
0 ignored issues
show
The parameter $request 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 $response 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...
79
    {
80
        $config = $this->getConfig();
81
        $redis = $this->getRedisDriver();
0 ignored issues
show
The method getRedisDriver() does not seem to exist on object<Ps2alerts\Api\Con...dderEndpointController>.

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...
82
83
        $data = [];
84
85
        foreach($config['servers'] as $server) {
86
            $key = "ps2alerts:api:leaderboards:status:{$server}";
87
88
            if ($redis->exists($key)) {
89
                $entry = json_decode($redis->get($key));
90
                $data[$server] = $this->createItem($entry, new LeaderboardUpdatedTransformer);
0 ignored issues
show
The method createItem() does not seem to exist on object<Ps2alerts\Api\Con...dderEndpointController>.

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...
91
            }
92
        }
93
94
        return $this->respondWithData($data);
95
    }
96
}
97