Issues (7)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Connector/Ldap.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\ldap\Connector;
6
7
use SimpleSAML\Assert\Assert;
8
use SimpleSAML\Error;
9
use SimpleSAML\Logger;
10
use SimpleSAML\Module\ldap\ConnectorInterface;
11
use Symfony\Component\Ldap\Adapter\AdapterInterface;
12
use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter;
13
use Symfony\Component\Ldap\Entry;
14
use Symfony\Component\Ldap\Exception\InvalidCredentialsException;
15
use Symfony\Component\Ldap\Exception\LdapException;
16
use Symfony\Component\Ldap\Ldap as LdapObject;
17
18
use function array_merge;
19
use function array_pop;
20
use function explode;
21
use function implode;
22
use function ini_get;
23
use function sprintf;
24
use function var_export;
25
26
class Ldap implements ConnectorInterface
27
{
28
    use LdapHelpers;
29
30
    /**
31
     * @var \Symfony\Component\Ldap\Adapter\AdapterInterface
32
     */
33
    protected AdapterInterface $adapter;
34
35
    /**
36
     * @var \Symfony\Component\Ldap\Ldap
37
     */
38
    protected LdapObject $connection;
39
40
41
    /**
42
     * @param string $connection_strings
43
     * @param string $encryption
44
     * @param int $version
45
     * @param string $extension
46
     * @param bool $debug
47
     * @param array<mixed> $options
48
     */
49
    public function __construct(
50
        string $connection_strings,
51
        string $encryption = 'ssl',
52
        int $version = 3,
53
        string $extension = 'ext_ldap',
0 ignored issues
show
The parameter $extension is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
        /** @scrutinizer ignore-unused */ string $extension = 'ext_ldap',

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
        bool $debug = false,
55
        array $options = ['referrals' => false, 'network_timeout' => 3],
56
    ) {
57
        foreach (explode(' ', $connection_strings) as $connection_string) {
58
            Assert::regex($connection_string, '#^ldap[s]?:\/\/#');
59
        }
60
61
        Logger::debug(sprintf(
62
            "Setting up LDAP connection: host='%s', encryption=%s, version=%d, debug=%s, timeout=%d, referrals=%s.",
63
            $connection_strings,
64
            $encryption,
65
            $version,
66
            var_export($debug, true),
67
            $options['timeout'] ?? ini_get('default_socket_timeout'),
68
            var_export($options['referrals'] ?? false, true),
69
        ));
70
71
        $this->adapter = new Adapter(
72
            [
73
                'connection_string' => $connection_strings,
74
                'encryption'        => $encryption,
75
                'version'           => $version,
76
                'debug'             => $debug,
77
                'options'           => $options,
78
            ],
79
        );
80
81
        $this->connection = new LdapObject($this->adapter);
82
    }
83
84
85
    /**
86
     * @return \Symfony\Component\Ldap\Adapter\AdapterInterface
87
     */
88
    public function getAdapter(): AdapterInterface
89
    {
90
        return $this->adapter;
91
    }
92
93
94
    /**
95
     * @inheritDoc
96
     */
97
    public function bind(?string $username, #[\SensitiveParameter]?string $password): void
98
    {
99
        try {
100
            $this->connection->bind($username, strval($password));
101
        } catch (InvalidCredentialsException $e) {
102
            throw new Error\Error($this->resolveBindException());
103
        }
104
105
        if ($username === null) {
106
            Logger::debug("LDAP bind(): Anonymous bind succesful.");
107
        } else {
108
            Logger::debug(sprintf("LDAP bind(): Bind successful for DN '%s'.", $username));
109
        }
110
    }
111
112
    /**
113
     * @inheritDoc
114
     */
115
    public function saslBind(
116
        ?string $username,
117
        #[\SensitiveParameter]?string $password,
118
        ?string $mech,
119
        ?string $realm,
120
        ?string $authcId,
121
        ?string $authzId,
122
        ?string $props,
123
    ): void {
124
        if (!method_exists($this->connection, 'saslBind')) {
125
            throw new Error\Error("SASL not implemented");
126
        }
127
128
        try {
129
            $this->connection->saslBind($username, strval($password), $mech, $realm, $authcId, $authzId, $props);
130
        } catch (InvalidCredentialsException $e) {
131
            throw new Error\Error($this->resolveBindException());
132
        }
133
134
        if ($username === null) {
135
            Logger::debug("LDAP bind(): Anonymous bind succesful.");
136
        } else {
137
            Logger::debug(sprintf("LDAP bind(): Bind successful for DN '%s'.", $username));
138
        }
139
    }
140
141
    /**
142
     * @inheritDoc
143
     */
144
    public function whoami(): string
145
    {
146
        if (!method_exists($this->connection, 'whoami')) {
147
            throw new Error\Error("SASL not implemented");
148
        }
149
150
        return $this->connection->whoami();
151
    }
152
153
    /**
154
     * @inheritDoc
155
     */
156
    public function search(
157
        array $searchBase,
158
        string $filter,
159
        array $options,
160
        bool $allowMissing,
161
    ): ?Entry {
162
        $entry = null;
163
164
        foreach ($searchBase as $base) {
165
            $query  = $this->connection->query($base, $filter, $options);
166
            $result = $query->execute()->toArray();
167
168
            if (count($result) > 1) {
169
                throw new Error\Exception(sprintf(
170
                    "LDAP search(): Found %d entries searching base '%s' for '%s'",
171
                    count($result),
172
                    $base,
173
                    $filter,
174
                ));
175
            } elseif (count($result) === 1) {
176
                $entry = array_pop($result);
177
                Logger::debug(sprintf(
178
                    "LDAP search(): Found 1 entry searching base '%s' for '%s'",
179
                    $base,
180
                    $filter,
181
                ));
182
                break;
183
            } else {
184
                Logger::debug(sprintf(
185
                    "LDAP search(): Found no entries searching base '%s' for '%s'",
186
                    $base,
187
                    $filter,
188
                ));
189
            }
190
        }
191
192
        if ($entry === null && $allowMissing === false) {
193
            throw new Error\Exception(sprintf(
194
                "Object not found using search base [%s] and filter '%s'",
195
                implode(', ', $searchBase),
196
                $filter,
197
            ));
198
        }
199
200
        return $entry;
201
    }
202
203
204
    /**
205
     * @inheritDoc
206
     */
207
    public function searchForMultiple(
208
        array $searchBase,
209
        string $filter,
210
        array $options,
211
        bool $allowMissing,
212
    ): array {
213
        $results = [];
214
215
        foreach ($searchBase as $base) {
216
            $query   = $this->connection->query($base, $filter, $options);
217
            $result  = $query->execute()->toArray();
218
            $results = array_merge($results, $result);
219
220
            Logger::debug(sprintf(
221
                "Library - LDAP search(): Found %d entries searching base '%s' for '%s'",
222
                count($result),
223
                $base,
224
                $filter,
225
            ));
226
        }
227
228
        if (empty($results) && ($allowMissing === false)) {
229
            throw new Error\Exception(sprintf(
230
                "No Objects found using search base [%s] and filter '%s'",
231
                implode(', ', $searchBase),
232
                $filter,
233
            ));
234
        }
235
236
        return $results;
237
    }
238
239
240
    /**
241
     * Resolve the message to a UI exception
242
     *
243
     * @return string
244
     */
245
    protected function resolveBindException(): string
246
    {
247
        return self::ERR_WRONG_PASS;
248
    }
249
250
251
    /**
252
     * @param \Symfony\Component\Ldap\Entry $entry
253
     * @return bool
254
     */
255
    public function updateEntry(Entry $entry): bool
256
    {
257
        try {
258
            $this->adapter->getEntryManager()->update($entry);
259
            return true;
260
        } catch (LdapException $e) {
261
            Logger::warning($e->getMessage());
262
            return false;
263
        }
264
    }
265
}
266