Skip to content

Commit

Permalink
http2: do not log duplicate headers
Browse files Browse the repository at this point in the history
Ticket: 6900

And thus avoid DOS by logging a request using a compressed
header block repeated many times and having a long value...

(cherry picked from commit 03442c9)
  • Loading branch information
catenacyber authored and victorjulien committed Apr 22, 2024
1 parent e68ec4b commit c0af922
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions rust/src/http2/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use super::http2::{HTTP2Frame, HTTP2FrameTypeData, HTTP2Transaction};
use super::parser;
use crate::jsonbuilder::{JsonBuilder, JsonError};
use std;
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;

#[derive(Hash, PartialEq, Eq, Debug)]
enum HeaderName {
Expand All @@ -35,10 +36,20 @@ fn log_http2_headers<'a>(
blocks: &'a [parser::HTTP2FrameHeaderBlock], js: &mut JsonBuilder,
common: &mut HashMap<HeaderName, &'a Vec<u8>>,
) -> Result<(), JsonError> {
let mut logged_headers = HashSet::new();
for block in blocks {
js.start_object()?;
// delay js.start_object() because we skip suplicate headers
match block.error {
parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeSuccess => {
if Rc::strong_count(&block.name) > 2 {
// more than one reference in headers table + current headers
let ptr = Rc::as_ptr(&block.name) as usize;
if !logged_headers.insert(ptr) {
// only log once
continue;
}
}
js.start_object()?;
js.set_string_from_bytes("name", &block.name)?;
js.set_string_from_bytes("value", &block.value)?;
if let Ok(name) = std::str::from_utf8(&block.name) {
Expand Down Expand Up @@ -66,9 +77,11 @@ fn log_http2_headers<'a>(
}
}
parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeSizeUpdate => {
js.start_object()?;
js.set_uint("table_size_update", block.sizeupdate)?;
}
_ => {
js.start_object()?;
js.set_string("error", &block.error.to_string())?;
}
}
Expand Down

0 comments on commit c0af922

Please sign in to comment.