Issues (7)

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/SessionFlash.php (2 issues)

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 Sesshin;
4
5
6
    class SessionFlash
7
    {
8
        /**
9
         * Singleton of this class
10
         *
11
         * @var $this
12
         */
13
        public static $singleton;
14
15
        /**
16
         * Object manager of sessions.
17
         *
18
         * @var Session
19
         */
20
        private $session;
21
22
        /**
23
         * Unique ID in each transaction request.
24
         *
25
         * @var int
26
         */
27
        private $msg_id;
28
29
30
        /**
31
         * key name to save the flash dat
32
         *
33
         * @var string
34
         */
35
        protected $key_name = '_flash';
36
37
        /**
38
         * SessionFlash constructor.
39
         *
40
         * @param Session $session
41
         */
42
        public function __construct(Session $session)
43
        {
44
            $this->session = $session;
45
        }
46
47
        /**
48
         * Add a value in the flash session.
49
         *
50
         * @param $value
51
         * @param string $type
52
         */
53
        public function add($value, $type = 'n')
54
        {
55
            $this->session->put($type, $value);
56
            $this->session->push($this->key_name.'.new', $type);
57
            $this->removeFromOldFlashData([$type]);
58
        }
59
60
61
        /**
62
         * Add a value in the flash session.
63
         *
64
         * @param $key
65
         * @param $value
66
         */
67
        public function set($key, $value)
68
        {
69
            $this->session->put($key, $value);
70
            $this->session->push($this->key_name.'.new', $key);
71
            $this->removeFromOldFlashData([$key]);
72
        }
73
74
        /**
75
         * Get a value in the flash session.
76
         *
77
         * @param $key
78
         * @return mixed
79
         */
80
        public function get($key)
81
        {
82
            return $this->session->getValue($key);
83
        }
84
85
        /**
86
         * Determine if exist key in flash data.
87
         *
88
         * @param $key
89
         * @return bool
90
         */
91
        public function has($key)
92
        {
93
            $current_data = $this->session->getValue($key);
94
95
            return isset($current_data);
96
        }
97
98
        /**
99
         * Get all the data or data of a type.
100
         *
101
         * @return mixed
102
         */
103
        public function getCurrentData()
104
        {
105
            $current_data = $this->session->getValue($this->key_name);
106
107
            return isset($current_data) ? $current_data : $current_data = array();
108
        }
109
110
        /**
111
         * Reflash all of the session flash data.
112
         *
113
         * @return void
114
         */
115
        public function reflash()
116
        {
117
            $this->mergeNewFlashes($this->session->getValue($this->key_name.'.old'));
118
            $this->session->setValue($this->key_name.'.old', []);
119
        }
120
121
122
        /**
123
         * Reflash a subset of the current flash data.
124
         *
125
         * @param  array|mixed  $keys
126
         * @return void
127
         */
128
        public function keep($keys = null)
129
        {
130
            $this->mergeNewFlashes($keys = is_array($keys) ? $keys : func_get_args());
131
            $this->removeFromOldFlashData($keys);
132
        }
133
134
135
        /**
136
         * Merge new flash keys into the new flash array.
137
         *
138
         * @param  array  $keys
139
         * @return void
140
         */
141
        protected function mergeNewFlashes(array $keys)
142
        {
143
            $values = array_unique(array_merge($this->session->getValue($this->key_name.'.new'), $keys));
144
            $this->session->setValue($this->key_name.'.new', $values);
145
        }
146
147
        /**
148
         * Remove the given keys from the old flash data.
149
         *
150
         * @param  array  $keys
151
         * @return void
152
         */
153
        protected function removeFromOldFlashData(array $keys)
154
        {
155
            $old_data = $this->session->getValue($this->key_name.'.old');
156
157
            if (! is_array($old_data)) {
158
                $old_data = array();
159
            }
160
            $this->session->setValue($this->key_name.'.old', array_diff($old_data, $keys));
161
        }
162
163
        /**
164
         * Age the flash data for the session.
165
         *
166
         * @return void
167
         */
168
        public function ageFlashData()
169
        {
170
            $old_data = $this->session->getValue($this->key_name.'.old');
171
            if (! is_array($old_data)) {
172
                $old_data = array();
173
            }
174
            $this->session->forget($old_data);
175
            $this->session->put($this->key_name.'.old', $this->session->getValue($this->key_name.'.new'));
176
            $this->session->put($this->key_name.'.new', []);
177
        }
178
179
180
        /**
181
         * Clear all data flash.
182
         *
183
         */
184
        public function clear()
185
        {
186
            $this->session->unsetValue($this->key_name);
187
        }
188
189
190
        /**
191
         * Calling this class in a singleton way.
192
         *
193
         * @param Session|null $session
194
         * @return SessionFlash
195
         */
196
        static function singleton(Session $session = null)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
197
        {
198
            if (self::$singleton == null) {
199
                self::$singleton = new SessionFlash($session);
0 ignored issues
show
It seems like $session defined by parameter $session on line 196 can be null; however, Sesshin\SessionFlash::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
200
            }
201
202
            return self::$singleton;
203
        }
204
    }