Rust Diesel Sqlx Connection String Injection
Description
This vulnerability detector identifies SQL injection risks in Rust applications using diesel or sqlx libraries with actix_web framework. It detects when user-controlled data can be injected into database connection strings, which could allow attackers to modify connection parameters or access unauthorized databases.
Detection Strategy
• Checks if the code imports both database libraries (sqlx or diesel) and the actix_web web framework
• Scans for database connection string construction patterns that accept external input
• Identifies connection option host parameters that can be controlled by user input
• Reports vulnerabilities when user data flows into database connection strings or host parameters without proper validation
Vulnerable code example
use actix_web::{get, web, HttpResponse};
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};
use serde::Deserialize;
#[derive(Deserialize)]
struct ConnectRequest {
host: String,
}...✅ Secure code example
use actix_web::{get, web, HttpResponse};
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};
use serde::Deserialize;
#[derive(Deserialize)]
struct ConnectRequest {
host: String,
}...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.