CVE-2020-20120: SQL Injection in topthink/thinkphp

topthink/thinkphp Updated 02 Oct 2025

Summary

30/09/2021
No i
Critical
9.8

CVE-2020-20120: SQL Injection in topthink/thinkphp. Affects topthink/thinkphp versions < 3.2.3. No fix is published. 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 Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

ThinkPHP is a popular PHP framework used for developing web applications. It provides a range of features and functionalities to simplify the development process. However, versions 3.2.3 and below of ThinkPHP are vulnerable to a SQL injection attack. This vulnerability occurs when the 'where' and 'query' methods are not properly validated, allowing an attacker to inject malicious SQL code into the application's database queries.

Vulnerability Detail

The SQL injection vulnerability in ThinkPHP v3.2.3 and below arises due to the lack of proper input validation in the 'where' and 'query' methods. When an array is not passed correctly to these methods, an attacker can exploit this flaw by injecting malicious SQL code. This can lead to unauthorized access, data manipulation, or even complete compromise of the application's database. The severity of this vulnerability is rated as CRITICAL with a CVSS score of 9.8.

How To Fix

No fixed version is published for this vulnerability.

Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →

Workaround

As a temporary workaround, developers can manually validate and sanitize user input before passing it to the 'where' and 'query' methods. This can be done by using parameterized queries or prepared statements to ensure that user input is treated as data rather than executable code. Here is an example of using prepared statements to prevent SQL injection:

$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $username);
$stmt->execute();
$result = $stmt->fetchAll();

Conclusion

The SQL injection vulnerability in ThinkPHP v3.2.3 and below can have severe consequences, including unauthorized access and data manipulation. It is crucial to upgrade to a patched version of ThinkPHP and implement proper input validation to mitigate this vulnerability. For further support and assistance in vulnerability remediation, you can reach out to DevNack.com.

See every vulnerability recorded for topthink/thinkphp →

Share this vulnerability

FAQ

ThinkPHP is a PHP framework used for developing web applications. It provides a range of features and functionalities to simplify the development process.

Versions 3.2.3 and below of ThinkPHP are affected by this SQL injection vulnerability.

This vulnerability allows an attacker to execute arbitrary SQL queries, potentially leading to unauthorized access, data manipulation, or complete compromise of the application's database.

To fix this vulnerability, it is recommended to upgrade to a patched version of ThinkPHP. Additionally, always sanitize and validate user input before using it in database queries to prevent SQL injection attacks.

As a temporary workaround, you can manually validate and sanitize user input before passing it to the vulnerable methods. Use parameterized queries or prepared statements to prevent SQL injection.

Related vulnerabilities

Recent vulnerabilities recorded for topthink/thinkphp.

How To Fix

No fixed version is published for this vulnerability.

Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. 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