CVE-2022-2921 (published 2022-08-21T04:15Z)

Exposure of Private Personal Information to an Unauthorized Actor in GitHub repository notrinos/notrinoserp prior to v0.7. This results in privilege escalation to a system administrator account. An attacker can gain access to protected functionality such as create/update companies, install/update languages, install/activate extensions, install/activate themes and other permissive actions.

CVSS v3 base score: 8.8, HIGH (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-359
cwe_name: Exposure of Private Personal Information to an Unauthorized Actor
description: The product does not properly prevent a person's private, personal information from being accessed by actors who either (1) are not explicitly authorized to access the information or (2) do not have the implicit consent of the person about whom the information is collected.
extended_description: 
            There are many types of sensitive information that products must protect from attackers, including system data, communications, configuration, business secrets, intellectual property, and an individual's personal (private) information.  Private personal information may include a password, phone number, geographic location, personal messages, credit card number, etc.  Private information is important to consider whether the person is a user of the product, or part of a data set that is processed by the product.  An exposure of private information does not necessarily prevent the product from working properly, and in fact the exposure might be intended by the developer, e.g. as part of data sharing with other organizations.  However, the exposure of personal private information can still be undesirable or explicitly prohibited by law or regulation.
            Some types of private information include:
               
                  Government identifiers, such as Social Security Numbers
                  Contact information, such as home addresses and telephone numbers
                  Geographic location - where the user is (or was)
                  Employment history
                  Financial data - such as credit card numbers, salary, bank accounts, and debts
                  Pictures, video, or audio
                  Behavioral patterns - such as web surfing history, when certain activities are performed, etc.
                  Relationships (and types of relationships) with others - family, friends, contacts, etc.
                  Communications - e-mail addresses, private messages, text messages, chat logs, etc.
                  Health - medical conditions, insurance status, prescription records
                  Account passwords and other credentials
               
            Some of this information may be characterized as PII (Personally Identifiable Information), Protected Health Information (PHI), etc. Categories of private information may overlap or vary based on the intended usage or the policies and practices of a particular industry.
            Sometimes data that is not labeled as private can have a privacy implication in a different context. For example, student identification numbers are usually not considered private because there is no explicit and publicly-available mapping to an individual student's personal information. However, if a school generates identification numbers based on student social security numbers, then the identification numbers should be considered private.
         
         

Fix information:
repo_url: https://github.com/notrinos/notrinoserp
commit_details: repo_url: https://github.com/notrinos/notrinoserp
author: notrinos
author_date: 2022-08-21 09:07:55+07:00
msg: changed password hash method from md5 to bcrypt.
repository: repo_url: https://github.com/notrinos/notrinoserp
repo_name: notrinos/NotrinosERP
description: A web-based erp, accounting system that written in PHP and MySql includes Sales, Purchasing, Warehousing, Manufacturing, Human Resource... It supports multi user, multi currencies, multi languages.
repo_language: PHP
owner: notrinos
file_changes: filename: change_current_user_password.php
change_type: ModificationType.MODIFY
diff: @@ -25,7 +25,7 @@ function can_process() {
 	$Auth_Result = hook_authenticate($_SESSION['wa_current_user']->username, $_POST['cur_password']);
 
 	if (!isset($Auth_Result))	// if not used external login: standard method
-		$Auth_Result = get_user_auth($_SESSION['wa_current_user']->username, md5($_POST['cur_password']));
+		$Auth_Result = authenticate_user($_SESSION['wa_current_user']->username, $_POST['cur_password']);
 
 	if (!$Auth_Result) {
 		display_error( _('Invalid password entered.'));
@@ -57,7 +57,7 @@ if (isset($_POST['UPDATE_ITEM']) && check_csrf_token()) {
 		if ($SysPrefs->allow_demo_mode)
 			display_warning(_('Password cannot be changed in demo mode.'));
 		else {
-			update_user_password($_SESSION['wa_current_user']->user, $_SESSION['wa_current_user']->username, md5($_POST['password']));
+			update_user_password($_SESSION['wa_current_user']->user, $_SESSION['wa_current_user']->username, password_hash($_POST['password'], PASSWORD_DEFAULT));
 			display_notification(_('Your password has been updated.'));
 		}
 		$Ajax->activate('_page_body');
@@ -86,4 +86,4 @@ end_table(1);
 
 submit_center( 'UPDATE_ITEM', _('Change password'), true, '',  'default');
 end_form();
-end_page();
\ No newline at end of file
+end_page();

programming_language: PHP
filename: create_coy.php
change_type: ModificationType.MODIFY
diff: @@ -20,7 +20,7 @@ include_once($path_to_root.'/includes/ui.inc');
 
 page(_($help_context = 'Create/Update Company'));
 
-$comp_subdirs = array('images', 'pdf_files', 'backup','js_cache', 'reporting', 'attachments');
+$comp_subdirs = array('images', 'pdf_files', 'backup', 'js_cache', 'reporting', 'attachments');
 
 simple_page_mode(true);
 /*
@@ -107,7 +107,7 @@ function handle_submit($selected_id) {
 
 		$conn = $db_connections[$selected_id];
 		if (($db = db_create_db($conn)) === false) {
-			display_error(_('Error creating Database: ') . $conn['dbname'] . _(', Please create it manually'));
+			display_error(_('Error creating Database: ').$conn['dbname']._(', Please create it manually'));
 			$error = true;
 		}
 		else {
@@ -120,7 +120,7 @@ function handle_submit($selected_id) {
 			else {
 				if (!isset($_POST['admpassword']) || $_POST['admpassword'] == '')
 					$_POST['admpassword'] = 'password';
-				update_admin_password($conn, md5($_POST['admpassword']));
+				update_admin_password($conn, password_hash($_POST['admpassword']), PASSWORD_DEFAULT);
 			}
 		}
 		if ($error) {
@@ -350,4 +350,4 @@ submit_add_or_update_center($selected_id == -1, '', 'upgrade');
 
 end_form();
 
-end_page();
\ No newline at end of file
+end_page();

programming_language: PHP
filename: users_db.inc
change_type: ModificationType.MODIFY
diff: @@ -112,12 +112,29 @@ function delete_user($id) {
 
 //-----------------------------------------------------------------------------------------------
 
-function get_user_auth($user_id, $password) {
+function authenticate_user($user_id, $password) {
 
-	$sql = "SELECT * FROM ".TB_PREF."users WHERE user_id = ".db_escape($user_id)." AND"
-		." password=".db_escape($password);
+	$sql1 = "SELECT password FROM ".TB_PREF."users WHERE user_id = ".db_escape($user_id);
 
-	return db_num_rows(db_query($sql, 'could not get validate user login for '.$user_id)) != 0;
+	$result = db_query($sql1, 'could not get user login for '.$user_id);
+
+	if(db_num_rows($result) == 0)
+		return false;
+
+	$hash = db_fetch($result)[0];
+
+	// The user's password hash may have been created long ago by md5 password algorithm on the old NotrinosERP versions
+	if(password_verify($password, $hash) || $hash == md5($password)) {
+		if(password_needs_rehash($hash, PASSWORD_DEFAULT) === true) {
+			$new_hash = password_hash($password, PASSWORD_DEFAULT);
+			$sql2 = "UPDATE ".TB_PREF."users SET password = ".db_escape($new_hash)." WHERE user_id = ".db_escape($user_id);
+			db_query($sql2, 'could not update password hash for '.$user_id);
+		}
+
+		return true;
+	}
+
+	return false;
 }
 
 //-----------------------------------------------------------------------------------------------

programming_language: PHP
filename: users.php
change_type: ModificationType.MODIFY
diff: @@ -56,12 +56,12 @@ if (($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') && check_csrf_token()) {
 			update_user_prefs($selected_id, get_post(array('user_id', 'real_name', 'phone', 'email', 'role_id', 'language', 'print_profile', 'rep_popup' => 0, 'pos')));
 
 			if ($_POST['password'] != '')
-				update_user_password($selected_id, $_POST['user_id'], md5($_POST['password']));
+				update_user_password($selected_id, $_POST['user_id'], password_hash($_POST['password'], PASSWORD_DEFAULT));
 
 			display_notification_centered(_('The selected user has been updated.'));
 		} 
 		else {
-			add_user($_POST['user_id'], $_POST['real_name'], md5($_POST['password']), $_POST['phone'], $_POST['email'], $_POST['role_id'], $_POST['language'], $_POST['print_profile'], check_value('rep_popup'), $_POST['pos']);
+			add_user($_POST['user_id'], $_POST['real_name'], password_hash($_POST['password'], PASSWORD_DEFAULT), $_POST['phone'], $_POST['email'], $_POST['role_id'], $_POST['language'], $_POST['print_profile'], check_value('rep_popup'), $_POST['pos']);
 			$id = db_insert_id();
 			// use current user display preferences as start point for new user
 			$prefs = $_SESSION['wa_current_user']->prefs->get_all();

programming_language: PHP
filename: current_user.inc
change_type: ModificationType.MODIFY
diff: @@ -69,11 +69,11 @@ class current_user {
 
 		// Use external authentication source if any.
 		// Keep in mind you need to have user data set for $loginname
-		// in FA users table anyway to successfully log in.
+		// in NotrinosERP users table anyway to successfully log in.
 		$Auth_Result = hook_authenticate($loginname, $password);
 
 		if (!isset($Auth_Result))	// if not used: standard method
-			$Auth_Result = get_user_auth($loginname, md5($password));
+			$Auth_Result = authenticate_user($loginname, $password);
 		if ($SysPrefs->login_delay > 0)
 			write_login_filelog($loginname, $Auth_Result);
 		if ($Auth_Result) {
@@ -151,7 +151,7 @@ class current_user {
 		if ($user != false) {
 
 			$password = generate_password();
-			$hash = md5($password);
+			$hash = password_hash($password);
 
 			update_user_password($user['id'], $user['user_id'], $hash);
 			

programming_language: PHP