Skip to content

Commit 605e1b5

Browse files
committed
Added in functionality to require a minimum username length and for a username blacklist which helps to prevent unneeded LDAP authentication attempts.
1 parent c94133e commit 605e1b5

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed

configuration.example.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,97 @@
171171
'denied_ip' => [],
172172
],
173173
'public_keys' => [],
174+
];
175+
176+
// Add a minimum length for usernames (set to 0 to ignore length):
177+
$username_minimum_length = 4;
178+
179+
// This list of usernames will simply be ignored completed (no LDAP authentication will occur):
180+
$username_blacklist = [
181+
'admin',
182+
'apagar',
183+
'auto',
184+
'bananapi',
185+
'bdadmin',
186+
'billing',
187+
'bin',
188+
'crm',
189+
'csgoserver',
190+
'deploy',
191+
'eas',
192+
'escaner',
193+
'factorio',
194+
'fedena',
195+
'fernando',
196+
'ftp',
197+
'ftp_id',
198+
'ftpserver',
199+
'ftpuser',
200+
'furukawa',
201+
'gc',
202+
'git',
203+
'gitblit',
204+
'gmod',
205+
'guest',
206+
'hxeadm',
207+
'ircd',
208+
'kafka',
209+
'kk',
210+
'koha',
211+
'kms',
212+
'mariadb',
213+
'minecraft',
214+
'mysql',
215+
'node',
216+
'odoo',
217+
'oozie',
218+
'openvpn',
219+
'operator',
220+
'oracle',
221+
'pcguest',
222+
'pi',
223+
'platform',
224+
'plcmspip',
225+
'postgres',
226+
'prueba',
227+
'prueba1',
228+
'rpm',
229+
'root',
230+
'rs',
231+
'sample',
232+
'secretaria',
233+
'shutdown',
234+
'sinus',
235+
'squadserver',
236+
'steam',
237+
'student',
238+
'student10',
239+
'support',
240+
'sysadmin',
241+
'teacher',
242+
'teacher1',
243+
'teamspeak',
244+
'temp',
245+
'test',
246+
'test1',
247+
'test001',
248+
'teste',
249+
'testftp',
250+
'trinity',
251+
'ts3',
252+
'ts3bot',
253+
'ubuntu',
254+
'user',
255+
'usuario',
256+
'uploader',
257+
'vbox',
258+
'vboxuser',
259+
'voip',
260+
'vyos',
261+
'web5',
262+
'webftp',
263+
'www',
264+
'www-data',
265+
'zabbix',
266+
'zte',
174267
];

functions.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ function authenticateUser($data) {
2727
if (!empty($data)) {
2828

2929
try {
30-
global $connections, $domains_to_strip_automatically, $convert_username_to_lowercase;
30+
global $connections, $domains_to_strip_automatically, $convert_username_to_lowercase, $username_minimum_length, $username_blacklist;
3131

32+
// Convert username to lowercase if setting is enabled:
3233
if (isset($convert_username_to_lowercase) && $convert_username_to_lowercase === true) {
34+
$beforeUsername = $data['username'];
3335
$data['username'] = strtolower($data['username']);
36+
37+
if ($beforeUsername !== $data['username']) {
38+
logMessage('Converted ' . $beforeUsername . ' to ' . $data['username']);
39+
}
3440
}
3541

3642
// Strip specific organization email domains if provided:
@@ -43,6 +49,22 @@ function authenticateUser($data) {
4349
}
4450
}
4551

52+
// Prevent short usernames from being processed:
53+
if (isset($username_minimum_length) && $username_minimum_length > 0) {
54+
if (strlen($data['username']) < $username_minimum_length) {
55+
logMessage('Denying ' . $data['username'] . ' since length is less than minimum allowed (' . $username_minimum_length . ')');
56+
return denyRequest();
57+
}
58+
}
59+
60+
// Prevent blacklisted usernames from being processed:
61+
if (isset($username_blacklist) && !empty($username_blacklist)) {
62+
if (array_search($data['username'], $username_blacklist) !== false) {
63+
logMessage('Denying ' . $data['username'] . ' since it is in the username blacklist');
64+
return denyRequest();
65+
}
66+
}
67+
4668
foreach($connections as $connectionName => $connection) {
4769

4870
logMessage('Before connection attempt to ' . $connectionName);

0 commit comments

Comments
 (0)