diff options
| author | Luke Bratch <luke@bratch.co.uk> | 2026-08-11 21:53:12 +0100 |
|---|---|---|
| committer | Luke Bratch <luke@bratch.co.uk> | 2026-08-11 21:53:12 +0100 |
| commit | 5f16dd3e1b8b65217f8dc19af09e15df790143dd (patch) | |
| tree | 7c9d6baaef484d1f181f0de241b6d80c3142dc26 /dns.php | |
| parent | 99ea80e0e0f88720dcb39877423c6ec796975bd2 (diff) | |
Diffstat (limited to 'dns.php')
| -rw-r--r-- | dns.php | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -93,6 +93,7 @@ function writezone($domain, $zonetext, $password = null) { } // Escape characters that will break the echo later on + $zonetext = str_replace('\\', '', $zonetext); $zonetext = str_replace('$', '\$', $zonetext); $zonetext = str_replace('"', '\"', $zonetext); @@ -139,6 +140,39 @@ function writezone($domain, $zonetext, $password = null) { // Main entry point +// Ensure zone names are valid +if (isset($_GET['zone'])) { + if (strlen($_GET['zone']) < 3) { + die("error: provided zone is too short\n"); + } + + if (preg_match("/[^a-z0-9-\.]/", $_GET['zone'])) { + die("error: provided zone is invalid\n"); + } +} + +// Ensure hashes are valid +if (isset($_GET['hash'])) { + if (strlen($_GET['hash']) != 64) { + die("error: provided hash doesn't appear to be hex encoded SHA256 - too short\n"); + } + + if (preg_match("/[^A-Fa-f0-9]/", $_GET['hash'])) { + die("error: provided hash doesn't appear to be hex encoded SHA256 - invalid characters\n"); + } +} + +// Ensure domain names are valid +if (isset($_POST['domain'])) { + if (strlen($_POST['domain']) < 3) { + die("error: provided domain is too short\n"); + } + + if (preg_match("/[^a-z0-9-\.]/", $_POST['domain'])) { + die("error: provided domain is invalid\n"); + } +} + if (isset($_GET['mode']) && isset($_GET['zone']) && isset($_GET['hash']) && strlen($_GET['hash']) > 10) { // Some sort of mode (at the moment only "update" is supported if ($_GET['mode'] == "update") { @@ -272,7 +306,7 @@ if (isset($_GET['mode']) && isset($_GET['zone']) && isset($_GET['hash']) && strl } } else if (isset($_POST['domain']) && isset($_POST['password']) && !isset($_POST['zonetext'])) { if (!preg_match('/^[0-9A-Za-z\.\-]*$/', $_POST['domain'])) { - die("invalid domain"); + die("invalid character in domain"); } $password = hash("sha256", $_POST['password']); |
