CVE-2024-22196: Github.com/0xJacky/Nginx UI SQL Injection Vulnerability

HIGH
Advisory Identifier: GHSA-h374-mm57-879c
CVSS 7.0
CWE-89
Published
Advisory Summary

CVE-2024-22196 is a HIGH (CVSS 7.0) sql injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Github.com/0xJacky/Nginx UI libraries in the Go ecosystem. The issue involves authenticated (user role) sql injection in `orderandpaginate` (ghsl-2023-270). Remediation is available by upgrading affected packages to version 1.9.10-0.20231219195202-ec93ab05a3ec.

CVE-2024-22196 at a Glance

CVE Identifier CVE-2024-22196
GHSA Identifier GHSA-h374-mm57-879c
Severity HIGH
CVSS v3.1 Base Score 7.0
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product Github.com/0xJacky/Nginx UI
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 7.0

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:L).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity Low (I:L)
Availability Low (A:L)

How to Fix CVE-2024-22196

To remediate this vulnerability, upgrade all affected Github.com/0xJacky/Nginx UI dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/0xJacky/Nginx-UI fixed: 1.9.10-0.20231219195202-ec93ab05a3ec
Upgrade github.com/0xJacky/Nginx-UI to 1.9.10-0.20231219195202-ec93ab05a3ec
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/0xJacky/Nginx-UI

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-22196, inspect your project dependencies for Github.com/0xJacky/Nginx UI:

inspect dependencies for github.com/0xJacky/Nginx-UI

