Skip to content

Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') in OrgUnit program association

High
Philip-Larsen-Donnelly published GHSA-52vp-f7hj-cj92 Jun 1, 2022

Package

dhis2-core (dhis2)

Affected versions

2.36,2.37

Patched versions

2.36.10.1,2.37.6.1

Description

Improper neutralization of special elements used in an SQL command
('SQL Injection') vulnerability in the OrgUnit API in DHIS2 allows authenticated remote attackers to execute arbitrary SQL commands via unspecified vectors.

Impact

A serious SQL injection security vulnerability has been found affecting the /api/programs/orgUnits?programs= API endpoint in all DHIS2 versions.

The system is vulnerable to attack only from users that are logged in to DHIS2, and there is no known way of exploiting the vulnerability without first being logged in as a DHIS2 user.

The vulnerability is not exposed to a non-malicious user - the vulnerability requires a conscious attack to be exploited.

A successful exploit of this vulnerability could allow the malicious user to read, edit and delete data in the DHIS2 instance's database.

There are no known exploits of the security vulnerabilities addressed by these patch releases. However, we strongly recommend that all DHIS2 implementations using affected versions upgrade to one of the latest supported patches as soon as possible.

Patches

Security patches are now available for the following DHIS2 versions:

v2.36 -- Update to 2.36.10.1 or above
v2.37 -- Update to 2.37.6.1 or above

These patches address a critical security vulnerability. If your DHIS2 system is using one of the versions listed above, you should download and install the appropriate patch version immediately. If you are using a version of DHIS2 earlier than 2.35 you are also susceptible to this vulnerability and should upgrade to the latest "End of Support" build for your DHIS2 major version. All of the latest patch versions are available for download at dhis2.org/downloads.

Workarounds

N.B. the following mitigations can be used to mitigate SQL injection vulnerabilities in general, so please consider adding them regardless.

For implementations which can NOT upgrade, you can apply mitigations at the web proxy level.

For apache2, please follow the steps below:

  1. create a file called /etc/apache2/conf-available/block-requests.conf
  2. add the contents below
  3. run "a2enconf block-requests"
  4. run "apache2ctl -t" and make sure you see "Syntax OK"
  5. service apache2 reload
RewriteEngine On

# check for SQLi on all api requests
RewriteCond %{REQUEST_URI} ^.*/api/([0-9]+/)?
RewriteRule .* - [E=MY_ARGS:%{QUERY_STRING},C]

RewriteCond %{QUERY_STRING} (.*)&(filter=[^&]*)(?=&|$)(.*)|^(filter=[^&]*)(&|$)(.*)
RewriteRule .* - [E=MY_ARGS:%1%3%6]

RewriteCond %{ENV:MY_ARGS} ('|%27)
RewriteRule ^(.*)$ - [F,L]

For nginx, please follow the steps below:

  1. add the following snippet of code before the location block in nginx.conf (usually under /etc/nginx/)
  2. run nginx -t to make sure syntax is ok
  3. service nginx reload
# Set an alert flag to zero
set $sqli 0;

# Copy query parameters to a local variable
set $my_args $args;

# If a local copy of query parameters contains FILTER= parameter, exclude it (case insensitive)
if ($my_args ~* (.*)&(filter=[^&]*)(?=&|$)(.*)|^(filter=[^&]*)(&|$)(.*)) {
     set $my_args $1$3$6;
}

# Check that all remaining parameters don't contain a single quote
if ( $my_args ~* "('|%27)" ) {
    set $sqli 1;
}

# Return an error code if a single quote was found in parameters
if ($sqli = 1) {
    return 418;
}

References

You can read more about the process for identifying, reviewing, and addressing potential security vulnerabilities on our website: https://dhis2.org/security

For more information

If you have any questions or comments about this advisory:

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

CVE ID

CVE-2022-24848

Weaknesses