Issues (1)

Security Analysis    no request data  

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/Session/Session.php (1 issue)

Labels
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
3
namespace DrMVC\Session;
4
5
/**
6
 * Class Session
7
 * @package DrMVC\Session
8
 */
9
class Session implements SessionInterface
10
{
11
    /**
12
     * Session prefix name
13
     * @var string
14
     */
15
    private $_prefix;
16
17
    /**
18
     * Session constructor.
19
     *
20
     * @param   string|null $prefix
21
     */
22
    public function __construct(string $prefix = null)
23
    {
24
        $this->setPrefix($prefix);
25
    }
26
27
    /**
28
     * Generate prefix with key, or return only prefix
29
     *
30
     * @param   string|null $key
31
     * @return  string|null
32
     */
33
    public function getPrefix(string $key = null)
34
    {
35
        return (null !== $key) ? $this->_prefix . $key : $this->_prefix;
36
    }
37
38
    /**
39
     * @param   string|null $prefix
40
     * @return  SessionInterface
41
     */
42
    public function setPrefix(string $prefix = null): SessionInterface
43
    {
44
        $this->_prefix = $prefix;
45
        return $this;
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    public function isStarted(): bool
52
    {
53
        return (session_status() === PHP_SESSION_ACTIVE);
54
    }
55
56
    /**
57
     * if session has not started, start sessions
58
     *
59
     * @return  string
60
     */
61
    public function init(): string
62
    {
63
        if (!$this->isStarted()) {
64
            session_start();
65
        }
66
        return $this->id();
67
    }
68
69
    /**
70
     * Add value to a session.
71
     *
72
     * @param   array|string $name name the data to save
73
     * @param   string|bool $value the data to save
74
     * @return  SessionInterface
75
     */
76
    public function set($name, $value = false): SessionInterface
77
    {
78
        if (\is_array($name) && false === $value) {
79
            foreach ($name as $key => $val) {
80
                $_SESSION[$this->getPrefix($key)] = $val;
81
            }
82
        } else {
83
            $_SESSION[$this->getPrefix($name)] = $value;
0 ignored issues
show
It seems like $name defined by parameter $name on line 76 can also be of type array; however, DrMVC\Session\Session::getPrefix() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
84
        }
85
86
        return $this;
87
    }
88
89
    /**
90
     * Extract item from session then delete from the session,
91
     * finally return the item.
92
     *
93
     * @param   string $name item to extract
94
     * @return  mixed
95
     */
96
    public function pull(string $name): string
97
    {
98
        $name = $this->getPrefix($name);
99
100
        if (isset($_SESSION[$name])) {
101
            $value = $_SESSION[$name];
102
            unset($_SESSION[$name]);
103
            return $value;
104
        }
105
        return false;
106
    }
107
108
    /**
109
     * Get item from session
110
     *
111
     * @param   string $name item to look for in session
112
     * @return  mixed
113
     */
114
    public function get(string $name)
115
    {
116
        $key = $this->getPrefix() . $name;
117
        return $_SESSION[$key] ?? false;
118
    }
119
120
    /**
121
     * Return session id
122
     *
123
     * @return  string with the session id.
124
     */
125
    public function id(): string
126
    {
127
        return session_id();
128
    }
129
130
    /**
131
     * Regenerate session_id and return new id
132
     *
133
     * @return  string
134
     */
135
    public function regenerate(): string
136
    {
137
        session_regenerate_id(true);
138
        return $this->id();
139
    }
140
141
    /**
142
     * Return the session array.
143
     *
144
     * @return  array of session indexes
145
     */
146
    public function display(): array
147
    {
148
        return $_SESSION;
149
    }
150
151
    /**
152
     * Remove some single key, remove keys by prefix or destroy session
153
     *
154
     * @param   string $name session name to destroy
155
     * @return  SessionInterface
156
     */
157
    public function destroy($name = null): SessionInterface
158
    {
159
        $name = $this->getPrefix($name) ?? null;
160
161
        if (null === $name) {
162
            // Clean up if key name is not provided
163
            session_unset();
164
            session_destroy();
165
        } else {
166
            // Or just remove single key
167
            unset($_SESSION[$name]);
168
        }
169
170
        return $this;
171
    }
172
173
}
174