The portal derives the device MAC instead of trusting the caller
This commit is contained in:
31
src/Support/MacAddress.php
Normal file
31
src/Support/MacAddress.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user