mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 17:51:40 +09:00
Add admin setting to control the httpOnly attribute
This commit is contained in:
parent
56b37b7cbc
commit
a2932ee8c8
6 changed files with 36 additions and 19 deletions
|
|
@ -60,6 +60,7 @@ return array(
|
|||
'use_db' => false,
|
||||
'use_ssl' => false,
|
||||
'use_ssl_cookies' => false,
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax',
|
||||
'domain' => null,
|
||||
'path' => null,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class Session
|
|||
}
|
||||
|
||||
// Set session parameters.
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $samesite) = self::_getParams();
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $httponly, $samesite) = self::_getParams();
|
||||
$alt_domain = $domain ?: preg_replace('/:\\d+$/', '', strtolower($_SERVER['HTTP_HOST']));
|
||||
ini_set('session.gc_maxlifetime', $lifetime > 0 ? $lifetime : 28800);
|
||||
ini_set('session.use_cookies', 1);
|
||||
|
|
@ -90,7 +90,7 @@ class Session
|
|||
$path = ($path ?: '/') . '; SameSite=' . $samesite;
|
||||
}
|
||||
}
|
||||
session_set_cookie_params($lifetime, $path, $domain, $secure, true);
|
||||
session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
|
||||
session_name($session_name = Config::get('session.name') ?: session_name());
|
||||
|
||||
// Check if the session cookie already exists.
|
||||
|
|
@ -239,13 +239,13 @@ class Session
|
|||
$value = self::getLoginStatus();
|
||||
if (!isset($_COOKIE['rx_login_status']) || $_COOKIE['rx_login_status'] !== $value)
|
||||
{
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $samesite) = self::_getParams();
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $httponly, $samesite) = self::_getParams();
|
||||
self::_setCookie('rx_login_status', $value, array(
|
||||
'expires' => 0,
|
||||
'path' => $path,
|
||||
'domain' => $domain,
|
||||
'secure' => $secure,
|
||||
'httponly' => true,
|
||||
'httponly' => $httponly,
|
||||
'samesite' => $samesite,
|
||||
));
|
||||
}
|
||||
|
|
@ -422,28 +422,28 @@ class Session
|
|||
public static function refresh($refresh_cookie = false)
|
||||
{
|
||||
// Get session parameters.
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $samesite) = self::_getParams();
|
||||
$domain = self::getDomain() ?: preg_replace('/:\\d+$/', '', strtolower($_SERVER['HTTP_HOST']));
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $httponly, $samesite) = self::_getParams();
|
||||
$alt_domain = $domain ?: preg_replace('/:\\d+$/', '', strtolower($_SERVER['HTTP_HOST']));
|
||||
$lifetime = $lifetime ? ($lifetime + time()) : 0;
|
||||
$options = array(
|
||||
'expires' => $lifetime,
|
||||
'path' => $path,
|
||||
'domain' => $domain,
|
||||
'secure' => $secure,
|
||||
'httponly' => true,
|
||||
'httponly' => $httponly,
|
||||
'samesite' => $samesite,
|
||||
);
|
||||
|
||||
// Set the domain initialization timestamp.
|
||||
if (!isset($_SESSION['RHYMIX']['domains'][$domain]['started']))
|
||||
if (!isset($_SESSION['RHYMIX']['domains'][$alt_domain]['started']))
|
||||
{
|
||||
$_SESSION['RHYMIX']['domains'][$domain]['started'] = time();
|
||||
$_SESSION['RHYMIX']['domains'][$alt_domain]['started'] = time();
|
||||
}
|
||||
|
||||
// Reset the trusted information.
|
||||
if (!isset($_SESSION['RHYMIX']['domains'][$domain]['trusted']))
|
||||
if (!isset($_SESSION['RHYMIX']['domains'][$alt_domain]['trusted']))
|
||||
{
|
||||
$_SESSION['RHYMIX']['domains'][$domain]['trusted'] = 0;
|
||||
$_SESSION['RHYMIX']['domains'][$alt_domain]['trusted'] = 0;
|
||||
}
|
||||
|
||||
// Refresh the main session cookie.
|
||||
|
|
@ -490,7 +490,7 @@ class Session
|
|||
public static function destroy()
|
||||
{
|
||||
// Get session parameters.
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $samesite) = self::_getParams();
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $httponly, $samesite) = self::_getParams();
|
||||
|
||||
// Delete all cookies.
|
||||
self::destroyAutologinKeys();
|
||||
|
|
@ -1065,8 +1065,9 @@ class Session
|
|||
$domain = self::getDomain();
|
||||
$path = Config::get('session.path') ?: ini_get('session.cookie_path');
|
||||
$secure = (\RX_SSL && config('session.use_ssl')) ? true : false;
|
||||
$httponly = Config::get('session.httponly') ?? true;
|
||||
$samesite = config('session.samesite');
|
||||
return array($lifetime, $refresh, $domain, $path, $secure, $samesite);
|
||||
return array($lifetime, $refresh, $domain, $path, $secure, $httponly, $samesite);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1154,7 +1155,7 @@ class Session
|
|||
public static function setAutologinKeys($autologin_key, $security_key)
|
||||
{
|
||||
// Get session parameters.
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $samesite) = self::_getParams();
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $httponly, $samesite) = self::_getParams();
|
||||
$lifetime = time() + (86400 * 365);
|
||||
$samesite = config('session.samesite');
|
||||
|
||||
|
|
@ -1166,7 +1167,7 @@ class Session
|
|||
'path' => $path,
|
||||
'domain' => $domain,
|
||||
'secure' => $secure,
|
||||
'httponly' => true,
|
||||
'httponly' => $httponly,
|
||||
'samesite' => $samesite,
|
||||
));
|
||||
|
||||
|
|
@ -1187,7 +1188,7 @@ class Session
|
|||
public static function destroyAutologinKeys()
|
||||
{
|
||||
// Get session parameters.
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $samesite) = self::_getParams();
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $httponly, $samesite) = self::_getParams();
|
||||
|
||||
// Delete the autologin keys from the database.
|
||||
if (self::$_autologin_key)
|
||||
|
|
@ -1268,7 +1269,7 @@ class Session
|
|||
return false;
|
||||
}
|
||||
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $samesite) = self::_getParams();
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $httponly, $samesite) = self::_getParams();
|
||||
foreach ($cookies as $cookie)
|
||||
{
|
||||
foreach ($conflict_domains as $conflict_domain)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class Security extends Base
|
|||
Context::set('remote_addr', RX_CLIENT_IP);
|
||||
|
||||
// Session and cookie security settings
|
||||
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'));
|
||||
Context::set('use_cookies_ssl', Config::get('session.use_ssl_cookies'));
|
||||
|
|
@ -126,6 +127,7 @@ class Security extends Base
|
|||
|
||||
Config::set('admin.allow', array_values($allowed_ip));
|
||||
Config::set('admin.deny', array_values($denied_ip));
|
||||
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');
|
||||
Config::set('session.use_ssl_cookies', $vars->use_cookies_ssl === 'Y');
|
||||
|
|
|
|||
|
|
@ -165,9 +165,11 @@ $lang->mediafilter_classes = 'Allow HTML class';
|
|||
$lang->about_mediafilter_classes = 'This list defines the list of class attributes that users are allowed to use in HTML content.<br />Allowing classes that conflict with your site\'s design or functionality may cause breakage or confusing results.<br />This restriction does not apply to the administrator.';
|
||||
$lang->robot_user_agents = 'Robot user-agent';
|
||||
$lang->about_robot_user_agents = 'This list defines the list of browser user-agent strings that will be treated as robots, in addition to the usual search engines.<br />This may help prevent excessive server load and traffic due to malicious bots.';
|
||||
$lang->use_httponly = 'HttpOnly attribute';
|
||||
$lang->about_use_httponly = 'Reduce the risk of XSS attacks by blocking JavaScript access to session cookies.';
|
||||
$lang->use_samesite = 'SameSite attribute';
|
||||
$lang->use_samesite_empty = 'Do not use';
|
||||
$lang->about_use_samesite = 'Set the SameSite attribute for session cookies and session keys.<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_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->use_session_ssl = 'Use SSL-only session';
|
||||
|
|
|
|||
|
|
@ -166,9 +166,11 @@ $lang->mediafilter_classes = 'HTML class 허용';
|
|||
$lang->about_mediafilter_classes = '게시물, 댓글 등에서 허용되는 HTML class 속성의 목록을 지정할 수 있습니다.<br />사이트 디자인이나 기능과 중복되는 class를 허용할 경우 악의적으로 디자인을 망가뜨리거나 다른 사용자의 혼란을 유발할 수 있습니다.<br />관리자가 작성한 글은 제한을 받지 않습니다.';
|
||||
$lang->robot_user_agents = '로봇 user-agent';
|
||||
$lang->about_robot_user_agents = '일반적인 검색엔진 크롤러 외에 로봇으로 취급해야 할 user-agent가 있다면 한 줄에 하나씩 입력해 주십시오.<br />악성 크롤러로 인한 서버 부하 및 과도한 트래픽을 방지하는 데 도움이 될 수 있습니다.';
|
||||
$lang->use_httponly = 'HttpOnly 속성';
|
||||
$lang->about_use_httponly = '자바스크립트에서 세션 쿠키에 접근하지 못하도록 하여, XSS를 통한 세션 탈취의 가능성을 줄입니다.';
|
||||
$lang->use_samesite = 'SameSite 속성';
|
||||
$lang->use_samesite_empty = '표기하지 않음';
|
||||
$lang->about_use_samesite = '세션 쿠키, 보안키 등에 적용되는 SameSite 속성을 선택할 수 있습니다.<br>대부분의 사이트에는 Lax를 권장하며, 최신 브라우저에서 결제 연동 등에 문제가 있는 경우 None을 선택하시기 바랍니다.<br>단, None을 선택할 경우 SSL 전용 세션을 사용하여야 정상 작동합니다.';
|
||||
$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->use_session_ssl = 'SSL 전용 세션 사용';
|
||||
|
|
|
|||
|
|
@ -81,6 +81,15 @@
|
|||
<p class="x_help-block">{$lang->about_use_nofollow}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->use_httponly}</label>
|
||||
<div class="x_controls">
|
||||
<label for="use_httponly_y" class="x_inline"><input type="radio" name="use_httponly" id="use_httponly_y" value="Y" checked="checked"|cond="$use_httponly !== false" /> {$lang->cmd_yes}</label>
|
||||
<label for="use_httponly_n" class="x_inline"><input type="radio" name="use_httponly" id="use_httponly_n" value="N" checked="checked"|cond="$use_httponly === false" /> {$lang->cmd_no}</label>
|
||||
<br />
|
||||
<p class="x_help-block">{$lang->about_use_httponly}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->use_samesite}</label>
|
||||
<div class="x_controls">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue