/ justapi / fuzz / fuzz_targets / fuzz_router.rs
swadhinbiswas sec(fuzz): add cargo-fuzz targets for parser and protocol attack surfaces · 7/9/2026
e086c74
27 lines · 982 Bytes
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
#![no_main]

use libfuzzer_sys::fuzz_target;

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

    if let Ok(s) = std::str::from_utf8(data) {
        // Build a router with sample routes and fuzz the path matching
        use http::Method;
        let mut router = justapi_core::router::Router::new();
        let _ = router.insert(Method::GET, "/users/{id}", 1usize);
        let _ = router.insert(Method::GET, "/users/{id}/posts", 2);
        let _ = router.insert(Method::GET, "/users/{id}/posts/{post_id}", 3);
        let _ = router.insert(Method::GET, "/static/{*path}", 4);
        let _ = router.insert(Method::GET, "/api/v1/{resource}", 5);
        let _ = router.insert(Method::GET, "/api/v1/{resource}/{action}", 6);
        let _ = router.insert(Method::GET, "/health", 7);
        let _ = router.insert(Method::GET, "/live", 8);
        let _ = router.insert(Method::GET, "/ready", 9);

        let _ = router.at(&Method::GET, s);
    }
});