Skip to content

Commit 9decfa9

Browse files
Merge pull request #5818 from mailcow/fix/web
[Web] fix exception handler and rspamd_maps function
2 parents 17d797c + 3aee2b6 commit 9decfa9

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

data/web/inc/footer.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
$alerts = [];
1313
if (is_array($alertbox_log_parser)) {
1414
foreach ($alertbox_log_parser as $log) {
15-
$message = strtr($log['msg'], ["\n" => '', "\r" => '', "\t" => '<br>']);
15+
$message = htmlspecialchars($log['msg'], ENT_QUOTES);
16+
$message = strtr($message, ["\n" => '', "\r" => '', "\t" => '<br>']);
1617
$alerts[trim($log['type'], '"')][] = trim($message, '"');
1718
}
1819
$alert = array_filter(array_unique($alerts));

data/web/inc/functions.rspamd.inc.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ function rspamd_maps($_action, $_data = null) {
143143
return false;
144144
}
145145
$maps = (array)$_data['map'];
146+
$valid_maps = array();
146147
foreach ($maps as $map) {
147148
foreach ($RSPAMD_MAPS as $rspamd_map_type) {
148149
if (!in_array($map, $rspamd_map_type)) {
@@ -151,9 +152,12 @@ function rspamd_maps($_action, $_data = null) {
151152
'log' => array(__FUNCTION__, $_action, '-'),
152153
'msg' => array('global_map_invalid', $map)
153154
);
154-
continue;
155+
} else {
156+
array_push($valid_maps, $map);
155157
}
156158
}
159+
}
160+
foreach ($valid_maps as $map) {
157161
try {
158162
if (file_exists('/rspamd_custom_maps/' . $map)) {
159163
$map_content = trim($_data['rspamd_map_data']);

data/web/json_api.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ function api_log($_data) {
4747
}
4848
}
4949

50+
// Block requests not intended for direct API use by checking the 'Sec-Fetch-Dest' header.
51+
if (isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] !== 'empty') {
52+
header('HTTP/1.1 403 Forbidden');
53+
exit;
54+
}
55+
5056
if (isset($_GET['query'])) {
5157

5258
$query = explode('/', $_GET['query']);

0 commit comments

Comments
 (0)