Issues (243)

Security Analysis    2 potential vulnerabilities

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 (2)
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/web/Session.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 /** MicroSession */
2
3
namespace Micro\Web;
4
5
/**
6
 * Session is a Session manager
7
 *
8
 * @author Oleg Lunegov <[email protected]>
9
 * @link https://github.com/linpax/microphp-framework
10
 * @copyright Copyright (c) 2013 Oleg Lunegov
11
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
12
 * @package Micro
13
 * @subpackage web
14
 * @version 1.0
15
 * @since 1.0
16
 *
17
 * @property array $flash FlashMessages
18
 */
19
class Session extends \stdClass implements ISession
20
{
21
    /**
22
     * Construct for this class
23
     *
24
     * @access public
25
     *
26
     * @param bool $autoStart
27
     *
28
     * @result void
29
     */
30
    public function __construct($autoStart = false)
31
    {
32
        if ($autoStart === true) {
33
            $this->create();
34
        }
35
    }
36
37
    /**
38
     * Create a new session or load prev session
39
     *
40
     * @access public
41
     * @return void
42
     */
43
    public function create()
44
    {
45
        if (PHP_SESSION_ACTIVE !== session_status()) {
46
            session_start();
47
        }
48
    }
49
50
    /**
51
     * Destroy session
52
     *
53
     * @access public
54
     * @return void
55
     */
56
    public function destroy()
57
    {
58
        if (PHP_SESSION_ACTIVE === session_status()) {
59
            session_unset();
60
            session_destroy();
61
        }
62
    }
63
64
    /**
65
     * Getter session element
66
     *
67
     * @access public
68
     *
69
     * @param string $name element name
70
     *
71
     * @return mixed
72
     */
73
    public function __get($name)
0 ignored issues
show
__get uses the super-global variable $_SESSION 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...
74
    {
75
        return array_key_exists($name, $_SESSION) ? $_SESSION[$name] : null;
76
    }
77
78
    /**
79
     * Setter session element
80
     *
81
     * @access public
82
     *
83
     * @param string $name element name
84
     * @param mixed $value element value
85
     *
86
     * @return void
87
     */
88
    public function __set($name, $value)
0 ignored issues
show
__set uses the super-global variable $_SESSION 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...
89
    {
90
        $_SESSION[$name] = $value;
91
    }
92
93
    /**
94
     * Is set session element
95
     *
96
     * @access public
97
     *
98
     * @param string $name element name
99
     *
100
     * @return boolean
101
     */
102
    public function __isset($name)
0 ignored issues
show
__isset uses the super-global variable $_SESSION 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...
103
    {
104
        return array_key_exists($name, $_SESSION);
105
    }
106
107
    /**
108
     * Unset session element
109
     *
110
     * @access public
111
     *
112
     * @param string $name element name
113
     *
114
     * @return void
115
     */
116
    public function __unset($name)
0 ignored issues
show
__unset uses the super-global variable $_SESSION 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...
117
    {
118
        if (array_key_exists($name, $_SESSION)) {
119
            unset($_SESSION[$name]);
120
        }
121
    }
122
}
123