CVE-2021-3980 (published 2021-12-03T15:15Z)

elgg is vulnerable to Exposure of Private Personal Information to an Unauthorized Actor

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:P/I:N/A:N)
CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N)

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/elgg/elgg
commit_details: repo_url: https://github.com/elgg/elgg
author: Jerôme Bakker
author_date: 2021-11-22 12:38:25+01:00
msg: fix(ajax): forms in the admin namespace are protected

All forms in the view namespace 'forms/admin' are now protected by an
AdminGatekeeper in case of AJAX requests to 'ajax/form/admin/'. This is
inline with the requests to 'ajax/view/admin'.
repository: repo_url: https://github.com/elgg/elgg
repo_name: Elgg/Elgg
description: A social networking engine in PHP/MySQL
repo_language: PHP
owner: elgg
file_changes: filename: elgglib.php
change_type: ModificationType.MODIFY
diff: @@ -1105,6 +1105,10 @@ function _elgg_ajax_page_handler($segments) {
 			// ignore 'view/'
 			$view = implode('/', array_slice($segments, 1));
 		} else {
+			if ($segments[1] === 'admin') {
+				// protect admin forms similar to all admin pages that are protected automatically in the admin_page_handler
+				elgg_admin_gatekeeper();
+			}
 			// form views start with "forms", not "form"
 			$view = 'forms/' . implode('/', array_slice($segments, 1));
 		}

