Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Apr 24, 2024
1 parent 1bd2c78 commit 4aeff50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
6 changes: 6 additions & 0 deletions web/app/Actions/CreateLinuxWebUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public function handle()
$command = 'sudo echo '.$username.':'.$password.' | chpasswd -e';
$output .= shell_exec($command);

$homeDir = '/home';
if (substr(sprintf('%o', fileperms($homeDir)), -4) !== '0711') {
$command = 'sudo chmod 711 /home';
$output .= shell_exec($command);
}

$command = 'sudo chmod 711 /home/'.$username;
$output .= shell_exec($command);

Expand Down
29 changes: 17 additions & 12 deletions web/tests/Unit/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function testSecurity()
$hostingSubscription = $callHostingSubscriptionStoreResponse['data']['hostingSubscription'];

// Check user home dir permissions
$homeDir = '/home';
$this->assertDirectoryExists($homeDir);
$getHomeDirPermission = substr(sprintf('%o', fileperms($homeDir)), -4);
$this->assertSame('0711', $getHomeDirPermission);

$userHomeDir = '/home/' . $hostingSubscription['system_username'];
$this->assertDirectoryExists($userHomeDir);
$getUserHomeDirPermission = substr(sprintf('%o', fileperms($userHomeDir)), -4);
Expand Down Expand Up @@ -109,18 +114,18 @@ public function testSecurity()
$this->assertTrue($callHostingSubscriptionStoreResponse['status'] == 'ok');
$secondHostingSubscription = $callHostingSubscriptionStoreResponse['data']['hostingSubscription'];

// // Try to open /home directory with linux user
// $output = shell_exec("sudo -H -u ".$hostingSubscription['system_username']." bash -c 'ls -la /home'");
// $this->assertSame($output, null);
//
// // Try to open /home/$user with linux user
// $output = shell_exec("sudo -H -u ".$hostingSubscription['system_username']." bash -c 'ls -la /home/".$hostingSubscription['system_username']."'");
// $this->assertTrue(str_contains($output, 'public_html'));
// $this->assertTrue(str_contains($output, $hostingSubscription['system_username']));
//
// // Try to open /home/$user directory with another linux user
// $output = shell_exec("sudo -H -u ".$secondHostingSubscription['system_username']." bash -c 'ls -la /home/".$hostingSubscription['system_username']."'");
// $this->assertSame($output, null);
// Try to open /home directory with linux user
$output = shell_exec("sudo -H -u ".$hostingSubscription['system_username']." bash -c 'ls -la /home'");
$this->assertSame($output, null);

// Try to open /home/$user with linux user
$output = shell_exec("sudo -H -u ".$hostingSubscription['system_username']." bash -c 'ls -la /home/".$hostingSubscription['system_username']."'");
$this->assertTrue(str_contains($output, 'public_html'));
$this->assertTrue(str_contains($output, $hostingSubscription['system_username']));

// Try to open /home/$user directory with another linux user
$output = shell_exec("sudo -H -u ".$secondHostingSubscription['system_username']." bash -c 'ls -la /home/".$hostingSubscription['system_username']."'");
$this->assertSame($output, null);


}
Expand Down

0 comments on commit 4aeff50

Please sign in to comment.