GuardAPI Logo
GuardAPI
Automated Security Protocol

How to fix BOLA (Broken Object Level Authorization)
in Salvo

Executive Summary

BOLA (IDOR) is the crown jewel of API exploitation. It occurs when your application relies on user-supplied IDs to fetch resources without verifying if the requester actually owns that resource. In Salvo, this typically happens when a handler pulls a UUID or integer from the path and queries the database directly. If you aren't scoping your queries to the authenticated user, you're leaking data.

The Vulnerable Pattern

VULNERABLE CODE
#[handler]
async fn get_user_invoice(req: &mut Request, res: &mut Response) {
    let invoice_id = req.param::("id").unwrap();
    // VULNERABILITY: Fetching by ID only. Any authenticated user can guess an ID.
    let invoice = db::get_invoice(invoice_id).await;
    match invoice {
        Some(data) => res.render(Json(data)),
        None => res.status_code(StatusCode::NOT_FOUND),
    }
}

The Secure Implementation

To kill BOLA in Salvo, you must enforce authorization at the data access layer. First, ensure you have an authentication middleware that populates the Request extensions with the user's identity. In your handler, retrieve this identity and use it as a mandatory filter in your database query. Instead of 'SELECT * FROM invoices WHERE id = ?', your logic must be 'SELECT * FROM invoices WHERE id = ? AND user_id = ?'. If the query returns nothing, return a 404. This ensures that even if an attacker guesses a valid invoice ID, they cannot access it because they do not own it.

SECURE CODE
#[handler]
async fn get_user_invoice(req: &mut Request, res: &mut Response) {
    let invoice_id = req.param::("id").unwrap();
    // Extract the authenticated user's ID from Request extensions (populated by Auth middleware)
    let user = req.extensions().get::().expect("Auth middleware missing");
// FIX: Scope the query to BOTH the resource ID and the owner's ID
let invoice = db::get_invoice_by_user(invoice_id, user.id).await;

match invoice {
    Some(data) => res.render(Json(data)),
    None => {
        // Use 404 to avoid revealing resource existence to unauthorized users
        res.status_code(StatusCode::NOT_FOUND);
    }
}

}

System Alert • ID: 3042
Target: Salvo API
Potential Vulnerability

Your Salvo API might be exposed to BOLA (Broken Object Level Authorization)

74% of Salvo apps fail this check. Hackers use automated scanners to find this specific flaw. Check your codebase before they do.

RUN FREE SECURITY DIAGNOSTIC
GuardLabs Engine: ONLINE

Free Tier • No Credit Card • Instant Report

Verified by Ghost Labs Security Team

This content is continuously validated by our automated security engine and reviewed by our research team. Ghost Labs analyzes over 500+ vulnerability patterns across 40+ frameworks to provide up-to-date remediation strategies.