Move DNS rebind detection in to javascript; uses /dnscheck nginx endpoint to test this

This commit is contained in:
Eric Schultz
2017-09-02 13:13:13 -05:00
parent 84838c7cef
commit 6440d16fa5
2 changed files with 11 additions and 20 deletions
+1 -14
View File
@@ -16,20 +16,7 @@ $text = $_POST['text'] ?? '';
file_put_contents('/boot/config/ssl/certs/certificate_bundle.pem.new', $text);
//validate certificate_bundle.pem.new is for *.unraid.net before moving it over to certificate_bundle.pem
if (preg_match('/CN=([0-9a-f]{40}\.unraid\.net)$/', exec('openssl x509 -in /boot/config/ssl/certs/certificate_bundle.pem.new -subject -noout 2>&1'), $matches)) {
// Successful cases:
// If unraid.net and <hash>.unraid.net both fail then the dns servers are inaccessible ==> cross-fingers and hope their browser has proper dns
// If unraid.net and <hash>.unraid.net both resolve ==> dns rebinding protection isn't going to be a issue
//
// Failure case:
// If unraid.net resolves but <hash>.unraid.net fails ==> dns rebinding protection is a issue
if (count(dns_get_record('unraid.net', DNS_A)) !== count(dns_get_record($matches[1], DNS_A))) {
http_response_code(406);
header("Content-Type: application/json");
echo json_encode(['error' => 'Your router or configured DNS servers are protecting against DNS rebinding thus preventing this SSL certificate from working. See help for more details and workarounds']);
exit;
}
if (preg_match('/CN=[0-9a-f]{40}\.unraid\.net$/', exec('openssl x509 -in /boot/config/ssl/certs/certificate_bundle.pem.new -subject -noout 2>&1'))) {
rename('/boot/config/ssl/certs/certificate_bundle.pem.new', '/boot/config/ssl/certs/certificate_bundle.pem');
} else {
unlink('/boot/config/ssl/certs/certificate_bundle.pem.new');