Add options to control autologin cookie lifetime and refresh function

This commit is contained in:
Kijin Sung 2023-08-29 23:42:01 +09:00
parent 87300c9944
commit 4af7354bf0
7 changed files with 24 additions and 2 deletions

View file

@ -56,6 +56,8 @@ return array(
'rewrite' => 1,
),
'session' => array(
'autologin_lifetime' => 365,
'autologin_refresh' => true,
'delay' => false,
'use_db' => false,
'use_ssl' => false,

View file

@ -1149,7 +1149,8 @@ class Session
{
// Get session parameters.
list($lifetime, $refresh_interval, $domain, $path, $secure, $httponly, $samesite) = self::_getParams();
$lifetime = time() + (86400 * 365);
$lifetime_days = config('session.autologin_lifetime') ?: 365;
$lifetime = time() + (86400 * $lifetime_days);
// Set the autologin keys.
if ($autologin_key && $security_key)

View file

@ -32,6 +32,8 @@ class Security extends Base
Context::set('remote_addr', RX_CLIENT_IP);
// Session and cookie security settings
Context::set('autologin_lifetime', Config::get('session.autologin_lifetime') ?: 365);
Context::set('autologin_refresh', Config::get('session.autologin_refresh') ?? true);
Context::set('use_httponly', Config::get('session.httponly'));
Context::set('use_samesite', Config::get('session.samesite'));
Context::set('use_session_ssl', Config::get('session.use_ssl'));
@ -127,6 +129,8 @@ class Security extends Base
Config::set('admin.allow', array_values($allowed_ip));
Config::set('admin.deny', array_values($denied_ip));
Config::set('session.autologin_lifetime', max(1, min(400, intval($vars->autologin_lifetime))));
Config::set('session.autologin_refresh', ($vars->autologin_refresh ?? 'N') === 'Y');
Config::set('session.httponly', $vars->use_httponly === 'Y');
Config::set('session.samesite', $vars->use_samesite);
Config::set('session.use_ssl', $vars->use_session_ssl === 'Y');

View file

@ -172,6 +172,9 @@ $lang->use_samesite_empty = 'Do not use';
$lang->about_use_samesite = 'Set the SameSite attribute for session cookies.<br>Lax is the recommended setting for most sites. You may need to use None if you are having difficulties integrating with external services such as payment gateways.<br>However, None is only valid when used with SSL-only sessions.';
$lang->about_x_frame_options = 'Block loading this site in an iframe from another site. This helps prevent clickjacking attacks.<br />SameOrigin is recommended for most sites. Deny will make iframes stop working even on this site.<br />Do not use this setting if you have already enabled the X-Frame-Options header in your server configuration.';
$lang->about_x_content_type_options = 'Prevent browser sniffing of MIME types of documents and attached files.<br />Do not use this setting if you have already enabled the X-Content-Type-Options header in your server configuration.';
$lang->autologin_lifetime = 'Autologin cookie validity';
$lang->autologin_refresh = 'Refresh security key';
$lang->about_autologin_lifetime = 'Select how long autologin cookies will be valid for, from 1 to 400 days.<br>Refreshing the security key periodically makes cookies more secure.';
$lang->use_session_ssl = 'Use SSL-only session';
$lang->about_use_session_ssl = 'Force the session to be SSL-only.<br>This helps improve security if your site always uses SSL.';
$lang->use_cookies_ssl = 'Use SSL-only cookies';

View file

@ -173,6 +173,9 @@ $lang->use_samesite_empty = '표기하지 않음';
$lang->about_use_samesite = '세션 쿠키에 적용되는 SameSite 속성을 선택할 수 있습니다.<br>대부분의 사이트에는 Lax를 권장하며, 최신 브라우저에서 결제 연동 등에 문제가 있는 경우 None을 선택하시기 바랍니다.<br>단, None을 선택할 경우 SSL 전용 세션을 사용하여야 정상 작동합니다.';
$lang->about_x_frame_options = '다른 사이트에서 이 사이트를 iframe으로 로딩하는 것을 차단합니다. Clickjacking 공격 방지에 도움이 됩니다.<br />대부분의 사이트에는 SameOrigin을 추천합니다. Deny로 설정하면 같은 사이트 내에서도 iframe이 작동하지 않습니다.<br />웹서버 설정에서 이미 X-Frame-Options 헤더를 출력하고 있는 경우에는 중복 사용하지 마십시오.';
$lang->about_x_content_type_options = '브라우저가 문서나 첨부파일의 MIME type을 스니핑하여 임의로 처리하는 것을 막습니다.<br />웹서버 설정에서 이미 X-Content-Type-Options 헤더를 출력하고 있는 경우에는 중복 사용하지 마십시오.';
$lang->autologin_lifetime = '자동 로그인 유지 기간';
$lang->autologin_refresh = '보안키 갱신';
$lang->about_autologin_lifetime = '자동 로그인을 유지할 기간을 선택할 수 있습니다. 설정할 수 있는 범위는 1~400일입니다.<br>보안키 갱신을 선택하면 자동 로그인 기능을 사용할 때마다 쿠키 값을 변경하여 안전성을 높입니다.';
$lang->use_session_ssl = 'SSL 전용 세션 사용';
$lang->about_use_session_ssl = '세션을 SSL 전용으로 지정하여 SSL이 아닌 페이지와 로그인 상태가 공유되지 않도록 합니다.<br>SSL을 항상 사용하도록 설정되어 있는 경우에만 활성화됩니다.';
$lang->use_cookies_ssl = 'SSL 전용 쿠키 사용';

View file

@ -45,6 +45,15 @@
<p class="x_help-block">{$lang->about_admin_ip_deny}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label" for="autologin_lifetime">{$lang->autologin_lifetime}</label>
<div class="x_controls">
<input type="number" name="autologin_lifetime" min="1" max="400" value="{$autologin_lifetime}" /> {$lang->unit_day} &nbsp;
<label for="autologin_refresh" class="x_inline"><input type="checkbox" name="autologin_refresh" id="autologin_refresh" value="Y" checked="checked"|cond="$autologin_refresh" /> {$lang->autologin_refresh}</label>
<br />
<p class="x_help-block">{$lang->about_autologin_lifetime}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{$lang->use_session_ssl}</label>
<div class="x_controls">

View file

@ -2211,7 +2211,7 @@ class MemberController extends Member
// If the current security key matches, generate a new key.
// If the previous key matches, don't update until the client has the current key.
// Resending the current key in this case will be handled by the Session class.
if ($hashed_security_key === $output->data->security_key)
if ($hashed_security_key === $output->data->security_key && config('session.autologin_refresh') !== false)
{
$new_security_key = Rhymix\Framework\Security::getRandom(24, 'alnum');
$new_hash = base64_encode(hash_hmac('sha256', $new_security_key, $autologin_key, true));