From d55dd98e6841436e0feea01c610b9b93d559b22b Mon Sep 17 00:00:00 2001 From: Dedushka Date: Sun, 17 Jan 2021 13:03:17 -0500 Subject: [PATCH] Protect IPv6 IPs in public moderation logs. As reported, IPv6 addresses were not properly hidden in the public facing moderation logs. This commit filters both IPv4 and IPv6 addresses. --- inc/mod/pages.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index af2613da..ef0c00cc 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -742,11 +742,13 @@ function mod_board_log($board, $page_no = 1, $hide_names = false, $public = fals error($config['error']['404']); if (!hasPermission($config['mod']['show_ip'])) { - // Supports ipv4 only! + $ipv4_regex = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; + $ipv6_regex = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'; + + $ipv4_link_regex = '/(?:)?(' . $ipv4_regex . ')(?:<\/a>)?/'; + $ipv6_link_regex = '/(?:)?(' . $ipv6_regex . ')(?:<\/a>)?/'; foreach ($logs as $i => &$log) { - $log['text'] = preg_replace_callback('/(?:)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?:<\/a>)?/', function($matches) { - return "xxxx";//less_ip($matches[1]); - }, $log['text']); + $log['text'] = preg_replace(array($ipv4_link_regex, $ipv6_link_regex), "xxxx", $log['text']); } }