programming_language: PHP
filename: ControllerIntegrationTest.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,164 @@
+<?php
+
+namespace Elgg\Ajax;
+
+use Elgg\IntegrationTestCase;
+
+class ControllerIntegrationTest extends IntegrationTestCase {
+
+	/**
+	 * @var \ElggUser
+	 */
+	protected $user;
+	
+	public function up() {
+		$this->registerViews();
+	}
+
+	public function down() {
+		elgg_get_session()->removeLoggedInUser();
+		
+		if (isset($this->user)) {
+			elgg_call(ELGG_IGNORE_ACCESS, function() {
+				$this->user->delete();
+			});
+		}
+	}
+	
+	protected function prepareService(\Elgg\Http\Request $request) {
+		$this->createApplication([
+			'isolate' => true,
+			'request' => $request,
+		]);
+		
+		$this->registerViews();
+	}
+	
+	protected function executeRequest(\Elgg\Http\Request $request, bool $prepare = true) {
+		if ($prepare) {
+			$this->prepareService($request);
+		}
+		
+		return _elgg_services()->router->getResponse($request);
+	}
+	
+	protected function registerViews() {
+		$views_dir = $this->normalizeTestFilePath('views');
+		_elgg_services()->views->autoregisterViews('', "{$views_dir}/default", 'default');
+		
+		elgg_register_ajax_view('ajax_test/registered');
+		elgg_register_ajax_view('admin/ajax_test/registered');
+		elgg_register_ajax_view('forms/ajax_test/registered');
+		elgg_register_ajax_view('forms/admin/ajax_test/registered');
+	}
+	
+	public function testCanLoadRegisteredAjaxView() {
+		$request = $this->prepareHttpRequest('ajax/view/ajax_test/registered', 'GET', [], 1);
+		
+		$response = $this->executeRequest($request);
+		$this->assertInstanceOf(\Elgg\Http\OkResponse::class, $response);
+		$this->assertEquals('registered', $response->getContent());
+	}
+	
+	public function testCantLoadRegisteredAjaxViewWithNonAjaxRequest() {
+		$request = $this->prepareHttpRequest('ajax/view/ajax_test/registered');
+		
+		$this->expectException(\Elgg\Http\Exception\AjaxGatekeeperException::class);
+		$this->executeRequest($request);
+	}
+	
+	public function testCantLoadNonRegisteredAjaxView() {
+		$this->assertTrue(elgg_view_exists('ajax_test/not_registered'));
+		$request = $this->prepareHttpRequest('ajax/view/ajax_test/not_registered', 'GET', [], 1);
+		
+		$response = $this->executeRequest($request);
+		$this->assertInstanceOf(\Elgg\Http\ErrorResponse::class, $response);
+	}
+	
+	public function testCantAccessAdminAjaxViewLoggedOut() {
+		$request = $this->prepareHttpRequest('ajax/view/admin/ajax_test/registered', 'GET', [], 1);
+		
+		$this->expectException(\Elgg\Http\Exception\LoggedInGatekeeperException::class);
+		$this->executeRequest($request);
+	}
+	
+	public function testCantAccessAdminAjaxViewAsNonAdmin() {
+		$request = $this->prepareHttpRequest('ajax/view/admin/ajax_test/registered', 'GET', [], 1);
+		
+		$this->prepareService($request);
+		
+		$this->user = $user = $this->createUser();
+		elgg_get_session()->setLoggedInUser($user);
+		
+		$this->expectException(\Elgg\Http\Exception\AdminGatekeeperException::class);
+		$this->executeRequest($request, false);
+	}
+	
+	public function testCanAccessAdminAjaxViewAsAdmin() {
+		$request = $this->prepareHttpRequest('ajax/view/admin/ajax_test/registered', 'GET', [], 1);
+		
+		$this->prepareService($request);
+		
+		$user = $this->getAdmin();
+		elgg_get_session()->setLoggedInUser($user);
+		
+		$response = $this->executeRequest($request, false);
+		$this->assertInstanceOf(\Elgg\Http\OkResponse::class, $response);
+		$this->assertEquals('registered', $response->getContent());
+	}
+	
+	public function testCanLoadRegisteredAjaxForm() {
+		$request = $this->prepareHttpRequest('ajax/form/ajax_test/registered', 'GET', [], 1);
+		
+		$response = $this->executeRequest($request);
+		$this->assertInstanceOf(\Elgg\Http\OkResponse::class, $response);
+		$this->assertStringContainsString('registered', $response->getContent());
+	}
+	
+	public function testCantLoadRegisteredAjaxFormWithNonAjaxRequest() {
+		$request = $this->prepareHttpRequest('ajax/form/ajax_test/registered');
+		
+		$this->expectException(\Elgg\Http\Exception\AjaxGatekeeperException::class);
+		$this->executeRequest($request);
+	}
+	
+	public function testCantLoadNonRegisteredAjaxForm() {
+		$this->assertTrue(elgg_view_exists('ajax_test/not_registered'));
+		$request = $this->prepareHttpRequest('ajax/form/ajax_test/not_registered', 'GET', [], 1);
+		
+		$response = $this->executeRequest($request);
+		$this->assertInstanceOf(\Elgg\Http\ErrorResponse::class, $response);
+	}
+	
+	public function testCantAccessAdminAjaxFormLoggedOut() {
+		$request = $this->prepareHttpRequest('ajax/form/admin/ajax_test/registered', 'GET', [], 1);
+		
+		$this->expectException(\Elgg\Http\Exception\LoggedInGatekeeperException::class);
+		$this->executeRequest($request);
+	}
+	
+	public function testCantAccessAdminAjaxFormAsNonAdmin() {
+		$request = $this->prepareHttpRequest('ajax/form/admin/ajax_test/registered', 'GET', [], 1);
+		
+		$this->prepareService($request);
+		
+		$this->user = $user = $this->createUser();
+		elgg_get_session()->setLoggedInUser($user);
+		
+		$this->expectException(\Elgg\Http\Exception\AdminGatekeeperException::class);
+		$this->executeRequest($request, false);
+	}
+	
+	public function testCanAccessAdminAjaxFormAsAdmin() {
+		$request = $this->prepareHttpRequest('ajax/form/admin/ajax_test/registered', 'GET', [], 1);
+		
+		$this->prepareService($request);
+		
+		$user = $this->getAdmin();
+		elgg_get_session()->setLoggedInUser($user);
+		
+		$response = $this->executeRequest($request, false);
+		$this->assertInstanceOf(\Elgg\Http\OkResponse::class, $response);
+		$this->assertStringContainsString('registered', $response->getContent());
+	}
+}

programming_language: PHP
filename: registered.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,6 @@
+<?php
+/**
+ * Registered ajax view
+ */
+
+echo 'registered';

programming_language: PHP
filename: not_registered.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,6 @@
+<?php
+/**
+ * Non registered ajax view
+ */
+
+echo 'not registered';

programming_language: PHP
filename: registered.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,6 @@
+<?php
+/**
+ * Registered ajax view
+ */
+
+echo 'registered';

programming_language: PHP
filename: registered.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,6 @@
+<?php
+/**
+ * Registered ajax view
+ */
+
+echo 'registered';

programming_language: PHP
filename: not_registered.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,6 @@
+<?php
+/**
+ * Non registered ajax view
+ */
+
+echo 'not registered';

programming_language: PHP
filename: registered.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,6 @@
+<?php
+/**
+ * Registered ajax view
+ */
+
+echo 'registered';

programming_language: PHP
filename: change_email.php
change_type: ModificationType.MODIFY
diff: @@ -10,7 +10,7 @@ $user = elgg_call(ELGG_SHOW_DISABLED_ENTITIES, function() use ($guid) {
 	return get_user($guid);
 });
 
-if (!$user instanceof ElggUser) {
+if (!$user instanceof ElggUser || !$user->canEdit()) {
 	return;
 }
 

programming_language: PHP