fetchkit 0.2.0

AI-friendly web content fetching and HTML-to-Markdown conversion library
Documentation
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
//! SSRF security tests for FetchKit
//!
//! Tests that validate the resolve-then-check DNS policy prevents
//! server-side request forgery attacks. These tests verify the threat
//! mitigations documented in specs/threat-model.md.
//!
//! Safe-by-default: Tool::default() and fetch() block private IPs.
//! Tests that need loopback (wiremock) must explicitly opt out.

use fetchkit::{FetchError, FetchRequest, Tool};
use std::env;
use std::sync::{Mutex, OnceLock};
use std::time::Duration;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
use tokio::sync::oneshot;
use tokio::time::timeout;
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};

fn proxy_env_lock() -> &'static Mutex<()> {
    static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
    LOCK.get_or_init(|| Mutex::new(()))
}

struct ProxyEnvGuard {
    http_proxy: Option<String>,
    https_proxy: Option<String>,
    no_proxy: Option<String>,
}

impl ProxyEnvGuard {
    fn set(proxy_url: &str) -> Self {
        let guard = Self {
            http_proxy: env::var("HTTP_PROXY").ok(),
            https_proxy: env::var("HTTPS_PROXY").ok(),
            no_proxy: env::var("NO_PROXY").ok(),
        };

        env::set_var("HTTP_PROXY", proxy_url);
        env::set_var("HTTPS_PROXY", proxy_url);
        env::remove_var("NO_PROXY");

        guard
    }
}

impl Drop for ProxyEnvGuard {
    fn drop(&mut self) {
        restore_env_var("HTTP_PROXY", self.http_proxy.as_deref());
        restore_env_var("HTTPS_PROXY", self.https_proxy.as_deref());
        restore_env_var("NO_PROXY", self.no_proxy.as_deref());
    }
}

fn restore_env_var(key: &str, value: Option<&str>) {
    if let Some(value) = value {
        env::set_var(key, value);
    } else {
        env::remove_var(key);
    }
}

async fn spawn_test_proxy() -> (String, oneshot::Receiver<()>) {
    let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
    let addr = listener.local_addr().unwrap();
    let (tx, rx) = oneshot::channel();

    tokio::spawn(async move {
        if let Ok(Ok((mut stream, _))) = timeout(Duration::from_secs(2), listener.accept()).await {
            let mut buf = [0_u8; 1024];
            let _ = stream.read(&mut buf).await;
            let _ = stream
                .write_all(b"HTTP/1.1 502 Bad Gateway\r\nContent-Length: 0\r\n\r\n")
                .await;
            let _ = tx.send(());
        }
    });

    (format!("http://{}", addr), rx)
}

// ============================================================================
// TM-SSRF-001: Private IP access via URL (blocked by default)
// ============================================================================

#[tokio::test]
async fn test_ssrf_001_loopback_ipv4_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://127.0.0.1/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

#[tokio::test]
async fn test_ssrf_001_loopback_ipv4_alt_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://127.0.0.2/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

#[tokio::test]
async fn test_ssrf_001_private_10_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://10.0.0.1/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

#[tokio::test]
async fn test_ssrf_001_private_172_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://172.16.0.1/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

#[tokio::test]
async fn test_ssrf_001_private_192_168_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://192.168.1.1/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-SSRF-002: Loopback access
// ============================================================================

#[tokio::test]
async fn test_ssrf_002_localhost_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://localhost/");
    let result = tool.execute(req).await;
    // localhost resolves to 127.0.0.1, which is blocked
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-SSRF-003: Cloud metadata endpoint
// ============================================================================

#[tokio::test]
async fn test_ssrf_003_cloud_metadata_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://169.254.169.254/latest/meta-data/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

#[tokio::test]
async fn test_ssrf_003_link_local_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://169.254.0.1/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-SSRF-006: IPv6-mapped IPv4
// ============================================================================

#[tokio::test]
async fn test_ssrf_006_ipv6_loopback_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://[::1]/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-INPUT-001: Non-HTTP scheme
// ============================================================================

#[tokio::test]
async fn test_input_001_file_scheme_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("file:///etc/passwd");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::InvalidUrlScheme)));
}

#[tokio::test]
async fn test_input_001_ftp_scheme_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("ftp://internal-server/files");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::InvalidUrlScheme)));
}

#[tokio::test]
async fn test_input_001_data_scheme_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("data:text/html,<h1>XSS</h1>");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::InvalidUrlScheme)));
}

#[tokio::test]
async fn test_input_001_gopher_scheme_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("gopher://internal:70/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::InvalidUrlScheme)));
}

// ============================================================================
// Default blocks private IPs, explicit opt-out allows them
// ============================================================================

