Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Regenerate session id after user/admin login to avoid session fixation vulnerability https://github.com/givanz/Vvveb/issues/312 reported by @helloandrewpaul
givanzd4b1e0300664
diff --git a/system/session.php b/system/session.phpindex b684d4d..d644a17 100755--- a/system/session.php+++ b/system/session.php@@ -71,4 +71,8 @@ class Session {public function sessionId($id = null) {return $this->driver ? $this->driver->sessionId($id) : null;}++ public function regenerateId($deleteOldSession = false) {+ return $this->driver ? $this->driver->regenerateId($deleteOldSession) : null;+ }}diff --git a/system/session/php.php b/system/session/php.phpindex 9748e08..3709c5e 100755--- a/system/session/php.php+++ b/system/session/php.php@@ -93,6 +93,10 @@ class Php {return session_id($id);}+ public function regenerateId($deleteOldSession = false) {+ return session_regenerate_id($deleteOldSession);+ }+public function gc() {//handled by phpreturn true;diff --git a/system/session/request.php b/system/session/request.phpnew file mode 100644index 0000000..d87f1b2--- /dev/null+++ b/system/session/request.php@@ -0,0 +1,66 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\System\Session;++/**+ * Session placeholder if no driver is provided.+ * Used for apps like GraphQl where session is handled externally.+ */+class Request {+ private $data;++ public function __construct($options) {+ }++ public function __destruct() {+ }++ public function get($key) {+ if (isset($this->data[$key])) {+ return $this->data[$key];+ }+ }++ public function set($key, $value) {+ $this->data[$key] = $value;+ }++ public function delete($key) {+ unset($this->data[$key]);+ }++ public function close() {+ }++ public function sessionId($id = null) {+ }++ public function regenerateId($deleteOldSession = false) {+ }++ public function gc() {+ $this->data = [];++ return true;+ }+}diff --git a/system/user/admin.php b/system/user/admin.phpindex 212238b..ab603ed 100755--- a/system/user/admin.php+++ b/system/user/admin.php@@ -25,6 +25,7 @@ namespace Vvveb\System\User;use function Vvveb\session as sess;use Vvveb\Sql\AdminSQL;use Vvveb\System\PageCache;+use Vvveb\System\Session;class Admin extends Auth {private static $namespace = 'admin';@@ -48,12 +49,22 @@ class Admin extends Auth {public static function add($data) {$admin = new AdminSQL();- //check if email is already registerd- if ($adminInfo = $admin->get(['email'=> $data['email']])) {- return true;+ if (! isset($data['username']) || ! $data['username']) {+ return false;+ }++ //check if email or username is already registered+ $check = ['email'=> $data['email']];++ if (isset($data['username'])) {+ $check['username'] = $data['username'];}- $data['status'] = 0;+ if ($adminInfo = $admin->get($check)) {+ return $adminInfo;+ }++ $data['status'] = 1; //0self::setUserData($data);@@ -164,8 +175,10 @@ class Admin extends Auth {return false;}+ $session = Session :: getInstance();+ $session->regenerateId(true);unset($adminInfo['password']);- sess([self :: $namespace => $adminInfo + $additionalInfo]);+ $session->set(self :: $namespace, $adminInfo + $additionalInfo);PageCache::disable('user');@@ -179,7 +192,15 @@ class Admin extends Auth {}public static function current() {- return sess(self :: $namespace, []);+ $current = sess(self :: $namespace, []);++ if ($current) {+ PageCache::disable('admin');+ } else {+ PageCache::enable('admin');+ }++ return $current;}/**diff --git a/system/user/user.php b/system/user/user.phpindex bb1af2d..48c84dc 100755--- a/system/user/user.php+++ b/system/user/user.php@@ -25,6 +25,7 @@ namespace Vvveb\System\User;use function Vvveb\session as sess;use Vvveb\Sql\UserSQL;use Vvveb\System\PageCache;+use Vvveb\System\Session;class User extends Auth {private static $namespace = 'user';@@ -32,9 +33,19 @@ class User extends Auth {public static function add($data) {$user = new UserSQL();- //check if email is already registerd- if ($userInfo = $user->get(['email'=> $data['email']])) {- return true;+ if (! isset($data['username']) || ! $data['username']) {+ return false;+ }++ //check if email or username is already registered+ $check = ['email'=> $data['email']];++ if (isset($data['username'])) {+ $check['username'] = $data['username'];+ }++ if ($userInfo = $user->get($check)) {+ return $userInfo;}if (empty($data['password'])) {@@ -43,7 +54,7 @@ class User extends Auth {$data['password'] = self :: password($data['password']);}- $data['status'] = 1; //0+ $data['status'] = 1; //0return $user->add([self :: $namespace => $data]);}@@ -112,8 +123,10 @@ class User extends Auth {return false;}+ $session = Session :: getInstance();+ $session->regenerateId(true);unset($userInfo['password']);- sess([self :: $namespace => $userInfo]);+ $session->set(self :: $namespace, $userInfo);PageCache::disable(self :: $namespace);@@ -158,7 +171,15 @@ class User extends Auth {* @return mixed*/public static function current() {- return sess(self :: $namespace, []);+ $current = sess(self :: $namespace, []);++ if ($current) {+ PageCache::disable('user');+ } else {+ PageCache::enable('user');+ }++ return $current;}/**