Skip to content

Commit

Permalink
Allow setting cookies as secure + httpOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
samerton committed Oct 25, 2021
1 parent a65cc32 commit d9e795d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions core/classes/Cookie.php
Expand Up @@ -36,9 +36,12 @@ public static function get(string $name) {
* @param string $name Name of cookie to create.
* @param string $value Value to store in cookie.
* @param int $expiry When does the cookie expire?
* @param ?bool $secure Create as secure cookie?
* @param ?bool $httpOnly Create as httpOnly cookie?
* @return bool Whether cookie was set or not
*/
public static function put(string $name, string $value, int $expiry): bool {
return setcookie($name, $value, time() + $expiry, '/');
public static function put(string $name, string $value, int $expiry, ?bool $secure = false, ?bool $httpOnly = false): bool {
return setcookie($name, $value, time() + $expiry, '/', null, $secure, $httpOnly);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/classes/User.php
Expand Up @@ -225,7 +225,7 @@ private function _commonLogin(?string $username, ?string $password, bool $rememb

$expiry = $is_admin ? 3600 : Config::get('remember/cookie_expiry');
$cookieName = $is_admin ? ($this->_cookieName . '_adm') : $this->_cookieName;
Cookie::put($cookieName, $hash, $expiry);
Cookie::put($cookieName, $hash, $expiry, Util::isConnectionSSL(), true);
}

return true;
Expand Down

0 comments on commit d9e795d

Please sign in to comment.