feat(announcer): Block browser by checking the User-Agent (#1764)

This commit is contained in:
Roman Kelesidis 2025-01-16 15:10:10 +03:00 committed by GitHub
commit 7b64b50819
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -138,10 +138,20 @@ if (!isset($left) || $left < 0) {
*
* @see https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/c64275f0b5dcb3c4c845d5204871adfe24f359d6/app/Http/Controllers/AnnounceController.php#L177
*/
if (strlen((string)$_SERVER['HTTP_USER_AGENT']) > 64) {
$userAgent = (string)$_SERVER['HTTP_USER_AGENT'];
if (strlen($userAgent) > 64) {
msg_die('User-Agent must be less than 64 characters long');
}
/**
* Block Browser by checking the User-Agent
*
* @see https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/c64275f0b5dcb3c4c845d5204871adfe24f359d6/app/Http/Controllers/AnnounceController.php#L182
*/
if (preg_match('/(Mozilla|Browser|Chrome|Safari|AppleWebKit|Opera|Links|Lynx|Bot|Unknown)/i', $userAgent)) {
msg_die('Browser disallowed');
}
// IP
$ip = $_SERVER['REMOTE_ADDR'];