Vulnerabilities in pkg:pypi/SQLAlchemy

PACKAGE
Advisory Identifier: GHSA-887w-45rq-vxgf
Advisory Summary

CVE-2019-7164 is a CRITICAL (CVSS 9.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 vulnerable to sql injection via order_by parameter. Remediation is available by upgrading affected packages to version 1.3.0b3.

3 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/SQLAlchemy

3 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/SQLAlchemy. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-887w-45rq-vxgf CVE-2019-7164 CRITICAL SQLAlchemy vulnerable to SQL Injection via order_by parameter
GHSA-hfg2-wf6j-x53p CVE-2012-0805 CRITICAL SQLAlchemy vulnerable to SQL injection
GHSA-38fc-9xqv-7f7q CVE-2019-7548 CRITICAL SQLAlchemy is vulnerable to SQL Injection via group_by parameter

CVE-2019-7164 at a Glance

CVE Identifier CVE-2019-7164
GHSA Identifier GHSA-887w-45rq-vxgf
Severity CRITICAL
CVSS v3.1 Base Score 9.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: 9.8

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

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

How to Fix CVE-2019-7164

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.3.0b3
pip install SQLAlchemy>=1.3.0b3
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-7164, 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.3.0b3), 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 before 1.3.0b3 allows SQL Injection via the order_by parameter. The fix (commit 30307c4) was applied only to the main branch and was never backported to the 1.2.x release line; all 1.2.x versions remain vulnerable.

CVE-2019-7164 Affected SQLAlchemy Versions

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

References

Frequently Asked Questions

What is CVE-2019-7164?
CVE-2019-7164 is a security vulnerability in SQLAlchemy involving SQLAlchemy vulnerable to SQL Injection via order_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.3.0b3 across affected packages: SQLAlchemy.
What version fixes CVE-2019-7164?
Upgrading to 1.3.0b3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is SQLAlchemy affected?
Yes, SQLAlchemy is affected in releases prior to 1.3.0b3. Upgrade your dependency to 1.3.0b3 or later.
What is the CVSS score of CVE-2019-7164?
CVE-2019-7164 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2019-7164?
CVE-2019-7164 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-7164?
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-887w-45rq-vxgf",
  "modified" : "2026-06-09T18:41:13Z",
  "published" : "2019-04-16T15:50:41Z",
  "aliases" : [ "CVE-2019-7164" ],
  "summary" : "SQLAlchemy vulnerable to SQL Injection via order_by parameter",
  "details" : "SQLAlchemy before 1.3.0b3 allows SQL Injection via the order_by parameter. The fix (commit 30307c4) was applied only to the main branch and was never backported to the 1.2.x release line; all 1.2.x versions remain vulnerable.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/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.3.0b3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2019-7164"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sqlalchemy/sqlalchemy/issues/4481"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sqlalchemy/sqlalchemy/commit/30307c4616ad67c01ddae2e1e8e34fabf6028414"
  }, {
    "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-887w-45rq-vxgf"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/sqlalchemy/PYSEC-2019-123.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-16T21:24:54Z",
    "nvd_published_at" : "2019-02-20T00:29:00Z"
  }
}