CVE-2024-22196: Authenticated (user role) SQL injection in `OrderAndPaginate` (GHSL-2023-270)

Published Jan 11, 2024
·
Updated

Summary The OrderAndPaginate function is used to order and paginate data. It is defined as follows: go func OrderAndPaginate(c gin.Context) func(db gorm.DB) gorm.DB { return func(db gorm.DB) gorm.DB { sort := c.DefaultQuery("order", "desc")

order := fmt.Sprintf("%s %s", DefaultQuery(c, "sortby", "id"), sort) db = db.Order(order)

... } } By using DefaultQuery, the "desc" and "id" values are used as default values if the query parameters are not set. Thus, the order and sortby query parameter are user-controlled and are being appended to the order variable without any sanitization. The same happens with SortOrder, but it doesn't seem to be used anywhere. go func SortOrder(c gin.Context) func(db gorm.DB) gorm.DB { return func(db gorm.DB) gorm.DB { sort := c.DefaultQuery("order", "desc") order := fmt.Sprintf("%s %s", DefaultQuery(c, "sortby", "id"), sort) return db.Order(order) } } This issue was found using CodeQL for Go: Database query built from user-controlled sources.

Proof of Concept > Based on this setup using uozi/nginx-ui:v2.0.0-beta.7. In order to exploit this issue, we need to find a place where the OrderAndPaginate function is used. We can find it in the GET /api/dnscredentials endpoint. go func GetDnsCredentialList(c gin.Context) { cosy.Coremodel.DnsCredential.SetFussy("provider").PagingList() } The PagingList function is defined as follows: go func (c Ctx[T]) PagingList() { data, ok := c.PagingListData() if ok { c.ctx.JSON(http.StatusOK, data) } } And the PagingListData function is defined as follows: go func (c Ctx[T]) PagingListData() (model.DataList, bool) { result, ok := c.result() if !ok { return nil, false }

result = result.Scopes(c.OrderAndPaginate()) ... } Using the following request, an attacker can retrieve arbitrary values by checking the order used by the query. That is, the result of the comparison will make the response to be ordered in a specific way. http GET /api/dnscredentials?sortby=(CASE+WHEN+(SELECT+1)=1+THEN+id+ELSE+updatedat+END)+ASC+--+ HTTP/1.1 Host: 127.0.0.1:8080 Authorization: <<JWT TOKEN> You can notice the order change by changing =1 to =2, and so the comparison will return false and the order will be updatedat instead of id.

Impact This issue may lead to Information Disclosure

Other sources

Nginx-UI is an online statistics for Server Indicators​​ Monitor CPU usage, memory usage, load average, and disk usage in real-time. This issue may lead to information disclosure. By using DefaultQuery, the "desc" and "id" values are used as default values if the query parameters are not set. Thus, the order and sortby query parameter are user-controlled and are being appended to the order variable without any sanitization. This issue has been patched in version 2.0.0.beta.9.

NVD

Nginx-UI is an online statistics for Server Indicators?? Monitor CPU usage, memory usage, load average, and disk usage in real-time. This issue may lead to information disclosure. By using DefaultQuery, the "desc" and "id" values are used as default values if the query parameters are not set. Thus, the order and sortby query parameter are user-controlled and are being appended to the order variable without any sanitization. This issue has been patched in version 2.0.0.beta.9.

NVD

Affected Software

15 affected componentsFixes available
go/github.com/0xJacky/Nginx-UI<2.0.0.beta.9
2.0.0.beta.9
NginxUI Nginx UI<2.0.0
NginxUI Nginx UI=2.0.0-beta1
NginxUI Nginx UI=2.0.0-beta2
NginxUI Nginx UI=2.0.0-beta3
NginxUI Nginx UI=2.0.0-beta4
NginxUI Nginx UI=2.0.0-beta4_patch
NginxUI Nginx UI=2.0.0-beta5
NginxUI Nginx UI=2.0.0-beta5_patch
NginxUI Nginx UI=2.0.0-beta6
NginxUI Nginx UI=2.0.0-beta6_patch
NginxUI Nginx UI=2.0.0-beta6_patch2
NginxUI Nginx UI=2.0.0-beta7
NginxUI Nginx UI=2.0.0-beta8
NginxUI Nginx UI=2.0.0-beta8_patch

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade go/github.com/0xJacky/Nginx-UI to a version that resolves this vulnerability.

    Fixed in 2.0.0.beta.9
  2. Upgrade

    Upgrade uozi/nginx-ui to a version that resolves this vulnerability.

    Fixed in 2.0.0.beta.9
  3. Configuration

    In the /api/dns_credentials handler path that uses OrderAndPaginate (model.go OrderAndPaginate / PagingListData), ensure the query parameters 'order' and 'sort_by' are validated against an allowlist of expected column names/directions before building the SQL ORDER BY clause (the issue is patched in v2.0.0.beta.9).

    Nginx-UI API endpoint SQL injection vectors via order/sort_by query parameters = Do not allow user-controlled order/sort_by values to be appended to SQL ORDER BY without sanitization/validation

Event History

Jan 11, 2024
Advisory Published
via GitHub·04:27 PM
CVE Published
via MITRE·07:24 PM
Data Sourced
via MITRE·07:24 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·08:15 PM
RemedyDescriptionSeverityWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2024-22196?

CVE-2024-22196 is classified as a critical severity vulnerability.

2

How do I fix CVE-2024-22196?

To fix CVE-2024-22196, upgrade to version 2.0.0.beta.9 or later of the affected software.

3

Which software versions are affected by CVE-2024-22196?

CVE-2024-22196 affects all versions of Nginx UI prior to 2.0.0.beta.9.

4

What does CVE-2024-22196 affect?

CVE-2024-22196 affects the OrderAndPaginate function in the Nginx UI application.

5

Where can I find more information on CVE-2024-22196?

More information on CVE-2024-22196 can be found in the official GitHub advisory.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203