gqlprobe 1.0.0

Fast GraphQL security scanner - schema-aware introspection, injection, DoS, CSRF, auth bypass, SARIF
Documentation
//! Rate-limit detection module (GQL-014).
//!
//! Sends a short burst of identical GraphQL POST requests and reports when the
//! endpoint processes nearly all of them without HTTP 429 throttling.

use anyhow::Result;
use scanclient::reqwest::header::CONTENT_TYPE;
use scanclient::ScanClient;
use secfinding::{Finding, FindingKind, Severity};
use serde_json::json;
use tracing::debug;

use crate::context::ScanContext;

/// Number of rapid requests in the burst probe.
pub const BURST_REQUEST_COUNT: usize = 25;

/// Minimum successes (non-429) before flagging missing rate limits.
pub const BURST_SUCCESS_THRESHOLD: usize = 20;

const PROBE_QUERY: &str = "{ __typename }";

/// Burst probe with scan context.
pub async fn test_with_context(client: &ScanClient, ctx: &ScanContext) -> Result<Vec<Finding>> {
    test(client, ctx.url()).await
}

/// Run burst rate-limit probe.
pub async fn test(client: &ScanClient, url: &str) -> Result<Vec<Finding>> {
    let mut successes = 0usize;
    let mut throttled = false;

    debug!(
        "Running rate-limit burst probe ({} requests) on {}",
        BURST_REQUEST_COUNT, url
    );

    for _ in 0..BURST_REQUEST_COUNT {
        let body = json!({ "query": PROBE_QUERY });
        let request = client
            .request(scanclient::reqwest::Method::POST, url)
            .header(CONTENT_TYPE, "application/json")
            .body(body.to_string());

        let Ok(resp) = client.execute(request).await else {
            continue;
        };

        if resp.status().as_u16() == 429 {
            throttled = true;
            break;
        }

        if resp.status().is_success() {
            successes += 1;
        }
    }

    if throttled || successes < BURST_SUCCESS_THRESHOLD {
        return Ok(Vec::new());
    }

    Ok(vec![Finding::builder("gqlprobe", url, Severity::Low)
        .title("No Rate Limiting Observed Under Burst Probe")
        .detail(format!(
            "Sent {BURST_REQUEST_COUNT} rapid identical GraphQL POST requests; \
             {successes} returned success without HTTP 429. Attackers may brute-force \
             or amplify load without per-client throttling."
        ))
        .remediation(
            "Apply per-IP and per-token rate limits; count GraphQL operations, not only HTTP requests.",
        )
        .kind(FindingKind::Misconfiguration)
        .tag("graphql")
        .tag("rate-limit")
        .cwe("CWE-770")
        .build()?])
}