/ justapi / fuzz / fuzz_targets / fuzz_pipeline.rs
swadhinbiswas p6: add untrusted-input pipeline fuzz target · 7/24/2026
98a4821
47 lines · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![no_main]

use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
    if data.len() < 2 {
        return;
    }

    // 1. Fuzz JSON Schema validation with arbitrary input bytes
    let schema = r#"{
        "type": "object",
        "properties": {
            "name": {"type": "string", "minLength": 1, "maxLength": 100},
            "age": {"type": "integer", "minimum": 0, "maximum": 150},
            "email": {"type": "string", "format": "email"},
            "website": {"type": "string", "format": "uri"},
            "id": {"type": "string", "format": "uuid"},
            "tags": {"type": "array", "items": {"type": "string"}}
        },
        "required": ["name"]
    }"#;

    let _ = justapi_core::validate::validate_json_schema(data, schema);

    // 2. Fuzz precompiled validator execution
    if let Ok(compiled) = justapi_core::validate::compile_schema(schema) {
        let _ = compiled.validate(data);
    }

    // 3. Fuzz query string parsing
    if let Ok(s) = std::str::from_utf8(data) {
        let _ = justapi_core::validate::parse_query::<serde_json::Value>(s);
    }

    // 4. Fuzz route matching with dynamic paths
    use http::Method;
    let mut router = justapi_core::router::Router::<usize>::new();
    let _ = router.insert(Method::GET, "/users/{id}", 1);
    let _ = router.insert(Method::POST, "/api/v1/{*rest}", 2);

    if let Ok(path) = std::str::from_utf8(data) {
        let _ = router.at(&Method::GET, path);
        let _ = router.at(&Method::POST, path);
    }
});