Skip to content

Commit

Permalink
Merge pull request #974 from pi-hole/fix/admin-email-validation
Browse files Browse the repository at this point in the history
Prevent command injection via admin email
  • Loading branch information
AzureMarker committed Jul 3, 2019
2 parents 3928026 + f790516 commit 00d9b3d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scripts/pi-hole/php/savesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ function validMAC($mac_addr)
return (preg_match('/([a-fA-F0-9]{2}[:]?){6}/', $mac_addr) == 1);
}

function validEmail($email)
{
return filter_var($email, FILTER_VALIDATE_EMAIL)
// Make sure that the email does not contain special characters which
// may be used to execute shell commands, even though they may be valid
// in an email address. If the escaped email does not equal the original
// email, it is not safe to store in setupVars.
&& escapeshellcmd($email) === $email;
}

$dhcp_static_leases = array();
function readStaticLeasesFile()
{
Expand Down Expand Up @@ -481,7 +491,7 @@ function readAdlists()
{
$adminemail = 'noadminemail';
}
elseif(!filter_var($adminemail, FILTER_VALIDATE_EMAIL) || strpos($adminemail, "'") !== false)
elseif(!validEmail($adminemail))
{
$error .= "Administrator email address (".htmlspecialchars($adminemail).") is invalid!<br>";
}
Expand Down

0 comments on commit 00d9b3d

Please sign in to comment.