Analyze the terminal output to locate any version of Github.com/0xJacky/Nginx UI in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.9.10-0.20231219195202-ec93ab05a3ec), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the product constructs all or part of an sql command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended sql command when it is sent to a downstream component. without sufficient removal or quoting of sql syntax in user-controllable inputs, the generated sql query can cause those inputs to be interpreted as sql instead of ordinary user data. In Github.com/0xJacky/Nginx UI, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary The [`OrderAndPaginate`](https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L99C4) 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, "sort_by", "id"), sort) db = db.Order(order) ... } } ``` By using [`DefaultQuery`](https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L278-L287), the `"desc"` and `"id"` values are used as default values if the query parameters are not set. Thus, the `order` and `sort_by` query parameter are user-controlled and are being appended to the `order` variable without any sanitization. The same happens with [`SortOrder`](https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L91), 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, "sort_by", "id"), sort) return db.Order(order) } } ``` This issue was found using CodeQL for Go: [Database query built from user-controlled sources](https://codeql.github.com/codeql-query-help/go/go-sql-injection/). #### Proof of Concept > Based on [this setup](https://github.com/0xJacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/README.md?plain=1#L210) 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/dns_credentials` endpoint. ```go func GetDnsCredentialList(c *gin.Context) { cosy.Core[model.DnsCredential](c).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/dns_credentials?sort_by=(CASE+WHEN+(SELECT+1)=1+THEN+id+ELSE+updated_at+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 `updated_at` instead of `id`. ### Impact This issue may lead to `Information Disclosure`

CVE-2024-22196 Affected Github.com/0xJacky/Nginx UI Versions

1 component(s)
Fixed Versions:
1.9.10-0.20231219195202-ec93ab05a3ec
Product / Package Ecosystem Affected Versions Fixed Version
github.com/0xJacky/Nginx-UI
Go
< 1.9.10-0.20231219195202-ec93ab05a3ec
1.9.10-0.20231219195202-ec93ab05a3ec

References

Frequently Asked Questions

What is CVE-2024-22196?
CVE-2024-22196 is a security vulnerability in Github.com/0xJacky/Nginx UI involving Authenticated (user role) SQL injection in `OrderAndPaginate` (GHSL-2023-270) under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which Github.com/0xJacky/Nginx UI versions are affected?
Affected versions include releases prior to 1.9.10-0.20231219195202-ec93ab05a3ec across affected packages: github.com/0xJacky/Nginx-UI.
What version fixes CVE-2024-22196?
Upgrading to 1.9.10-0.20231219195202-ec93ab05a3ec (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/0xJacky/Nginx-UI affected?
Yes, github.com/0xJacky/Nginx-UI is affected in releases prior to 1.9.10-0.20231219195202-ec93ab05a3ec. Upgrade your dependency to 1.9.10-0.20231219195202-ec93ab05a3ec or later.
What is the CVSS score of CVE-2024-22196?
CVE-2024-22196 has a CVSS v3.1 base score of 7.0 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:L.
What CWE is associated with CVE-2024-22196?
CVE-2024-22196 is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.).
How can I check Go dependencies for CVE-2024-22196?
Run the dependency tree command: 'inspect dependencies for github.com/0xJacky/Nginx-UI'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-h374-mm57-879c",
  "modified" : "2026-07-06T19:14:29Z",
  "published" : "2024-01-11T16:27:06Z",
  "aliases" : [ "CVE-2024-22196" ],
  "summary" : "Authenticated (user role) SQL injection in `OrderAndPaginate` (GHSL-2023-270)",
  "details" : "### Summary\nThe [`OrderAndPaginate`](https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L99C4) function is used to order and paginate data. It is defined as follows:\n```go\nfunc OrderAndPaginate(c *gin.Context) func(db *gorm.DB) *gorm.DB {\n\treturn func(db *gorm.DB) *gorm.DB {\n\t\tsort := c.DefaultQuery(\"order\", \"desc\")\n\n\t\torder := fmt.Sprintf(\"`%s` %s\", DefaultQuery(c, \"sort_by\", \"id\"), sort)\n\t\tdb = db.Order(order)\n\n\t\t...\n\t}\n}\n```\nBy using [`DefaultQuery`](https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L278-L287), the `\"desc\"` and `\"id\"` values are used as default values if the query parameters are not set. Thus, the `order` and `sort_by` query parameter are user-controlled and are being appended to the `order` variable without any sanitization.\nThe same happens with [`SortOrder`](https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L91), but it doesn't seem to be used anywhere.\n```go\nfunc SortOrder(c *gin.Context) func(db *gorm.DB) *gorm.DB {\n\treturn func(db *gorm.DB) *gorm.DB {\n\t\tsort := c.DefaultQuery(\"order\", \"desc\")\n\t\torder := fmt.Sprintf(\"`%s` %s\", DefaultQuery(c, \"sort_by\", \"id\"), sort)\n\t\treturn db.Order(order)\n\t}\n}\n```\nThis issue was found using CodeQL for Go: [Database query built from user-controlled sources](https://codeql.github.com/codeql-query-help/go/go-sql-injection/).\n\n#### Proof of Concept\n> Based on [this setup](https://github.com/0xJacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/README.md?plain=1#L210) using `uozi/nginx-ui:v2.0.0-beta.7`.\nIn 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/dns_credentials` endpoint.\n```go\nfunc GetDnsCredentialList(c *gin.Context) {\n\tcosy.Core[model.DnsCredential](c).SetFussy(\"provider\").PagingList()\n}\n```\nThe `PagingList` function is defined as follows:\n```go\nfunc (c *Ctx[T]) PagingList() {\n\tdata, ok := c.PagingListData()\n\tif ok {\n\t\tc.ctx.JSON(http.StatusOK, data)\n\t}\n}\n```\nAnd the `PagingListData` function is defined as follows:\n```go\nfunc (c *Ctx[T]) PagingListData() (*model.DataList, bool) {\n\tresult, ok := c.result()\n\tif !ok {\n\t\treturn nil, false\n\t}\n\n\tresult = result.Scopes(c.OrderAndPaginate())\n\t...\n}\n```\nUsing 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.\n```http\nGET /api/dns_credentials?sort_by=(CASE+WHEN+(SELECT+1)=1+THEN+id+ELSE+updated_at+END)+ASC+--+ HTTP/1.1\nHost: 127.0.0.1:8080\nAuthorization: <<JWT TOKEN>\n```\nYou can notice the order change by changing `=1` to `=2`, and so the comparison will return `false` and the order will be `updated_at` instead of `id`.\n\n### Impact\nThis issue may lead to `Information Disclosure`",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/0xJacky/Nginx-UI"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.9.10-0.20231219195202-ec93ab05a3ec"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/0xJacky/nginx-ui/security/advisories/GHSA-h374-mm57-879c"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-22196"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/0xJacky/nginx-ui/commit/ec93ab05a3ecbb6bcf464d9dca48d74452df8a5b"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/0xJacky/nginx-ui"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L278-L287"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L91"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/0xjacky/nginx-ui/blob/04bf8ec487f06ab17a9fb7f34a28766e5f53885e/model/model.go#L99C4"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-89" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-01-11T16:27:06Z",
    "nvd_published_at" : "2024-01-11T20:15:44Z"
  }
}