gqlprobe 1.0.0

Fast GraphQL security scanner - schema-aware introspection, injection, DoS, CSRF, auth bypass, SARIF
Documentation
//! Shared scan context passed to every detection module.

use scanclient::ScanClient;

use crate::baseline::EndpointBaseline;
use crate::schema::SchemaGraph;

/// Runtime context for a single scan against one GraphQL endpoint.
#[derive(Debug, Clone)]
pub struct ScanContext {
    /// Target endpoint URL.
    pub url: String,
    /// Parsed schema from introspection, when available.
    pub schema: Option<SchemaGraph>,
    /// Baseline behavior captured before active tests.
    pub baseline: EndpointBaseline,
}

impl ScanContext {
    /// Build context after schema discovery and baseline capture.
    #[must_use]
    pub fn new(
        url: impl Into<String>,
        schema: Option<SchemaGraph>,
        baseline: EndpointBaseline,
    ) -> Self {
        Self {
            url: url.into(),
            schema,
            baseline,
        }
    }

    /// Borrow the target URL.
    pub fn url(&self) -> &str {
        &self.url
    }
}

/// Arguments passed into each module's `detect` implementation.
pub struct ModuleRun<'a> {
    /// HTTP client.
    pub client: &'a ScanClient,
    /// Scan context (URL, schema, baseline).
    pub ctx: &'a ScanContext,
}

impl<'a> ModuleRun<'a> {
    /// Target URL for this scan.
    pub fn url(&self) -> &str {
        self.ctx.url()
    }
}