Issues (25)

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/Mvc/Util/Session.php (2 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 Nkey\Caribu\Mvc\Util;
3
4
use IteratorAggregate;
5
6
/**
7
 * This class contains to the Caribu MVC package.
8
 *
9
 * It provides an abstract access to session variables.
10
 *
11
 * @author Maik Greubel <[email protected]>
12
 */
13
class Session implements \IteratorAggregate
14
{
15
16
    /**
17
     * The session data
18
     *
19
     * @var array
20
     */
21
    private $sessionData = array();
22
23
    /**
24
     * The session namespace
25
     *
26
     * @var string
27
     */
28
    private $namespace = null;
29
30
    /**
31
     * The session identifier
32
     *
33
     * @var string
34
     */
35
    private $sessionId;
36
37
    /**
38
     * Create a new session instance
39
     *
40
     * @param string $namespace
41
     *            Optional name of session namespace
42
     */
43
    public function __construct($namespace = null)
0 ignored issues
show
__construct 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...
44
    {
45
        session_start();
46
        $this->sessionId = session_id();
47
        
48
        if (null === $namespace) {
49
            $this->sessionData = $_SESSION;
50
        } else {
51
            if (! isset($_SESSION[$namespace])) {
52
                $_SESSION[$namespace] = array();
53
            }
54
            $this->sessionData = $_SESSION[$namespace];
55
        }
56
    }
57
58
    /**
59
     * Set a specific session key to arbitrary data
60
     *
61
     * @param string $key
62
     *            The session data key
63
     * @param mixed $value
64
     *            The value
65
     */
66
    public function set($key, $value)
67
    {
68
        $this->sessionData[$key] = $value;
69
        $this->update();
70
    }
71
72
    /**
73
     * Destroy the session
74
     */
75
    public function destroy()
76
    {
77
        $this->sessionData = array();
78
        session_destroy();
79
    }
80
81
    /**
82
     * Update internal session data
83
     */
84
    private function update()
0 ignored issues
show
update 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...
85
    {
86
        if (null !== $this->namespace) {
87
            $_SESSION[$this->namespace] = $this->sessionData;
88
        } else {
89
            $_SESSION = $this->sessionData;
90
        }
91
    }
92
93
    /**
94
     * Get specific session data
95
     *
96
     * @param string $key
97
     * @return NULL|mixed
98
     */
99
    public function get($key)
100
    {
101
        return $this->has($key) ? $this->sessionData[$key] : null;
102
    }
103
104
    /**
105
     * Checks whether a specific key exists in session data
106
     *
107
     * @param string $key
108
     */
109
    public function has($key)
110
    {
111
        return isset($this->sessionData[$key]);
112
    }
113
114
    /**
115
     * (non-PHPdoc)
116
     *
117
     * @see IteratorAggregate::getIterator()
118
     */
119
    public function getIterator()
120
    {
121
        return new \ArrayIterator($this->sessionData);
122
    }
123
}
124