Validate hostname to ensure no nefarious attacks are attempted by manipulating it.

This commit is contained in:
Andy Miller
2015-10-15 11:31:32 -06:00
parent babd50fb6c
commit 30f09994d6

View File

@@ -12,6 +12,8 @@ use Grav\Common\Page\Pages;
*/
class Uri
{
const HOSTNAME_REGEX = '/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/';
public $url;
protected $basename;
@@ -35,6 +37,9 @@ class Uri
// Remove port from HTTP_HOST generated $name
$name = Utils::substrToString($name, ':');
// Validate the hostname
$name = preg_match(Uri::HOSTNAME_REGEX, $name) ? $name : 'unknown';
$port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';