logo

Database

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.

Weakness:

100 - Server-side request forgery (SSRF)

Category: Deceptive Interactions

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,
}...