Skip to content

Commit 614b23b

Browse files
author
Till Brehm
committed
Added apache directives check agains regex blacklist in security settings.
1 parent b18d6ed commit 614b23b

27 files changed

+79
-2
lines changed

interface/lib/classes/IDS/Monitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private function detect($key, $value)
250250
$filterSet = $this->storage->getFilterSet();
251251

252252
if ($tags = $this->tags) {
253-
$filterSet = array_filter(
253+
$filterSet = @array_filter(
254254
$filterSet,
255255
function (Filter $filter) use ($tags) {
256256
return (bool) array_intersect($tags, $filter->getTags());
@@ -259,7 +259,7 @@ function (Filter $filter) use ($tags) {
259259
}
260260

261261
$scanKeys = $this->scanKeys;
262-
$filterSet = array_filter(
262+
$filterSet = @array_filter(
263263
$filterSet,
264264
function (Filter $filter) use ($key, $value, $scanKeys) {
265265
return $filter->match($value) || $scanKeys && $filter->match($key);

interface/lib/classes/validate_domain.inc.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,45 @@ function web_domain_autosub($field_name, $field_value, $validator) {
9797
$result = $this->_check_unique($field_value . '.' . $check_domain, true);
9898
if(!$result) return $this->get_error('domain_error_autosub');
9999
}
100+
101+
/* Check apache directives */
102+
function web_apache_directives($field_name, $field_value, $validator) {
103+
global $app;
104+
105+
if(trim($field_value) != '') {
106+
$security_config = $app->getconf->get_security_config('ids');
107+
108+
if($security_config['apache_directives_scan_enabled'] == 'yes') {
109+
110+
// Get blacklist
111+
$blacklist_path = '/usr/local/ispconfig/security/apache_directives.blacklist';
112+
if(is_file('/usr/local/ispconfig/security/apache_directives.blacklist.custom')) $blacklist_path = '/usr/local/ispconfig/security/apache_directives.blacklist.custom';
113+
if(!is_file($blacklist_path)) $blacklist_path = realpath(ISPC_ROOT_PATH.'/../security/apache_directives.blacklist');
114+
115+
$directives = explode("\n",$field_value);
116+
$regex = explode("\n",file_get_contents($blacklist_path));
117+
$blocked = false;
118+
$blocked_line = '';
119+
120+
if(is_array($directives) && is_array($regex)) {
121+
foreach($directives as $directive) {
122+
$directive = trim($directive);
123+
foreach($regex as $r) {
124+
if(preg_match(trim($r),$directive)) {
125+
$blocked = true;
126+
$blocked_line = $directive;
127+
};
128+
}
129+
}
130+
}
131+
}
132+
}
133+
134+
if($blocked === true) {
135+
return $this->get_error('apache_directive_blocked_error').' '.$blocked_line;
136+
}
137+
}
138+
100139

101140
/* internal validator function to match regexp */
102141
function _regex_validate($domain_name, $allow_wildcard = false) {
@@ -175,5 +214,6 @@ function _wildcard_limit() {
175214
}
176215
return true; // admin may always add wildcard domain
177216
}
217+
178218

179219
}

interface/web/sites/form/web_domain.tform.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,13 @@
730730
'apache_directives' => array (
731731
'datatype' => 'TEXT',
732732
'formtype' => 'TEXT',
733+
'validators' => array ( 0 => array(
734+
'type' => 'CUSTOM',
735+
'class' => 'validate_domain',
736+
'function' => 'web_apache_directives',
737+
'errmsg' => 'apache_directive_blockd_error'
738+
),
739+
),
733740
'default' => '',
734741
'value' => '',
735742
'width' => '30',

interface/web/sites/form/web_vhost_subdomain.tform.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,13 @@
706706
'apache_directives' => array (
707707
'datatype' => 'TEXT',
708708
'formtype' => 'TEXT',
709+
'validators' => array ( 0 => array(
710+
'type' => 'CUSTOM',
711+
'class' => 'validate_domain',
712+
'function' => 'web_apache_directives',
713+
'errmsg' => 'apache_directive_blockd_error'
714+
),
715+
),
709716
'default' => '',
710717
'value' => '',
711718
'width' => '30',

interface/web/sites/lib/lang/ar_web_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ $wb['backup_excludes_note_txt'] = '(Separate multiple directories with commas. E
128128
$wb['backup_excludes_error_regex'] = 'The excluded directories contain invalid characters.';
129129
$wb['invalid_custom_php_ini_settings_txt'] = 'Invalid php.ini settings';
130130
$wb['invalid_system_user_or_group_txt'] = 'Invalid system user or group';
131+
$wb['apache_directive_blocked_error'] = 'Apache directive blocked by security settings:';
131132
?>

interface/web/sites/lib/lang/bg_web_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ $wb['backup_excludes_note_txt'] = '(Separate multiple directories with commas. E
128128
$wb['backup_excludes_error_regex'] = 'The excluded directories contain invalid characters.';
129129
$wb['invalid_custom_php_ini_settings_txt'] = 'Invalid php.ini settings';
130130
$wb['invalid_system_user_or_group_txt'] = 'Invalid system user or group';
131+
$wb['apache_directive_blocked_error'] = 'Apache directive blocked by security settings:';
131132
?>

interface/web/sites/lib/lang/br_web_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ $wb['backup_excludes_note_txt'] = '(Separate multiple directories with commas. E
128128
$wb['backup_excludes_error_regex'] = 'The excluded directories contain invalid characters.';
129129
$wb['invalid_custom_php_ini_settings_txt'] = 'Invalid php.ini settings';
130130
$wb['invalid_system_user_or_group_txt'] = 'Invalid system user or group';
131+
$wb['apache_directive_blocked_error'] = 'Apache directive blocked by security settings:';
131132
?>

interface/web/sites/lib/lang/cz_web_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ $wb['backup_excludes_note_txt'] = '(Oddělte více adresářů čárkami. Vzor:
128128
$wb['backup_excludes_error_regex'] = 'Vyloučené adresáře obsahují neplatné znaky.';
129129
$wb['invalid_custom_php_ini_settings_txt'] = 'Neplatné nastavení php.ini';
130130
$wb['invalid_system_user_or_group_txt'] = 'Invalid system user or group';
131+
$wb['apache_directive_blocked_error'] = 'Apache directive blocked by security settings:';
131132
?>

interface/web/sites/lib/lang/de_web_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ $wb['backup_excludes_note_txt'] = '(Mehrere Verzeichnisse mit Kommas trennen. Be
128128
$wb['backup_excludes_error_regex'] = 'Die auszuschließenden Verzeichnisse enthalten ungültige Zeichen.';
129129
$wb['invalid_custom_php_ini_settings_txt'] = 'Unzulässige php.ini-Einstellungen';
130130
$wb['invalid_system_user_or_group_txt'] = 'Invalid system user or group';
131+
$wb['apache_directive_blocked_error'] = 'Die Apache Direktive wurde durch die Sicherheitsrichtline blockiert:';
131132
?>

interface/web/sites/lib/lang/el_web_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ $wb['backup_excludes_note_txt'] = '(Separate multiple directories with commas. E
128128
$wb['backup_excludes_error_regex'] = 'The excluded directories contain invalid characters.';
129129
$wb['invalid_custom_php_ini_settings_txt'] = 'Invalid php.ini settings';
130130
$wb['invalid_system_user_or_group_txt'] = 'Invalid system user or group';
131+
$wb['apache_directive_blocked_error'] = 'Apache directive blocked by security settings:';
131132
?>

0 commit comments

Comments
 (0)