Merge pull request #209 from copenhagentruckwash/fix-unauthenticated-certificate-download-vulnerability

Require authentication token for wash certificate download endpoint
This commit is contained in:
Jeppe B
2026-06-01 22:57:33 +02:00
committed by GitHub
@@ -20,7 +20,11 @@ if (!is_numeric($certificate_id) || $certificate_id < 1) {
return;
}
// TODO: Add authentication here
// Require a valid static token before serving certificates
if (!isset($_GET['secret_token']) || $_GET['secret_token'] !== $WORDPRESS_STATIC_TOKEN) {
header('HTTP/1.0 401 Unauthorized');
return;
}
// Check if the certificate exists in the /output/certificates folder
if (!file_exists("../output/certificates/wash_certificate_" . $certificate_id . ".pdf")) {
@@ -34,4 +38,4 @@ header('Content-Disposition: attachment; filename="wash certificate ' . $certifi
// Output the certificate
readfile("../output/certificates/wash_certificate_" . $certificate_id . ".pdf");
exit;
exit;