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:
- create a file called /etc/apache2/conf-available/block-requests.conf
- add the contents below
- run "a2enconf block-requests"
- run "apache2ctl -t" and make sure you see "Syntax OK"
- 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:
- add the following snippet of code before the
location
block in nginx.conf
(usually under /etc/nginx/
)
- run
nginx -t
to make sure syntax is ok
- 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:
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:
For nginx, please follow the steps below:
location
block innginx.conf
(usually under/etc/nginx/
)nginx -t
to make sure syntax is okReferences
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: