Skip to content

Commit

Permalink
http2: event on mismatch between authority and host
Browse files Browse the repository at this point in the history
Ticket: OISF#6425
(cherry picked from commit 46a46e5)
  • Loading branch information
catenacyber committed Nov 9, 2023
1 parent b0e8b6f commit 4c16eb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions rules/http2-events.rules
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ alert http2 any any -> any any (msg:"SURICATA HTTP2 too long frame data"; flow:e
alert http2 any any -> any any (msg:"SURICATA HTTP2 stream identifier reuse"; flow:established; app-layer-event:http2.stream_id_reuse; classtype:protocol-command-decode; sid:2290007; rev:1;)
alert http2 any any -> any any (msg:"SURICATA HTTP2 invalid HTTP1 settings during upgrade"; flow:established; app-layer-event:http2.invalid_http1_settings; classtype:protocol-command-decode; sid:2290008; rev:1;)
alert http2 any any -> any any (msg:"SURICATA HTTP2 failed decompression"; flow:established; app-layer-event:http2.failed_decompression; classtype:protocol-command-decode; sid:2290009; rev:1;)
#alert http2 any any -> any any (msg:"SURICATA HTTP2 invalid range header"; flow:established; app-layer-event:http2.invalid_range; classtype:protocol-command-decode; sid:2290010; rev:1;)
#alert http2 any any -> any any (msg:"SURICATA HTTP2 variable-length integer overflow"; flow:established; app-layer-event:http2.header_integer_overflow; classtype:protocol-command-decode; sid:2290011; rev:1;)
#alert http2 any any -> any any (msg:"SURICATA HTTP2 too many streams"; flow:established; app-layer-event:http2.too_many_streams; classtype:protocol-command-decode; sid:2290012; rev:1;)
alert http2 any any -> any any (msg:"SURICATA HTTP2 authority host mismatch"; flow:established,to_server; app-layer-event:http2.authority_host_mismatch; classtype:protocol-command-decode; sid:2290013; rev:1;)
30 changes: 22 additions & 8 deletions rust/src/http2/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,27 @@ impl HTTP2Transaction {
}
}

#[cfg(not(feature = "decompression"))]
fn handle_headers(&mut self, _blocks: &Vec<parser::HTTP2FrameHeaderBlock>, _dir: u8) {}

#[cfg(feature = "decompression")]
fn handle_headers(&mut self, blocks: &Vec<parser::HTTP2FrameHeaderBlock>, dir: u8) {
for i in 0..blocks.len() {
if blocks[i].name == b"content-encoding" {
self.decoder.http2_encoding_fromvec(&blocks[i].value, dir);
fn handle_headers(&mut self, blocks: &[parser::HTTP2FrameHeaderBlock], dir: u8) {
let mut authority = None;
let mut host = None;
for block in blocks {
if block.name == b"content-encoding" {
#[cfg(feature = "decompression")]
self.decoder.http2_encoding_fromvec(&block.value, dir);
} else if block.name.eq_ignore_ascii_case(b":authority") {
authority = Some(&block.value);
} else if block.name.eq_ignore_ascii_case(b"host") {
host = Some(&block.value);
}
}
if let Some(a) = authority {
if let Some(h) = host {
if !a.eq_ignore_ascii_case(h) {
// The event is triggered only if both headers
// are in the same frame to avoid excessive
// complexity at runtime.
self.set_event(HTTP2Event::AuthorityHostMismatch);
}
}
}
}
Expand Down Expand Up @@ -336,6 +349,7 @@ pub enum HTTP2Event {
StreamIdReuse,
InvalidHTTP1Settings,
FailedDecompression,
AuthorityHostMismatch,
}

impl HTTP2Event {
Expand Down

0 comments on commit 4c16eb5

Please sign in to comment.