CVE-2023-1269: Use of Hard-coded Credentials (CWE-798)
value: Use of Hard-coded Credentials in GitHub repository alextselegidis/easyappointments prior to 1.5.0.
CWE description: The product contains hard-coded credentials, such as a password or cryptographic key.
CVSS v3 base score: 9.8
Published: 2023-03-08T11:15Z
Repository: https://github.com/alextselegidis/easyappointments
Language: PHP
Files changed: application/controllers/Console.php, application/controllers/Installation.php, application/libraries/Instance.php
Commit date: 2023-03-01 09:00:24 +0100
Commit message: Update the seeders so that they set dynamic passwords by default

Diff: diff --git a/application/controllers/Console.php b/application/controllers/Console.php
index 705702e4c..cf4f9e110 100644
--- a/application/controllers/Console.php
+++ b/application/controllers/Console.php
@@ -53,13 +53,13 @@ class Console extends EA_Controller {
      */
     public function install()
     {
         $this->instance->migrate('fresh');
 
-        $this->instance->seed();
+        $password = $this->instance->seed();
 
-        response(PHP_EOL . '⇾ Installation completed, login with "administrator" / "administrator".' . PHP_EOL . PHP_EOL);
+        response(PHP_EOL . '⇾ Installation completed, login with "administrator" / "' . $password . '".' . PHP_EOL . PHP_EOL);
     }
 
     /**
      * Migrate the database to the latest state.
      *
diff --git a/application/controllers/Installation.php b/application/controllers/Installation.php
index 3da9b853d..2231f409c 100644
--- a/application/controllers/Installation.php
+++ b/application/controllers/Installation.php
@@ -111,11 +111,11 @@ class Installation extends EA_Controller {
                 'services' => [
                     $service_id
                 ],
                 'settings' => [
                     'username' => 'janedoe',
-                    'password' => 'janedoe',
+                    'password' => random_string(),
                     'working_plan' => setting('company_working_plan'),
                     'notifications' => TRUE,
                     'google_sync' => FALSE,
                     'sync_past_days' => 30,
                     'sync_future_days' => 90,
diff --git a/application/libraries/Instance.php b/application/libraries/Instance.php
index 03c1c0ef4..05d247679 100644
--- a/application/libraries/Instance.php
+++ b/application/libraries/Instance.php
@@ -82,72 +82,83 @@ class Instance {
         }
     }
 
     /**
      * Seed the database with test data.
+     *
+     * @return string Return's the administrator user password.
      */
-    public function seed()
+    public function seed(): string
     {
         // Settings
+        
         setting([
             'company_name' => 'Company Name',
             'company_email' => 'info@example.org',
             'company_link' => 'https://example.org',
         ]);
 
+        $password = random_string();
+
         // Admin
+
         $this->CI->admins_model->save([
             'first_name' => 'John',
             'last_name' => 'Doe',
             'email' => 'john@example.org',
             'phone_number' => '+10000000000',
             'settings' => [
                 'username' => 'administrator',
-                'password' => 'administrator',
+                'password' => $password,
                 'notifications' => TRUE,
                 'calendar_view' => CALENDAR_VIEW_DEFAULT
             ],
         ]);
 
         // Service
+
         $service_id = $this->CI->services_model->save([
             'name' => 'Service',
             'duration' => '30',
             'price' => '0',
             'currency' => '',
             'availabilities_type' => 'flexible',
             'attendants_number' => '1'
         ]);
 
         // Provider
+
         $this->CI->providers_model->save([
             'first_name' => 'Jane',
             'last_name' => 'Doe',
             'email' => 'jane@example.org',
             'phone_number' => '+10000000000',
             'services' => [
                 $service_id
             ],
             'settings' => [
                 'username' => 'janedoe',
-                'password' => 'janedoe',
+                'password' => random_string(),
                 'working_plan' => setting('company_working_plan'),
                 'notifications' => TRUE,
                 'google_sync' => FALSE,
                 'sync_past_days' => 30,
                 'sync_future_days' => 90,
                 'calendar_view' => CALENDAR_VIEW_DEFAULT
             ],
         ]);
 
         // Customer
+
         $this->CI->customers_model->save([
             'first_name' => 'James',
             'last_name' => 'Doe',
             'email' => 'james@example.org',
             'phone_number' => '+10000000000',
         ]);
+
+        return $password;
     }
 
     /**
      * Create a database backup file.
      *

Vulnerable code:         $this->instance->seed();
        response(PHP_EOL . '⇾ Installation completed, login with "administrator" / "administrator".' . PHP_EOL . PHP_EOL);
                    'password' => 'janedoe',
    public function seed()
                'password' => 'administrator',
                'password' => 'janedoe',
Fixed code:         $password = $this->instance->seed();
        response(PHP_EOL . '⇾ Installation completed, login with "administrator" / "' . $password . '".' . PHP_EOL . PHP_EOL);
                    'password' => random_string(),
     *
     * @return string Return's the administrator user password.
    public function seed(): string
        
        $password = random_string();


                'password' => $password,


                'password' => random_string(),


        return $password;