Add more info to getLoginStatus and enforce stricter access control

AJAX를 많이 사용하는 페이지나 SPA에서 member.getLoginStatus API를 통해
현재 로그인 상태에 대해 더 자세한 정보를 알 수 있도록 함과 동시에,
이 정보를 외부에서 가로채지 못하도록 리퍼러 체크 및 CORS 제한을 추가
This commit is contained in:
Kijin Sung 2022-10-20 16:15:07 +09:00
parent 2ca32e0062
commit ed131897c5

View file

@ -179,8 +179,22 @@ class memberModel extends member
*/
public function getLoginStatus()
{
// Check origin
$origin = strval(($_SERVER['HTTP_ORIGIN'] ?? '') ?: ($_SERVER['HTTP_REFERER'] ?? ''));
if ($origin !== '' && $origin !== 'null' && !Rhymix\Framework\URL::isInternalURL($origin))
{
throw new Rhymix\Framework\Exceptions\SecurityViolation();
}
// Add CORS restriction
header('Access-Control-Allow-Origin: ' . rtrim(Rhymix\Framework\Url::getCurrentDomainURL(), '/'));
header('Cross-Origin-Resource-Policy: same-origin');
// Return login status and CSRF token
Context::setResponseMethod('JSON');
$this->add('status', Rhymix\Framework\Session::getLoginStatus());
$this->add('csrf_token', Rhymix\Framework\Session::getGenericToken());
$this->add('last_login', Rhymix\Framework\Session::getLastLoginTime());
}
/**