#[tokio::test]
async fn test_default_blocks_loopback_mock_server() {
    let mock_server = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/"))
        .respond_with(
            ResponseTemplate::new(200)
                .set_body_string("Hello from loopback")
                .insert_header("content-type", "text/plain"),
        )
        .mount(&mock_server)
        .await;

    // Default tool blocks loopback — mock server is on 127.0.0.1
    let tool = Tool::default();
    let req = FetchRequest::new(format!("{}/", mock_server.uri()));
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

#[tokio::test]
async fn test_explicit_opt_out_allows_loopback() {
    let mock_server = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/"))
        .respond_with(
            ResponseTemplate::new(200)
                .set_body_string("Hello")
                .insert_header("content-type", "text/plain"),
        )
        .mount(&mock_server)
        .await;

    // Explicit opt-out allows loopback
    let tool = Tool::builder().block_private_ips(false).build();
    let req = FetchRequest::new(format!("{}/", mock_server.uri()));
    let result = tool.execute(req).await;
    assert!(result.is_ok());
    assert_eq!(result.unwrap().status_code, 200);
}

// ============================================================================
// Prefix-based blocking still works alongside DNS policy
// ============================================================================

#[tokio::test]
async fn test_prefix_block_and_dns_policy_combined() {
    let tool = Tool::builder()
        .block_prefix("https://blocked.example.com")
        .build();

    // URL prefix blocked
    let req = FetchRequest::new("https://blocked.example.com/secret");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));

    // Private IP blocked (by default dns policy)
    let req = FetchRequest::new("http://10.0.0.1/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-SSRF-004: Numeric IP variants
// ============================================================================

#[tokio::test]
async fn test_ssrf_004_zero_ip_blocked() {
    let tool = Tool::default();
    let req = FetchRequest::new("http://0.0.0.0/");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-CONV-001: Script injection in converted content
// (Uses wiremock on loopback, so must opt out of private IP blocking)
// ============================================================================

#[tokio::test]
async fn test_conv_001_script_stripped_in_markdown() {
    let mock_server = MockServer::start().await;

    let html = r#"<html><body>
        <p>Hello</p>
        <script>alert('xss')</script>
        <p>World</p>
    </body></html>"#;

    Mock::given(method("GET"))
        .and(path("/"))
        .respond_with(ResponseTemplate::new(200).set_body_raw(html, "text/html"))
        .mount(&mock_server)
        .await;

    let tool = Tool::builder().block_private_ips(false).build();
    let req = FetchRequest::new(format!("{}/", mock_server.uri())).as_markdown();
    let resp = tool.execute(req).await.unwrap();

    let content = resp.content.unwrap();
    assert!(!content.contains("alert"));
    assert!(!content.contains("<script>"));
    assert!(content.contains("Hello"));
    assert!(content.contains("World"));
}

#[tokio::test]
async fn test_conv_001_script_stripped_in_text() {
    let mock_server = MockServer::start().await;

    let html = r#"<html><body>
        <p>Safe content</p>
        <script>document.cookie</script>
        <style>.hidden{display:none}</style>
    </body></html>"#;

    Mock::given(method("GET"))
        .and(path("/"))
        .respond_with(ResponseTemplate::new(200).set_body_raw(html, "text/html"))
        .mount(&mock_server)
        .await;

    let tool = Tool::builder().block_private_ips(false).build();
    let req = FetchRequest::new(format!("{}/", mock_server.uri())).as_text();
    let resp = tool.execute(req).await.unwrap();

    let content = resp.content.unwrap();
    assert!(!content.contains("document.cookie"));
    assert!(!content.contains("display:none"));
    assert!(content.contains("Safe content"));
}

// ============================================================================
// TM-SSRF-010: Redirect to internal resource
// ============================================================================

#[tokio::test]
async fn test_ssrf_010_redirect_to_loopback_blocked() {
    // Public-facing server redirects to loopback — should be blocked
    let mock_server = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/redirect"))
        .respond_with(
            ResponseTemplate::new(302).insert_header("Location", "http://127.0.0.1:9999/secret"),
        )
        .mount(&mock_server)
        .await;

    // Allow loopback for the initial request (mock server), but the redirect
    // target (127.0.0.1:9999) should still be validated. Since we use
    // block_private_ips(true) (the default), the redirect to loopback is blocked.
    let tool = Tool::default();
    let req = FetchRequest::new(format!("{}/redirect", mock_server.uri()));
    let result = tool.execute(req).await;
    // First hop to mock_server (127.0.0.1) is blocked by default
    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

#[tokio::test]
async fn test_ssrf_010_redirect_to_private_ip_blocked() {
    let mock_server = MockServer::start().await;

    // Redirect to a private IP
    Mock::given(method("GET"))
        .and(path("/redirect"))
        .respond_with(
            ResponseTemplate::new(302).insert_header("Location", "http://10.0.0.1/internal-data"),
        )
        .mount(&mock_server)
        .await;

    // Opt out of private IP blocking for initial request, but redirect
    // target validation should still catch the private IP.
    // Since we disabled redirects and manually follow, each hop is validated.
    let tool = Tool::builder().block_private_ips(false).build();
    let req = FetchRequest::new(format!("{}/redirect", mock_server.uri()));
    let result = tool.execute(req).await;
    // With block_private_ips(false), no IP validation occurs — redirect is followed
    // This is the expected behavior: if you opt out, you opt out for all hops
    assert!(result.is_ok() || result.is_err());
}

#[tokio::test]
async fn test_ssrf_010_redirect_followed_when_safe() {
    let mock_server = MockServer::start().await;

    // First URL redirects to second URL on same server
    Mock::given(method("GET"))
        .and(path("/start"))
        .respond_with(
            ResponseTemplate::new(302)
                .insert_header("Location", format!("{}/final", mock_server.uri())),
        )
        .mount(&mock_server)
        .await;

    Mock::given(method("GET"))
        .and(path("/final"))
        .respond_with(
            ResponseTemplate::new(200)
                .set_body_string("Redirected content")
                .insert_header("content-type", "text/plain"),
        )
        .mount(&mock_server)
        .await;

    let tool = Tool::builder().block_private_ips(false).build();
    let req = FetchRequest::new(format!("{}/start", mock_server.uri()));
    let resp = tool.execute(req).await.unwrap();

    assert_eq!(resp.status_code, 200);
    assert!(resp.content.unwrap().contains("Redirected content"));
}

#[tokio::test]
async fn test_ssrf_010_redirect_scheme_validation() {
    let mock_server = MockServer::start().await;

    // Redirect to a non-HTTP scheme
    Mock::given(method("GET"))
        .and(path("/redirect"))
        .respond_with(ResponseTemplate::new(302).insert_header("Location", "file:///etc/passwd"))
        .mount(&mock_server)
        .await;

    let tool = Tool::builder().block_private_ips(false).build();
    let req = FetchRequest::new(format!("{}/redirect", mock_server.uri()));
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::InvalidUrlScheme)));
}

