vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
//! Catalog entry for `detect_path_traversal`.

use crate::ops::security_detection::detector_support::{attacks, DetectionError};

/// Embedded operation spec formerly stored in metadata/spec.toml.
pub const SPEC_TOML: &str = r#"schema_version = 1
id = "security_detection.detect_path_traversal"
archetype = "rule-bytes-to-bool"
display_name = "Detect Path Traversal"
summary = "Returns true for decoded or raw parent-directory traversal."
category = "C"

[intrinsic]
wgsl = "security_detection_detect_path_traversal"

[signature]
inputs = ["Bytes"]
output = "Bool"

laws = []
equivalence_classes = ["raw_traversal", "encoded_traversal", "plain_path", "t47_cap"]
workgroup_size = [64, 1, 1]
tags = ["security-detection", "path-traversal", "owasp", "t47"]
fixtures_dir = "fixtures/"
"#;

/// Embedded reference vectors formerly stored in fixtures/reference-vectors.toml.
pub const REFERENCE_VECTORS_TOML: &str = r#"[[case]]
name = "positive_encoded"
input = "path=..%2f..%2fetc/passwd"
expected = true

[[case]]
name = "negative_plain_path"
input = "path=/var/www/static/app.js"
expected = false
"#;

/// WGSL lowering source for this detector.
pub mod lowering {
    /// Return the detector-specific WGSL source.
    #[must_use]
    pub const fn source() -> &'static str {
        r#"@compute @workgroup_size(64)
pub fn detect_path_traversal() {
    out[0] = select(0u, 1u,
        contains_ci("../") || contains_ci("..\\") ||
        contains_ci("..//") || contains_ci("..\\\\"));
}"#
    }
}

/// Return true for decoded or raw parent-directory traversal.
///
/// # Errors
///
/// Returns `Fix: ...` when input exceeds 64 MiB.
pub fn detect_path_traversal(input: &[u8]) -> Result<bool, DetectionError> {
    attacks::detect_path_traversal(input)
}

/// Compatibility surface for the previous generated implementation module.
pub mod implementation {
    pub use super::detect_path_traversal;
    /// Compatibility module for callers that used the generated kernel path.
    pub mod kernel {
        pub use super::super::detect_path_traversal;
    }

    /// Compatibility module for callers that used the generated lowering path.
    pub mod lowering {
        /// Compatibility module for callers that used `implementation::lowering::wgsl`.
        pub mod wgsl {
            pub use super::super::super::lowering::source;
        }
    }
}