CVE-2019-7548: SQLAlchemy SQL Injection Vulnerability

CRITICAL
Advisory Identifier: GHSA-38fc-9xqv-7f7q
CVSS 7.8
CWE-89
Published
Advisory Summary

CVE-2019-7548 is a CRITICAL (CVSS 7.8) sql injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting SQLAlchemy libraries in the PyPI ecosystem. The issue involves sqlalchemy is vulnerable to sql injection via group_by parameter. Remediation is available by upgrading affected packages to version 1.2.19.

CVE-2019-7548 at a Glance

CVE Identifier CVE-2019-7548
GHSA Identifier GHSA-38fc-9xqv-7f7q
Severity CRITICAL
CVSS v3.1 Base Score 7.8
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product SQLAlchemy
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.8

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

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

How to Fix CVE-2019-7548

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

SQLAlchemy fixed: 1.2.19
pip install SQLAlchemy>=1.2.19
Verify Direct and Transitive Dependencies

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

pip show SQLAlchemy

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2019-7548, inspect your installed packages using pip:

pip show SQLAlchemy

Analyze the terminal output to locate any version of SQLAlchemy in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.2.19), your application is affected.

Note: The pip show SQLAlchemy command checks currently installed packages in your active Python environment.

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 SQLAlchemy, 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

SQLAlchemy 1.2.17 has SQL Injection when the group_by parameter can be controlled.

CVE-2019-7548 Affected SQLAlchemy Versions

1 component(s)
Fixed Versions:
1.2.19
Product / Package Ecosystem Affected Versions Fixed Version
SQLAlchemy
PyPI
< 1.2.19
1.2.19

References

NVD — CVE-2019-7548 NVD
https://nvd.nist.gov/vuln/detail/CVE-2019-7548
SQLAlchemy Source Repository REPOSITORY
https://github.com/sqlalchemy/sqlalchemy/issues/4481#issuecomment-461204518
SQLAlchemy Source Repository REPOSITORY
https://github.com/sqlalchemy/sqlalchemy/issues/4510
access.redhat.com/errata/rhsa-2019:09... WEB
https://access.redhat.com/errata/RHSA-2019:0981
access.redhat.com/errata/rhsa-2019:09... WEB
https://access.redhat.com/errata/RHSA-2019:0984
GitHub Advisory / Wiki ADVISORY
https://github.com/advisories/GHSA-38fc-9xqv-7f7q
SQLAlchemy Source Repository REPOSITORY
https://github.com/no-security/sqlalchemy_test
SQLAlchemy Source Repository REPOSITORY
https://github.com/pypa/advisory-database/tree/main/vulns/sqlalchemy/PYSEC-2019-124.yaml
SQLAlchemy Source Repository REPOSITORY
https://github.com/sqlalchemy/sqlalchemy
lists.debian.org/debian-lts-announce... WEB
https://lists.debian.org/debian-lts-announce/2019/03/msg00020.html
lists.debian.org/debian-lts-announce... WEB
https://lists.debian.org/debian-lts-announce/2021/11/msg00005.html
SQLAlchemy Security Information SECURITY
https://www.oracle.com/security-alerts/cpujan2021.html
SQLAlchemy Security Information SECURITY
http://lists.opensuse.org/opensuse-security-announce/2019-08/msg00087.html
SQLAlchemy Security Information SECURITY
http://lists.opensuse.org/opensuse-security-announce/2019-09/msg00010.html
SQLAlchemy Security Information SECURITY
http://lists.opensuse.org/opensuse-security-announce/2019-09/msg00016.html

Frequently Asked Questions

What is CVE-2019-7548?
CVE-2019-7548 is a security vulnerability in SQLAlchemy involving SQLAlchemy is vulnerable to SQL Injection via group_by parameter under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which SQLAlchemy versions are affected?
Affected versions include releases prior to 1.2.19 across affected packages: SQLAlchemy.
What version fixes CVE-2019-7548?
Upgrading to 1.2.19 (or the latest patched release for your respective branch) resolves the vulnerability.
Is SQLAlchemy affected?
Yes, SQLAlchemy is affected in releases prior to 1.2.19. Upgrade your dependency to 1.2.19 or later.
What is the CVSS score of CVE-2019-7548?
CVE-2019-7548 has a CVSS v3.1 base score of 7.8 (CRITICAL) with vector string CVSS:3.0/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2019-7548?
CVE-2019-7548 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 PyPI dependencies for CVE-2019-7548?
Run the dependency tree command: 'pip show SQLAlchemy'. 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-38fc-9xqv-7f7q",
  "modified" : "2024-10-28T14:22:48Z",
  "published" : "2019-04-16T15:50:39Z",
  "aliases" : [ "CVE-2019-7548" ],
  "summary" : "SQLAlchemy is vulnerable to SQL Injection via group_by parameter ",
  "details" : "SQLAlchemy 1.2.17 has SQL Injection when the group_by parameter can be controlled.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.0/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "SQLAlchemy"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.2.19"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2019-7548"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sqlalchemy/sqlalchemy/issues/4481#issuecomment-461204518"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sqlalchemy/sqlalchemy/issues/4510"
  }, {
    "type" : "WEB",
    "url" : "https://access.redhat.com/errata/RHSA-2019:0981"
  }, {
    "type" : "WEB",
    "url" : "https://access.redhat.com/errata/RHSA-2019:0984"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-38fc-9xqv-7f7q"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/no-security/sqlalchemy_test"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/sqlalchemy/PYSEC-2019-124.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sqlalchemy/sqlalchemy"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2019/03/msg00020.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2021/11/msg00005.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpujan2021.html"
  }, {
    "type" : "WEB",
    "url" : "http://lists.opensuse.org/opensuse-security-announce/2019-08/msg00087.html"
  }, {
    "type" : "WEB",
    "url" : "http://lists.opensuse.org/opensuse-security-announce/2019-09/msg00010.html"
  }, {
    "type" : "WEB",
    "url" : "http://lists.opensuse.org/opensuse-security-announce/2019-09/msg00016.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-89" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2020-06-16T20:54:34Z",
    "nvd_published_at" : "2019-02-06T21:29:00Z"
  }
}