From b120d441d5cc18d61df4b37068343e1569166a75 Mon Sep 17 00:00:00 2001 From: lolcat Date: Mon, 30 Nov 2026 17:24:40 -0500 Subject: [PATCH] f --- data/config.php | 11 +++++++++++ lib/backend.php | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/data/config.php b/data/config.php index 00e0a49..80412f6 100644 --- a/data/config.php +++ b/data/config.php @@ -83,6 +83,17 @@ class config{ //["minecraft", 848] ]; + // + // HMAC SIGNATURES + // + // If null, no signatures are added to proxy URLs and resolver targets. + // If a hex string, will be used as the secret and signatures will be appended. + // Generate one in a PHP session like this: echo bin2hex(random_bytes(32)); + const HMAC_SECRET = null; + + // Time the tokens remain valid, in minutes + const HMAC_TTL = 720; + // If this regex expression matches on the user agent, it blocks the request // Not useful at all against a targetted attack const HEADER_REGEX = '/bot|wget|curl|python-requests|scrapy|go-http-client|ruby|yahoo|spider|qwant|meta/i'; diff --git a/lib/backend.php b/lib/backend.php index d30f461..925cae4 100644 --- a/lib/backend.php +++ b/lib/backend.php @@ -347,7 +347,7 @@ class backend{ $header = pack("CN", $purpose, intdiv(time(), 60)); - $hash = hash_hmac("sha256", $header . $payload, config::HMAC_SECRET, true); + $hash = hash_hmac("sha256", $header . $payload, hex2bin(config::HMAC_SECRET), true); return rtrim(strtr(base64_encode( $header . $hash @@ -403,7 +403,7 @@ class backend{ // check hmac $r_header = pack("CN", $expected_purpose, $timestamp); - $r_hash = hash_hmac("sha256", $r_header . $payload, config::HMAC_SECRET, true); + $r_hash = hash_hmac("sha256", $r_header . $payload, hex2bin(config::HMAC_SECRET), true); if(!hash_equals($signature, $r_hash)){