Skip to content

Commit 06d0edf

Browse files
author
Till Brehm
committed
Merge branch '5643-confidential-issue' into 'stable-3.1'
- disallow several folders for vhost subdomains and aliasdomains See merge request ispconfig/ispconfig3!1067
2 parents a1e7fda + cb4ddc3 commit 06d0edf

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

interface/lib/classes/system.inc.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,42 @@ public function has_service($userid, $service) {
6767
}
6868
}
6969

70+
public function is_blacklisted_web_path($path) {
71+
$blacklist = array('bin', 'cgi-bin', 'dev', 'etc', 'home', 'lib', 'lib64', 'log', 'ssl', 'usr', 'var', 'proc', 'net', 'sys', 'srv', 'sbin', 'run');
72+
73+
$path = ltrim($path, '/');
74+
$parts = explode('/', $path);
75+
if(in_array(strtolower($parts[0]), $blacklist, true)) {
76+
return true;
77+
}
78+
79+
return false;
80+
}
81+
7082
public function last_exec_out() {
7183
return $this->_last_exec_out;
7284
}
73-
85+
7486
public function last_exec_retcode() {
7587
return $this->_last_exec_retcode;
7688
}
77-
89+
7890
public function exec_safe($cmd) {
7991
$arg_count = func_num_args();
8092
$args = func_get_args();
81-
93+
8294
if($arg_count != substr_count($cmd, '?') + 1) {
8395
trigger_error('Placeholder count not matching argument list.', E_USER_WARNING);
8496
return false;
8597
}
8698
if($arg_count > 1) {
8799
array_shift($args);
88-
100+
89101
$pos = 0;
90102
$a = 0;
91103
foreach($args as $value) {
92104
$a++;
93-
105+
94106
$pos = strpos($cmd, '?', $pos);
95107
if($pos === false) {
96108
break;
@@ -100,16 +112,16 @@ public function exec_safe($cmd) {
100112
$pos += strlen($value);
101113
}
102114
}
103-
115+
104116
$this->_last_exec_out = null;
105117
$this->_last_exec_retcode = null;
106118
return exec($cmd, $this->_last_exec_out, $this->_last_exec_retcode);
107119
}
108-
120+
109121
public function system_safe($cmd) {
110122
call_user_func_array(array($this, 'exec_safe'), func_get_args());
111123
return implode("\n", $this->_last_exec_out);
112-
}
124+
}
113125

114126
//* Check if a application is installed
115127
public function is_installed($appname) {
@@ -122,5 +134,5 @@ public function is_installed($appname) {
122134
return false;
123135
}
124136
}
125-
137+
126138
} //* End Class

interface/web/sites/web_vhost_domain_edit.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,7 @@ function onSubmit() {
10301030
$this->dataRecord['web_folder'] = strtolower($this->dataRecord['web_folder']);
10311031
if(substr($this->dataRecord['web_folder'], 0, 1) === '/') $this->dataRecord['web_folder'] = substr($this->dataRecord['web_folder'], 1);
10321032
if(substr($this->dataRecord['web_folder'], -1) === '/') $this->dataRecord['web_folder'] = substr($this->dataRecord['web_folder'], 0, -1);
1033-
$forbidden_folders = array('', 'cgi-bin', 'log', 'private', 'ssl', 'tmp', 'webdav');
1034-
$check_folder = strtolower($this->dataRecord['web_folder']);
1035-
if(substr($check_folder, 0, 1) === '/') $check_folder = substr($check_folder, 1); // strip / at beginning to check against forbidden entries
1036-
if(strpos($check_folder, '/') !== false) $check_folder = substr($check_folder, 0, strpos($check_folder, '/')); // get the first part of the path to check it
1037-
if(in_array($check_folder, $forbidden_folders)) {
1033+
if($app->system->is_blacklisted_web_path($this->dataRecord['web_folder'])) {
10381034
$app->tform->errorMessage .= $app->tform->lng("web_folder_invalid_txt")."<br>";
10391035
}
10401036

server/lib/classes/system.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,18 @@ function set_immutable($path, $enable = true, $recursive = false) {
17871787
}
17881788
}
17891789

1790+
public function is_blacklisted_web_path($path) {
1791+
$blacklist = array('bin', 'cgi-bin', 'dev', 'etc', 'home', 'lib', 'lib64', 'log', 'ssl', 'usr', 'var', 'proc', 'net', 'sys', 'srv', 'sbin', 'run');
1792+
1793+
$path = ltrim($path, '/');
1794+
$parts = explode('/', $path);
1795+
if(in_array(strtolower($parts[0]), $blacklist, true)) {
1796+
return true;
1797+
}
1798+
1799+
return false;
1800+
}
1801+
17901802
function web_folder_protection($document_root, $protect) {
17911803
global $app, $conf;
17921804

server/plugins-available/apache2_plugin.inc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,11 @@ function update($event_name, $data) {
580580
$log_folder .= '/' . $subdomain_host;
581581
unset($tmp);
582582

583+
if($app->system->is_blacklisted_web_path($web_folder)) {
584+
$app->log('Vhost is using a blacklisted web folder: ' . $web_folder, LOGLEVEL_ERROR);
585+
return 0;
586+
}
587+
583588
if(isset($data['old']['parent_domain_id'])) {
584589
// old one
585590
$tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ?', $data['old']['parent_domain_id']);

server/plugins-available/nginx_plugin.inc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ function update($event_name, $data) {
425425
$log_folder .= '/' . $subdomain_host;
426426
unset($tmp);
427427

428+
if($app->system->is_blacklisted_web_path($web_folder)) {
429+
$app->log('Vhost is using a blacklisted web folder: ' . $web_folder, LOGLEVEL_ERROR);
430+
return 0;
431+
}
432+
428433
if(isset($data['old']['parent_domain_id'])) {
429434
// old one
430435
$tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ?', $data['old']['parent_domain_id']);

0 commit comments

Comments
 (0)