Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for banned IPs #4379

Open
wants to merge 1 commit into
base: feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion admin/modules/config/banning.php
Expand Up @@ -35,6 +35,28 @@
$errors[] = $lang->error_filter_already_banned;
}

if(!$errors && $mybb->input['type'] == 1)
{
$ip_address = $db->escape_string($mybb->input['filter']);
$subnet_mask = "0";
if(strpos($ip_address, "*") !== false)
{
$ip_address = str_replace("*", "0", $ip_address);
}
else if(strpos($ip_address, "/") !== false)
{
list($ip_address, $subnet_mask) = explode("/", $ip_address);
}

$is_valid_v4 = filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && $subnet_mask <= 32 && $subnet_mask >= 0;
$is_valid_v6 = filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && $subnet_mask <= 128 && $subnet_mask >= 0;

if (!$is_valid_v4 && !$is_valid_v6 || !ctype_digit($subnet_mask))
{
$errors[] = $lang->error_invalid_filter;
}
}

if(!$errors)
{
$new_filter = array(
Expand Down Expand Up @@ -100,7 +122,7 @@
// Does the filter not exist?
if(!$filter['fid'])
{
flash_message($lang->error_invalid_filter, 'error');
flash_message($lang->error_filter_not_found, 'error');
admin_redirect("index.php?module=config-banning");
}

Expand Down
3 changes: 2 additions & 1 deletion inc/languages/english/admin/config_banning.lang.php
Expand Up @@ -34,7 +34,8 @@
$l['ban_ip_address'] = "Ban IP Address";

$l['error_missing_ban_input'] = "You did not enter a value to ban.";
$l['error_invalid_filter'] = "The specified filter does not exist.";
$l['error_invalid_filter'] = "The specified filter is not valid.";
$l['error_filter_not_found'] = "The specified filter does not exist.";
$l['error_filter_already_banned'] = "The filter you entered is already banned.";
n-thumann marked this conversation as resolved.
Show resolved Hide resolved

$l['success_ip_banned'] = "The IP address has been banned successfully.";
Expand Down