logo

Database

Rust Log Macro Injection

Description

This detector identifies log injection vulnerabilities in Rust applications using the actix-web framework. Log injection occurs when user-controlled data is directly passed to logging macros without proper sanitization, allowing attackers to inject malicious content into application logs that could corrupt log files or facilitate other attacks.

Weakness:

091 - Log injection

Category: System Manipulation

Detection Strategy

    Code must import or use the actix-web library (checked via library import detection)

    Code contains calls to Rust logging macros (such as log::info!, log::warn!, log::error!, etc.)

    The arguments passed to these logging macros contain user-controlled input or data that originates from user requests

    The user input flows directly into the logging macro without proper validation or sanitization

Vulnerable code example

use actix_web::{get, web, HttpRequest, HttpResponse};

#[get("/search")]
async fn search_vulnerable(query: web::Query<std::collections::HashMap<String, String>>) -> HttpResponse {
    let term = query.get("term").unwrap();
    
    log::info!("User searched for: {}", term); // User input directly logged - enables log injection
    ...

✅ Secure code example

use actix_web::{get, web, HttpRequest, HttpResponse};

fn sanitize_log_input(input: &str) -> String {
    input
        .replace('\n', "\\n")
        .replace('\r', "\\r")
        .replace('\t', "\\t")
        .chars()...