mirror of
git://f0xx.org/ac/ac-platform-php
synced 2026-07-29 04:18:41 +03:00
fix(session): honor X-Forwarded-Proto; widen auth route matching
Secure session cookies behind TLS-terminating FE. resolve_console_route recognizes /two-factor/approve and /api/two-factor/poll. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -11,12 +11,14 @@ function platform_start_session(string $sessionName = 'ac_crash_sess', string $c
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
session_name($sessionName);
|
session_name($sessionName);
|
||||||
|
$secure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|
||||||
|
|| strtolower((string) ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '')) === 'https';
|
||||||
session_set_cookie_params([
|
session_set_cookie_params([
|
||||||
'lifetime' => 0,
|
'lifetime' => 0,
|
||||||
'path' => $cookiePath,
|
'path' => $cookiePath,
|
||||||
'httponly' => true,
|
'httponly' => true,
|
||||||
'samesite' => 'Lax',
|
'samesite' => 'Lax',
|
||||||
'secure' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'),
|
'secure' => $secure,
|
||||||
]);
|
]);
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ function resolve_console_route(string $uri): string {
|
|||||||
if ($projectRoot !== '' && str_starts_with($uri, $projectRoot)) {
|
if ($projectRoot !== '' && str_starts_with($uri, $projectRoot)) {
|
||||||
$suffix = substr($uri, strlen($projectRoot)) ?: '/';
|
$suffix = substr($uri, strlen($projectRoot)) ?: '/';
|
||||||
$candidate = rtrim(strtok($suffix, '?') ?: '/', '/') ?: '/';
|
$candidate = rtrim(strtok($suffix, '?') ?: '/', '/') ?: '/';
|
||||||
if (preg_match('#^/(login|logout|register|two-factor|verify-email)(?:/|$)#', $candidate)) {
|
if (preg_match('#^/(login|logout|register|verify-email|two-factor(?:/approve)?|api/two-factor(?:/poll)?)(/|$)#', $candidate)) {
|
||||||
return $candidate;
|
return $candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user