Fix HTTP 403 on login: add Origin and Referer headers
UniFi OS enforces CSRF protection on the login endpoint itself and returns 403 if Origin/Referer headers are absent, regardless of whether the credentials are correct. Required headers: Origin: https://controller:port Referer: https://controller:port/login Documented in Art-of-WiFi UniFi-API-client reference implementation. https://claude.ai/code/session_01UsuvFAmmeagtQa14QA4iaq
This commit is contained in:
parent
7fdf156f5f
commit
78a2b41329
1 changed files with 5 additions and 1 deletions
|
|
@ -38,7 +38,11 @@ class UniFiController {
|
||||||
CURLOPT_COOKIEFILE => $this->cookieFile,
|
CURLOPT_COOKIEFILE => $this->cookieFile,
|
||||||
CURLOPT_TIMEOUT => 10,
|
CURLOPT_TIMEOUT => 10,
|
||||||
CURLOPT_CONNECTTIMEOUT => 5,
|
CURLOPT_CONNECTTIMEOUT => 5,
|
||||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
CURLOPT_HTTPHEADER => [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Origin: ' . $this->controllerUrl,
|
||||||
|
'Referer: ' . $this->controllerUrl . '/login',
|
||||||
|
],
|
||||||
CURLOPT_HEADERFUNCTION => function($ch, $header) {
|
CURLOPT_HEADERFUNCTION => function($ch, $header) {
|
||||||
$parts = explode(':', $header, 2);
|
$parts = explode(':', $header, 2);
|
||||||
if (count($parts) === 2) {
|
if (count($parts) === 2) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue