Issues (183)

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/Cookie.php (4 issues)

Severity

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
namespace FMUP;
3
4
/**
5
 * Class Cookie
6
 * @package FMUP
7
 */
8
class Cookie
9
{
10
    private static $instance;
11
12 1
    private function __construct()
13
    {
14 1
    }
15
16
    /**
17
     * @codeCoverageIgnore
18
     */
19
    private function __clone()
20
    {
21
    }
22
23
    /**
24
     * Retrieve cookie system - start cookie if not started
25
     * @return Cookie
26
     */
27 2
    final public static function getInstance()
28
    {
29 2
        if (!isset(self::$instance)) {
30 1
            $class = get_called_class();
31 1
            self::$instance = new $class;
32
        }
33 2
        return self::$instance;
34
    }
35
36
    /**
37
     * Check whether a specific information exists in cookie
38
     * @param string $name
39
     * @throws Exception if parameter is not a string
40
     * @return bool
41
     */
42 4
    public function has($name)
0 ignored issues
show
has uses the super-global variable $_COOKIE 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...
43
    {
44 4
        if (!is_string($name)) {
45 3
            throw new Exception('Parameter must be a string');
46
        }
47 4
        return isset($_COOKIE[$name]);
48
    }
49
50
    /**
51
     * Define a new cookie
52
     * @param string $name
53
     * @param string $value
54
     * @param int $expire
55
     * @param string $path
56
     * @param string $domain
57
     * @param bool $secure
58
     * @param bool $httpOnly
59
     * @throws Exception if parameter is not a string
60
     * @return $this
61
     */
62 1
    public function set($name, $value, $expire = 0, $path = "/", $domain = "", $secure = false, $httpOnly = false)
63
    {
64 1
        if (!is_string($name)) {
65 1
            throw new Exception('Parameter must be a string');
66
        }
67 1
        $time = time();
68 1
        if ($expire < $time) {
69 1
            $expire = $time + $expire;
70
        }
71 1
        $this->setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
72 1
        return $this;
73
    }
74
75
    /**
76
     * Method that sends cookie - Unit test only
77
     * @codeCoverageIgnore
78
     * @param $name
79
     * @param $value
80
     * @param int $expire
81
     * @param string $path
82
     * @param string $domain
83
     * @param bool|false $secure
84
     * @param bool|false $httpOnly
85
     * @return bool
86
     */
87
    protected function setCookie(
88
        $name,
89
        $value,
90
        $expire = 0,
91
        $path = "/",
92
        $domain = "",
93
        $secure = false,
94
        $httpOnly = false
95
    ) {
96
        return setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
97
    }
98
99
    /**
100
     * Retrieve a specific Cookie value
101
     * @param string $name
102
     * @throws Exception if parameter is not a string
103
     * @return mixed
104
     */
105 1
    public function get($name)
0 ignored issues
show
get uses the super-global variable $_COOKIE 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...
106
    {
107 1
        return $this->has($name) ? $_COOKIE[$name] : null;
108
    }
109
110
    /**
111
     * Remove a specific Cookie
112
     * @param string $name
113
     * @param string $path
114
     * @param string $domain
115
     * @param bool $secure
116
     * @return $this
117
     */
118 2
    public function remove($name, $path = "/", $domain = "", $secure = false)
0 ignored issues
show
remove uses the super-global variable $_COOKIE 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...
119
    {
120 2
        if ($this->has($name)) {
121 2
            $this->setCookie($name, "", time() - (3600 * 24), $path, $domain, $secure);
122 2
            unset($_COOKIE[$name]);
123
        }
124 2
        return $this;
125
    }
126
127
    /**
128
     * Remove all Cookies
129
     * @return $this
130
     */
131 1
    public function destroy()
0 ignored issues
show
destroy uses the super-global variable $_COOKIE 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...
132
    {
133 1
        foreach (array_keys($_COOKIE) as $cookie) {
134 1
            $this->remove($cookie);
135
        }
136 1
        return $this;
137
    }
138
}
139