The portal derives the device MAC instead of trusting the caller

This commit is contained in:
2026-08-21 13:18:30 -04:00
parent ccd6fc49b2
commit 4322d07b40
4 changed files with 168 additions and 21 deletions

View File

@@ -0,0 +1,31 @@
<?php
namespace Dashboard\Unifi\Support;
/**
* Pure MAC helpers. No dependencies, so they are cheap to test and safe to call
* from anywhere.
*/
class MacAddress
{
/** Lower-case, colon-separated, or null if it is not a MAC at all. */
public static function normalise(?string $mac): ?string
{
$mac = strtolower(str_replace('-', ':', trim((string) $mac)));
return preg_match('/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/', $mac) ? $mac : null;
}
/**
* Is this a private (randomized) address rather than a real manufacturer one?
*
* The locally-administered bit is the second-least-significant bit of the
* first octet. iOS "Private Wi-Fi Address" and Android per-network
* randomization both set it. This is why OUI is useless for identifying
* device types: a randomized MAC has no real manufacturer prefix.
*/
public static function isRandomized(string $mac): bool
{
return (bool) (hexdec(substr($mac, 0, 2)) & 0b10);
}
}