Skip to content

Commit 5870d27

Browse files
committed
add check for special characters in login shell
1 parent 4c14eef commit 5870d27

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

resources/lib/UnityUser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,10 @@ public function getSSHKeys($ignorecache = false)
446446
*/
447447
public function setLoginShell($shell, $operator = null, $send_mail = true)
448448
{
449-
// FIXME throw error if shell is not ascii
450449
// ldap schema syntax is "IA5 String (1.3.6.1.4.1.1466.115.121.1.26)"
450+
if (!mb_check_encoding($shell, 'ASCII')) {
451+
throw new Exception("non ascii characters are not allowed in a login shell!");
452+
}
451453
$ldapUser = $this->getLDAPUser();
452454
if ($ldapUser->exists()) {
453455
$ldapUser->setAttribute("loginshell", $shell);

webroot/panel/account.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@
257257

258258
<hr>
259259

260-
261260
<script>
262261
const sitePrefix = '<?php echo $CONFIG["site"]["prefix"]; ?>';
263262
const ldapLoginShell = '<?php echo $USER->getLoginShell(); ?>';
@@ -289,6 +288,57 @@ function showOrHideCustomLoginBox() {
289288
$("#loginSelector").change(showOrHideCustomLoginBox);
290289
showOrHideCustomLoginBox();
291290

291+
function getNewLoginShell() {
292+
var loginSelectorVal = $("#loginSelector").val();
293+
if (loginSelectorVal != "Custom") {
294+
return loginSelectorVal;
295+
}
296+
return $("#customLoginBox").val();
297+
}
298+
299+
function isLoginShellValid(x) {
300+
if (x.trim().length === 0) {
301+
return false;
302+
}
303+
// only ascii characters allowed
304+
if (!(/^[\x00-\x7F]*$/.test(x))) {
305+
return false;
306+
}
307+
return true;
308+
}
309+
310+
function enableOrDisableCustomLoginBoxHighlight() {
311+
if (
312+
($("#customLoginSelectorOption").prop("selected") == true) &&
313+
!isLoginShellValid($("#customLoginBox").val())
314+
) {
315+
$("#customLoginBox").css("box-shadow", "0 0 0 0.3rem rgba(220, 53, 69, 0.25)");
316+
} else {
317+
$("#customLoginBox").css("box-shadow", "none");
318+
}
319+
}
320+
$("#customLoginBox").on("input", enableOrDisableCustomLoginBoxHighlight);
321+
$("#loginSelector").change(enableOrDisableCustomLoginBoxHighlight);
322+
enableOrDisableCustomLoginBoxHighlight();
323+
324+
function enableOrDisableSubmitLoginShell() {
325+
var newLoginShell = getNewLoginShell();
326+
if (!isLoginShellValid(newLoginShell)) {
327+
$("#submitLoginShell").prop("disabled", true);
328+
$("#submitLoginShell").prop("title", "Invalid Login Shell");
329+
return;
330+
}
331+
if (newLoginShell == ldapLoginShell) {
332+
$("#submitLoginShell").prop("disabled", true);
333+
$("#submitLoginShell").prop("title", "Login Shell Unchanged");
334+
return;
335+
}
336+
$("#submitLoginShell").prop("disabled", false);
337+
$("#submitLoginShell").prop("title", "Submit Login Shell");
338+
}
339+
$("#customLoginBox").on("input", enableOrDisableSubmitLoginShell);
340+
$("#loginSelector").change(enableOrDisableSubmitLoginShell);
341+
enableOrDisableSubmitLoginShell()
292342
</script>
293343

294344
<style>

0 commit comments

Comments
 (0)