Issues (37)

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/Storageless/Session/DefaultSessionData.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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
declare(strict_types=1);
20
21
namespace PSR7Sessions\Storageless\Session;
22
23
use InvalidArgumentException;
24
use JsonSerializable;
25
use stdClass;
26
use function array_key_exists;
27
use function assert;
28
use function count;
29
use function is_array;
30
use function is_string;
31
use function json_decode;
32
use function json_encode;
33
use function json_last_error;
34
use function json_last_error_msg;
35
use function sprintf;
36
use function var_export;
37
use const JSON_PRESERVE_ZERO_FRACTION;
38
39
final class DefaultSessionData implements SessionInterface
40
{
41
    /** @var array<string, int|bool|string|float|mixed[]|null> */
42
    private array $data;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
43
44
    /** @var array<string, int|bool|string|float|mixed[]|null> */
45
    private array $originalData;
46
47
    /**
48
     * Instantiation via __construct is not allowed, use
49
     * - {@see DefaultSessionData::fromDecodedTokenData}
50
     * - {@see DefaultSessionData::fromTokenData}
51
     * - {@see DefaultSessionData::newEmptySession}
52
     * instead
53
     */
54 194
    private function __construct()
55
    {
56 194
    }
57
58 33
    public static function fromDecodedTokenData(stdClass $data) : self
59
    {
60 33
        $instance = new self();
61
62 33
        $arrayShapedData = self::convertValueToScalar($data);
63 33
        assert(is_array($arrayShapedData));
64
65 33
        $instance->originalData = $instance->data = $arrayShapedData;
66
67 33
        return $instance;
68
    }
69
70
    /** @param mixed[] $data */
71 75
    public static function fromTokenData(array $data) : self
72
    {
73 75
        $instance = new self();
74
75 75
        $instance->data = [];
76
77 75
        foreach ($data as $key => $value) {
78 73
            $instance->set((string) $key, $value);
79
        }
80
81 74
        $instance->originalData = $instance->data;
82
83 74
        return $instance;
84
    }
85
86 108
    public static function newEmptySession() : self
87
    {
88 108
        $instance = new self();
89
90 108
        $instance->originalData = $instance->data = [];
91
92 108
        return $instance;
93
    }
94
95
    /**
96
     * {@inheritDoc}
97
     */
98 136
    public function set(string $key, $value) : void
99
    {
100 136
        $this->data[$key] = self::convertValueToScalar($value);
101 135
    }
102
103
    /**
104
     * {@inheritDoc}
105
     */
106 95
    public function get(string $key, $default = null)
107
    {
108 95
        if (! $this->has($key)) {
109 26
            return self::convertValueToScalar($default);
110
        }
111
112 69
        return $this->data[$key];
113
    }
114
115 1
    public function remove(string $key) : void
116
    {
117 1
        unset($this->data[$key]);
118 1
    }
119
120 4
    public function clear() : void
121
    {
122 4
        $this->data = [];
123 4
    }
124
125 96
    public function has(string $key) : bool
126
    {
127 96
        return array_key_exists($key, $this->data);
128
    }
129
130 90
    public function hasChanged() : bool
131
    {
132 90
        return $this->data !== $this->originalData;
133
    }
134
135 50
    public function isEmpty() : bool
136
    {
137 50
        return ! count($this->data);
138
    }
139
140 41
    public function jsonSerialize() : object
141
    {
142 41
        return (object) $this->data;
143
    }
144
145
    /**
146
     * @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value
147
     *
148
     * @return int|bool|string|float|mixed[]
149
     */
150 183
    private static function convertValueToScalar($value)
151
    {
152 183
        $jsonScalar = json_encode($value, JSON_PRESERVE_ZERO_FRACTION);
153
154 183
        if (! is_string($jsonScalar)) {
155
            // @TODO use PHP 7.3 and JSON_THROW_ON_ERROR instead? https://wiki.php.net/rfc/json_throw_on_error
156 1
            throw new InvalidArgumentException(sprintf(
157 1
                'Could not serialise given value %s due to %s (%s)',
158 1
                var_export($value, true),
159 1
                json_last_error_msg(),
160 1
                json_last_error()
161
            ));
162
        }
163
164 182
        return json_decode($jsonScalar, true);
165
    }
166
}
167