Issues (190)

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.

bundles/lib/Ldap.php (4 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
 * Ldap
5
 *
6
 * @category  	lib
7
 * @author    	Judicaël Paquet <[email protected]>
8
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
9
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
10
 * @version   	Release: 1.0.0
11
 * @filesource	https://github.com/las93/venus2
12
 * @link      	https://github.com/las93
13
 * @since     	1.0.2
14
 */
15
namespace Venus\lib;
16
17
use \Venus\core\Config as Config;
18
19
/**
20
 * Ldap library
21
 *
22
 * @category  	core
23
 * @author    	Judicaël Paquet <[email protected]>
24
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
25
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
26
 * @version   	Release: 1.0.0
27
 * @filesource	https://github.com/las93/venus2
28
 * @link      	https://github.com/las93
29
 * @since     	1.0.2
30
 */
31
class Ldap
32
{
33
    /**
34
     * connection at ldap server
35
     * 
36
     * @access private
37
     * @var    resource
38
     */
39
	private $_rConnect;
40
	
41
	/**
42
	 * the databse to connect
43
	 * 
44
	 * @access private
45
	 * @var    string
46
	 */
47
	private $_sBase;
48
	
49
	/**
50
	 * if the user is connected or not
51
	 * 
52
	 * @access private
53
	 * @var    bool
54
	 */
55
	private $_bConnected = false;
56
57
	/**
58
	 * constructor of class
59
	 * 
60
	 * @access public
61
	 * @return \Venus\lib\Ldap
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
62
	 */
63
	public function __construct()
64
	{
65
	    $oDbConf = Config::get('Ldap')->configuration;
66
67
		$this->_sBase = $oDbConf->base;
68
69
		$this->_rConnect = ldap_connect($oDbConf->host, $oDbConf->port);
70
71
		$this->set_option(LDAP_OPT_REFERRALS, 0);
0 ignored issues
show
Documentation Bug introduced by
The method set_option does not exist on object<Venus\lib\Ldap>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
72
	}
73
74
	/**
75
	 * Get groups
76
	 *
77
	 * @access public
78
	 * @return array
79
	 */
80
    public function getGroups() : array
81
    {
82
        $rSearch = ldap_search( $this->_rConnect , $this->_sBase , "objectclass=group" , array("cn") );
83
        $aEntries = ldap_get_entries($this->_rConnect, $rSearch);
84
        $aGroups = array();
85
86
        for ( $i = 0 ; $i < $aEntries["count"] ; $i++ ) {
87
            
88
            $aGroups[] = utf8_encode($aEntries[$i]["dn"]);
89
        }
90
91
        return $aGroups;
92
    }
93
94
    /**
95
     * Authentification in Ldap
96
     * 
97
     * @access public
98
     * @param  string $sUser
99
     * @param  string $sPassword
100
     * @return \Venus\lib\Ldap
101
     */
102
	public function bind($sUser, $sPassword) : Ldap
103
	{
104
		return $this->_bConnected = ldap_bind($this->_rConnect, $sUser, $sPassword);
105
		return $this;
0 ignored issues
show
return $this; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
106
	}
107
108
	/**
109
	 * Close authentification in Ldap
110
	 *
111
	 * @access public
112
	 * @return bool
113
	 */
114
	public function unbind() : bool
115
	{
116
	    if ($this->_bConnected) { return $this->_bConnected = ldap_unbind($this->_rConnect); }
117
	    else { return true; }
118
	}
119
120
	/**
121
	 * destructor of the class
122
	 *
123
	 * @access public
124
	 * @return void
125
	 */
126
	public function __destruct()
127
	{
128
		$this->close();
0 ignored issues
show
Documentation Bug introduced by
The method close does not exist on object<Venus\lib\Ldap>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
129
	}
130
131
	/**
132
	 * Call a classic ldap method. You have to ignore the ldap_ part
133
	 * You put all parameters without the connector
134
	 *
135
	 * @access public
136
	 * @param  string $sFunctionName
137
	 * @param  array $aArgv
138
	 * @return void
139
	 */
140
	public function __call(string $sFunctionName, array $aArgv)
141
	{
142
		array_unshift($argv, $this->_rConnect);
143
		return call_user_func_array('ldap_'.$sFunctionName, $aArgv);
144
	}
145
146
	/**
147
	 * get in Ldap
148
	 *
149
	 * @access public
150
	 * @param  string $sFilter
151
	 * @param  array $aAttributes
152
	 * @return array
153
	 */
154
	public function get(string $sFilter, array $aAttributes)
155
	{
156
		$res = $this->search($sFilter, $aAttributes);
157
158
		return $this->getEntries($res, $aAttributes);
159
	}
160
161
	/**
162
	 * search in Ldap
163
	 *
164
	 * @access public
165
	 * @param  string $sFilter
166
	 * @param  array $aAttributes
167
	 * @return resource
168
	 */
169
	public function search(string $sFilter, array $aAttributes)
170
	{
171
		return ldap_search($this->_rConnect, $this->_sBase, $sFilter, $aAttributes);
172
	}
173
174
	/**
175
	 * get in Ldap
176
	 *
177
	 * @access public
178
	 * @param  resource $rResultIdentifier
179
	 * @param  array $aAttributes
180
	 * @return array
181
	 */
182
	public function getEntries($rResultIdentifier, array $aAttributes) : array
183
	{
184
		$aEntries = ldap_get_entries($this->_rConnect, $rResultIdentifier);
185
186
		$aMask = array_flip($aAttributes);
187
188
		$aResultSet = array();
189
190
		for ($i = 0, $count = $aEntries['count']; $i < $count; ++$i) {
191
		    
192
			$aResultSet[$i] = array_intersect_key($aEntries[$i], $aMask);
193
194
			foreach($aResultSet[$i] as &$aValues) {
195
			    
196
				unset($aValues['count']);
197
			}
198
		}
199
200
		return $aResultSet;
201
	}
202
}
203