Issues (1208)

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/LightSaml/Context/AbstractContext.php (5 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
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Context;
13
14
abstract class AbstractContext implements ContextInterface
15
{
16
    /** @var ContextInterface|null */
17
    private $parent;
18
19
    /** @var ContextInterface[] */
20
    private $subContexts = array();
21
22
    /**
23
     * @return ContextInterface|null
24
     */
25 71
    public function getParent()
26
    {
27 71
        return $this->parent;
28
    }
29
30
    /**
31
     * @return ContextInterface
32
     */
33 63
    public function getTopParent()
34
    {
35 63
        if ($this->getParent()) {
36 3
            return $this->getParent()->getTopParent();
37
        }
38
39 63
        return $this;
40
    }
41
42
    /**
43
     * @param ContextInterface|null $parent
44
     *
45
     * @return ContextInterface
46
     */
47 130
    public function setParent(ContextInterface $parent = null)
48
    {
49 130
        $this->parent = $parent;
50
51 130
        return $this;
52
    }
53
54
    /**
55
     * @param string      $name
56
     * @param null|string $class
57
     *
58
     * @return ContextInterface|null
59
     */
60 134
    public function getSubContext($name, $class = null)
61
    {
62 134
        if (isset($this->subContexts[$name])) {
63 103
            return $this->subContexts[$name];
64
        }
65
66 131
        if ($class) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $class of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
67 129
            $result = $this->createSubContext($class);
68 129
            $this->addSubContext($name, $result);
69
70 129
            return $result;
71
        }
72
73 4
        return null;
74
    }
75
76
    /**
77
     * @param string $class
78
     * @param bool   $autoCreate
79
     *
80
     * @return ContextInterface|null
81
     */
82
    public function getSubContextByClass($class, $autoCreate)
83
    {
84
        return $this->getSubContext($class, $autoCreate ? $class : null);
85
    }
86
87
    /**
88
     * @param string                  $name
89
     * @param object|ContextInterface $subContext
90
     *
91
     * @return AbstractContext
92
     */
93 139
    public function addSubContext($name, $subContext)
94
    {
95 139
        if (false === is_object($subContext)) {
96 1
            throw new \InvalidArgumentException('Expected object or ContextInterface');
97
        }
98
99 138
        $existing = isset($this->subContexts[$name]) ? $this->subContexts[$name] : null;
100 138
        if ($existing === $subContext) {
101 1
            return $this;
102
        }
103
104 138
        $this->subContexts[$name] = $subContext;
105 138
        if ($subContext instanceof ContextInterface) {
106 130
            $subContext->setParent($this);
107
        }
108
109 138
        if ($existing instanceof ContextInterface) {
110 1
            $existing->setParent(null);
111
        }
112
113 138
        return $this;
114
    }
115
116
    /**
117
     * @param string $name
118
     *
119
     * @return ContextInterface
120
     */
121 2
    public function removeSubContext($name)
122
    {
123 2
        $subContext = $this->getSubContext($name, false);
0 ignored issues
show
false is of type boolean, but the function expects a null|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
125 2
        if ($subContext) {
126 2
            $subContext->setParent(null);
127 2
            unset($this->subContexts[$name]);
128
        }
129
130 2
        return $this;
131
    }
132
133
    /**
134
     * @param string $name
135
     *
136
     * @return bool
137
     */
138 2
    public function containsSubContext($name)
139
    {
140 2
        return isset($this->subContexts[$name]);
141
    }
142
143
    /**
144
     * @return ContextInterface
145
     */
146 1
    public function clearSubContexts()
147
    {
148 1
        foreach ($this->subContexts as $subContext) {
149 1
            $subContext->setParent(null);
150
        }
151 1
        $this->subContexts = array();
152
153 1
        return $this;
154
    }
155
156
    /**
157
     * @return \ArrayIterator
158
     */
159 6
    public function getIterator()
160
    {
161 6
        return new \ArrayIterator($this->subContexts);
162
    }
163
164
    /**
165
     * @param string $ownName
166
     *
167
     * @return array
168
     */
169 2
    public function debugPrintTree($ownName = 'root')
170
    {
171
        $result = array(
172 2
            $ownName => static::class,
173
        );
174
175 2
        if ($this->subContexts) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->subContexts of type LightSaml\Context\ContextInterface[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
176 2
            $arr = array();
177 2
            foreach ($this->subContexts as $name => $subContext) {
178 2 View Code Duplication
                if ($subContext instanceof ContextInterface) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
179 2
                    $arr = array_merge($arr, $subContext->debugPrintTree($name));
180
                } else {
181 2
                    $arr = array_merge($arr, array($name => get_class($subContext)));
182
                }
183
            }
184 2
            $result[$ownName.'__children'] = $arr;
185
        }
186
187 2
        return $result;
188
    }
189
190
    /**
191
     * @return string
192
     */
193 1
    public function __toString()
194
    {
195 1
        return json_encode($this->debugPrintTree(), JSON_PRETTY_PRINT);
196
    }
197
198
    /**
199
     * @param string $path
200
     *
201
     * @return ContextInterface
202
     */
203 3
    public function getPath($path)
204
    {
205 3
        if (is_string($path)) {
206 3
            $path = explode('/', $path);
207 3
        } elseif (false === is_array($path)) {
208
            throw new \InvalidArgumentException('Expected string or array');
209
        }
210
211 3
        $name = array_shift($path);
212 3
        $subContext = $this->getSubContext($name);
213 3
        if (null == $subContext) {
214 2
            return null;
215
        }
216
217 3
        if (empty($path)) {
218 1
            return $subContext;
219
        } else {
220 3
            return $subContext->getPath($path);
0 ignored issues
show
$path is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
221
        }
222
    }
223
224
    /**
225
     * @param string $class
226
     *
227
     * @return ContextInterface
228
     */
229 129
    protected function createSubContext($class)
230
    {
231 129
        $result = new $class();
232
233 129
        return $result;
234
    }
235
}
236