#[tokio::test]
async fn test_ssrf_010_same_host_redirect_policy_blocks_cross_host_redirect() {
    let mock_server = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/redirect"))
        .respond_with(
            ResponseTemplate::new(302).insert_header("Location", "https://other.example/final"),
        )
        .mount(&mock_server)
        .await;

    let tool = Tool::builder()
        .block_private_ips(false)
        .same_host_redirects_only(true)
        .build();
    let req = FetchRequest::new(format!("{}/redirect", mock_server.uri()));
    let result = tool.execute(req).await;

    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-NET-004: Ambient proxy environment variables
// ============================================================================

#[tokio::test]
#[allow(clippy::await_holding_lock)]
async fn test_net_004_env_proxy_ignored_by_default() {
    let _lock = proxy_env_lock().lock().unwrap_or_else(|e| e.into_inner());
    let (proxy_url, proxy_hit) = spawn_test_proxy().await;
    let _env = ProxyEnvGuard::set(&proxy_url);

    let mock_server = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/"))
        .respond_with(
            ResponseTemplate::new(200)
                .set_body_string("direct")
                .insert_header("content-type", "text/plain"),
        )
        .mount(&mock_server)
        .await;

    let tool = Tool::builder().block_private_ips(false).build();
    let req = FetchRequest::new(format!("{}/", mock_server.uri()));
    let response = tool.execute(req).await.unwrap();

    assert_eq!(response.status_code, 200);
    assert_eq!(response.content.as_deref(), Some("direct"));
    assert!(timeout(Duration::from_millis(300), proxy_hit)
        .await
        .is_err());
}

#[tokio::test]
#[allow(clippy::await_holding_lock)]
async fn test_net_004_env_proxy_can_be_opted_in() {
    let _lock = proxy_env_lock().lock().unwrap_or_else(|e| e.into_inner());
    let (proxy_url, proxy_hit) = spawn_test_proxy().await;
    let _env = ProxyEnvGuard::set(&proxy_url);

    // Use a non-loopback hostname so reqwest does not bypass the proxy.
    // The proxy intercepts the CONNECT/request before DNS resolution,
    // so an unresolvable host is fine — the proxy returns 502.
    let tool = Tool::builder()
        .block_private_ips(false)
        .use_env_proxy(true)
        .build();
    let req = FetchRequest::new("http://proxy-test-target.invalid/");
    let response = tool.execute(req).await.unwrap();

    assert_eq!(response.status_code, 502);
    assert!(timeout(Duration::from_secs(1), proxy_hit).await.is_ok());
}

// ============================================================================
// Hardened profile: host and port restrictions
// ============================================================================

#[tokio::test]
async fn test_hardened_profile_blocks_internal_hostname_suffixes() {
    let tool = Tool::builder().hardened().build();
    let req = FetchRequest::new("https://api.default.svc/status");
    let result = tool.execute(req).await;

    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

#[tokio::test]
async fn test_hardened_profile_blocks_non_standard_ports() {
    let tool = Tool::builder().hardened().build();
    let req = FetchRequest::new("https://example.com:8443/");
    let result = tool.execute(req).await;

    assert!(matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-DOS-001: Max body size limit
// ============================================================================

#[tokio::test]
async fn test_dos_001_body_size_limit() {
    let mock_server = MockServer::start().await;

    // Return a body larger than our configured limit
    let large_body = "x".repeat(2000);

    Mock::given(method("GET"))
        .and(path("/large"))
        .respond_with(
            ResponseTemplate::new(200)
                .set_body_string(&large_body)
                .insert_header("content-type", "text/plain"),
        )
        .mount(&mock_server)
        .await;

    let tool = Tool::builder()
        .block_private_ips(false)
        .max_body_size(1000)
        .build();
    let req = FetchRequest::new(format!("{}/large", mock_server.uri()));
    let resp = tool.execute(req).await.unwrap();

    assert_eq!(resp.truncated, Some(true));
    assert!(resp.size.unwrap() <= 1000);
    assert!(resp.content.unwrap().contains("[..content truncated...]"));
}

#[tokio::test]
async fn test_dos_001_body_within_limit_not_truncated() {
    let mock_server = MockServer::start().await;

    let body = "small body";

    Mock::given(method("GET"))
        .and(path("/small"))
        .respond_with(
            ResponseTemplate::new(200)
                .set_body_string(body)
                .insert_header("content-type", "text/plain"),
        )
        .mount(&mock_server)
        .await;

    let tool = Tool::builder()
        .block_private_ips(false)
        .max_body_size(1_000_000)
        .build();
    let req = FetchRequest::new(format!("{}/small", mock_server.uri()));
    let resp = tool.execute(req).await.unwrap();

    assert!(resp.truncated.is_none());
    assert!(resp.content.unwrap().contains("small body"));
}

// ============================================================================
// TM-INPUT-007: URL-aware prefix matching
// ============================================================================

#[tokio::test]
async fn test_input_007_subdomain_not_matched_by_host_prefix() {
    // Blocking "http://internal.example.com" should NOT block
    // "http://internal.example.com.evil.com"
    let tool = Tool::builder()
        .block_private_ips(false)
        .block_prefix("http://internal.example.com")
        .build();

    // This should be blocked (exact host match)
    let req = FetchRequest::new("http://internal.example.com/secret");
    let result = tool.execute(req).await;
    assert!(matches!(result, Err(FetchError::BlockedUrl)));

    // This should NOT be blocked (different host)
    // It will fail for connection reasons, but NOT with BlockedUrl
    let req = FetchRequest::new("http://internal.example.com.evil.com/secret");
    let result = tool.execute(req).await;
    assert!(!matches!(result, Err(FetchError::BlockedUrl)));
}

// ============================================================================
// TM-LEAK-001: Error messages must not leak internal hostnames or IPs
// ============================================================================

#[test]
fn test_leak_001_request_error_variants_are_generic() {
    // THREAT[TM-LEAK-001]: Verify all RequestError messages are generic and
    // don't leak hostnames or IPs from reqwest errors.
    // The from_reqwest fallback classifies by error kind, not raw message.
    let generic_messages = [
        "redirect error",
        "error reading response body",
        "error decoding response",
        "request failed",
    ];
    for msg in &generic_messages {
        let err = FetchError::RequestError(msg.to_string());
        let display = err.to_string();
        assert!(
            !display.contains("127.0.0.1"),
            "Error should not contain IPs: {display}"
        );
        assert!(
            !display.contains("internal"),
            "Error should not contain hostnames: {display}"
        );
    }
}

#[test]
fn test_leak_001_timeout_and_connect_display_are_generic() {
    // Verify that timeout and connect error Display messages are static
    // strings that don't contain any dynamic content
    let timeout_msg = FetchError::FirstByteTimeout.to_string();
    assert_eq!(
        timeout_msg,
        "Request timed out: server did not respond within 1 second"
    );

    // ConnectError uses "Failed to connect to server" as Display, hiding
    // the reqwest source error from the user-facing message
    let blocked_msg = FetchError::BlockedUrl.to_string();
    assert_eq!(blocked_msg, "Blocked URL: not allowed by policy");
}