Issues (42)

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.

src/Psr/Messages/ServerRequest.php (4 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
namespace Almendra\Http\Psr\Messages;
4
5
use Psr\Http\Message\ServerRequestInterface as RequestInterface;
6
use Almendra\Http\Psr\Messages\Response;
7
8
use Almendra\Http\Helpers\URI as URIHelper;
9
use Almendra\Http\Server;
10
11
class ServerRequest extends Response implements RequestInterface
0 ignored issues
show
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: getAttribute, getAttributes, getMethod, getParsedBody, getRequestTarget, getUploadedFiles, getUri, withAttribute, withMethod, withParsedBody, withQueryParams, withRequestTarget, withUploadedFiles, withUri, withoutAttribute
Loading history...
12
{
13
    protected $_cookies = [];
14
    protected $_serverParams = [];
15
16
    // protocol ver
17
    // headers
18
    // body
19
20
21
    public function __construct($cookies = null, $serverParams = null)
0 ignored issues
show
The parameter $serverParams 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...
22
    {
23
        if (isset($cookies) && null !== $cookies) {
24
            $this -> setCookies($cookies);
25
        } else {
26
            $this -> setCookies($this -> getCookieParams());
27
        }
28
    }
29
    
30
    /**
31
     * Retrieve server parameters.
32
     *
33
     * Retrieves data related to the incoming request environment,
34
     * typically derived from PHP's $_SERVER superglobal. The data IS NOT
35
     * REQUIRED to originate from $_SERVER.
36
     *
37
     * @return array
38
     */
39
    public function getServerParams()
0 ignored issues
show
getServerParams 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...
40
    {
41
        if (isset($_SERVER) && null !== $_SERVER) {
42
            $this -> _serverParams = $_SERVER;
43
        }
44
45
        return $this -> _serverParams; // attempt to retrieve them
46
    }
47
48
49
    /**
50
     * Retrieve cookies.
51
     *
52
     * Retrieves cookies sent by the client to the server.
53
     *
54
     * The data MUST be compatible with the structure of the $_COOKIE
55
     * superglobal.
56
     *
57
     * @return array
58
     */
59
    public function getCookieParams()
60
    {
61
        return $this -> _cookies;
62
    }
63
64
    public function withCookieParams(array $cookies)
65
    {
66
        $clone = clone $this;
67
        $clone -> setCookies($cookies);
68
69
        return $clone;
70
    }
71
72
    public function setCookies(array $cookies)
73
    {
74
        foreach ($cookies as $name => $value) {
75
            $this -> setCookie($name, $value);
76
        }
77
    }
78
79
    public function setCookie($name, $value)
80
    {
81
        $this -> _cookies[$name] = $value;
82
    }
83
84
    /**
85
     * Retrieve query string arguments.
86
     *
87
     * Retrieves the deserialized query string arguments, if any.
88
     *
89
     * Note: the query params might not be in sync with the URI or server
90
     * params. If you need to ensure you are only getting the original
91
     * values, you may need to parse the query string from `getUri()->getQuery()`
92
     * or from the `QUERY_STRING` server param.
93
     *
94
     * @return array
95
     */
96
    public function getQueryParams()
97
    {
98
        return URIHelper::getQueryParams($this -> getUri(), false);
0 ignored issues
show
Bug Compatibility introduced by
The expression \Almendra\Http\Helpers\U...this->getUri(), false); of type array|string adds the type string to the return on line 98 which is incompatible with the return type declared by the interface Psr\Http\Message\ServerR...terface::getQueryParams of type array.
Loading history...
99
    }
100
}
101