CVE-2019-7164: SQL Injection in SQLAlchemy

sqlalchemy Updated 02 Oct 2025

Summary

20/02/2019
N/A
Yes i
Unrated
Not published

PYSEC-2019-53: SQLAlchemy through 1.2.17 and 1.3.x through 1.3.0b2 allows SQL Injection via the order_by parameter. Affects sqlalchemy versions < 1.2.18. Fixed in 1.2.18. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

Background

SQLAlchemy is a popular Python SQL toolkit and Object-Relational Mapping (ORM) library. It provides a set of high-level API for interacting with relational databases. SQLAlchemy versions 1.2.17 and 1.3.x through 1.3.0b2 are affected by a SQL Injection vulnerability. This vulnerability can be exploited through the 'order_by' parameter, allowing an attacker to inject malicious SQL code into the query.

Vulnerability Detail

The SQL Injection vulnerability in SQLAlchemy allows an attacker to manipulate the 'order_by' parameter to inject arbitrary SQL code. This can lead to unauthorized access, data leakage, or even remote code execution, depending on the context in which the vulnerable code is used. It is important to note that this vulnerability affects all applications that use SQLAlchemy and do not properly sanitize or validate user input when constructing SQL queries.

How To Fix

Latest published version: 2.1.6 as of 23 Oct 2026

pip install --upgrade "sqlalchemy==2.1.6"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

1.2.18

This is the first release that contains the fix.

pip install --upgrade "sqlalchemy==1.2.18"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If upgrading to the latest version of SQLAlchemy is not immediately feasible, a temporary workaround can be implemented by manually sanitizing and validating user input before using it in SQL queries. This can be achieved by using parameterized queries or escaping special characters. Here is an example of using parameterized queries with SQLAlchemy to prevent SQL Injection:

from sqlalchemy import create_engine, text

engine = create_engine('sqlite:///mydatabase.db')

with engine.connect() as conn:
    query = text('SELECT * FROM users WHERE id = :user_id')
    result = conn.execute(query, user_id=user_id)
    # Process the query result

In this example, the user input is passed as a parameter to the query, ensuring that it is properly sanitized and preventing SQL Injection.

Conclusion

The SQL Injection vulnerability in SQLAlchemy can have serious security implications for applications that use this library. It is crucial to upgrade to the latest version of SQLAlchemy and implement proper input validation and sanitization to mitigate the risk of SQL Injection attacks. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for sqlalchemy →

Share this vulnerability

FAQ

SQL Injection is a type of security vulnerability that allows an attacker to manipulate SQL queries by injecting malicious SQL code. This can lead to unauthorized access, data leakage, or even remote code execution.

The SQL Injection vulnerability in SQLAlchemy is caused by improper sanitization and validation of user input in the 'order_by' parameter. An attacker can manipulate this parameter to inject arbitrary SQL code into the query.

The consequences of the SQL Injection vulnerability in SQLAlchemy can vary depending on the context in which the vulnerable code is used. Possible consequences include unauthorized access to sensitive data, data leakage, or even remote code execution.

To fix the SQL Injection vulnerability in SQLAlchemy, it is recommended to upgrade to version 1.2.18 or later. Additionally, developers should ensure that user input is properly sanitized and validated before being used in SQL queries.

If upgrading to the latest version of SQLAlchemy is not immediately feasible, a temporary workaround can be implemented by manually sanitizing and validating user input before using it in SQL queries. Parameterized queries or escaping special characters can help prevent SQL Injection.

Related vulnerabilities

Recent vulnerabilities recorded for sqlalchemy.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

How To Fix

Latest published version: 2.1.6 as of 23 Oct 2026

pip install --upgrade "sqlalchemy==2.1.6"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

1.2.18

This is the first release that contains the fix.

pip install --upgrade "sqlalchemy==1.2.18"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback