Browse Source

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.
main
Dedushka 3 years ago
committed by discomrade
parent
commit
d55dd98e68
  1. 10
      inc/mod/pages.php

10
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 = '/(?:<a href="\?\/IP\/'. $ipv4_regex . '">)?(' . $ipv4_regex . ')(?:<\/a>)?/';
$ipv6_link_regex = '/(?:<a href="\?\/IP\/'. $ipv6_regex . '">)?(' . $ipv6_regex . ')(?:<\/a>)?/';
foreach ($logs as $i => &$log) {
$log['text'] = preg_replace_callback('/(?:<a href="\?\/IP\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}">)?(\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']);
}
}

Loading…
Cancel
Save