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

Trim user input where applicable #1293

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/pi-hole/js/groups-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function addClient() {
var ip = $("#select").val();
var comment = $("#new_comment").val();
if (ip === "custom") {
ip = $("#ip-custom").val();
ip = $("#ip-custom").val().trim();
}

utils.disableAll();
Expand Down
4 changes: 2 additions & 2 deletions scripts/pi-hole/php/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ function error($msg)
try
{
if(isset($_REQUEST['ip']))
$ip = $_REQUEST['ip'];
$ip = trim($_REQUEST['ip']);

if(isset($_REQUEST['domain']))
$domain = $_REQUEST['domain'];
$domain = trim($_REQUEST['domain']);

if (empty($ip))
return error("IP must be set");
Expand Down
25 changes: 14 additions & 11 deletions scripts/pi-hole/php/savesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ function addStaticDHCPLease($mac, $ip, $hostname) {
if(array_key_exists("custom".$i,$_POST))
{
$exploded = explode("#", $_POST["custom".$i."val"], 2);
$IP = $exploded[0];
$IP = trim($exploded[0]);
if(count($exploded) > 1)
{
$port = $exploded[1];
$port = trim($exploded[1]);
}
else
{
Expand Down Expand Up @@ -326,22 +326,25 @@ function addStaticDHCPLease($mac, $ip, $hostname) {
// Check if Conditional Forwarding is requested
if(isset($_POST["conditionalForwarding"]))
{
$conditionalForwardingIP = trim($_POST["conditionalForwardingIP"]);
$conditionalForwardingDomain = trim($_POST["conditionalForwardingDomain"]);

// Validate conditional forwarding IP
if (!validIP($_POST["conditionalForwardingIP"]))
if (!validIP($conditionalForwardingIP))
{
$error .= "Conditional forwarding IP (".htmlspecialchars($_POST["conditionalForwardingIP"]).") is invalid!<br>";
$error .= "Conditional forwarding IP (".htmlspecialchars($conditionalForwardingIP).") is invalid!<br>";
}

// Validate conditional forwarding domain name
if(!validDomain($_POST["conditionalForwardingDomain"]))
if(!validDomain($conditionalForwardingDomain))
{
$error .= "Conditional forwarding domain name (".htmlspecialchars($_POST["conditionalForwardingDomain"]).") is invalid!<br>";
$error .= "Conditional forwarding domain name (".htmlspecialchars($conditionalForwardingDomain).") is invalid!<br>";
}
if(!$error)
{
$addressArray = explode(".", $_POST["conditionalForwardingIP"]);
$addressArray = explode(".", $conditionalForwardingIP);
$reverseAddress = $addressArray[2].".".$addressArray[1].".".$addressArray[0].".in-addr.arpa";
$extra .= " conditional_forwarding ".$_POST["conditionalForwardingIP"]." ".$_POST["conditionalForwardingDomain"]." $reverseAddress";
$extra .= " conditional_forwarding ".$conditionalForwardingIP." ".$conditionalForwardingDomain." $reverseAddress";
}
}

Expand Down Expand Up @@ -588,9 +591,9 @@ function addStaticDHCPLease($mac, $ip, $hostname) {

if(isset($_POST["addstatic"]))
{
$mac = $_POST["AddMAC"];
$ip = $_POST["AddIP"];
$hostname = $_POST["AddHostname"];
$mac = trim($_POST["AddMAC"]);
$ip = trim($_POST["AddIP"]);
$hostname = trim($_POST["AddHostname"]);

addStaticDHCPLease($mac, $ip, $hostname);
break;
Expand Down