Skip to content

Commit

Permalink
Switch brotli2 for brotli resolving CVE
Browse files Browse the repository at this point in the history
CVE-2020-8927 affects Brotli versions <1.0.8 and this includes the
version bundled with `brotli-sys`, no updated upstream version exists so
switching to the pure Rust implementation available in `brotli` is the
most sensible course of action.
  • Loading branch information
bradfier committed Dec 22, 2021
1 parent 92c28b3 commit a799b49
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ categories = ["web-programming::http-server", "web-programming::websocket"]

[features]
default = ["gzip", "brotli"]
brotli = ["brotli2"]
gzip = ["deflate"]
ssl = ["tiny_http/ssl"]

[dependencies]
base64 = "0.13"
brotli2 = { version = "0.3.2", optional = true }
brotli = { version = "3.3.2", optional = true }
chrono = { version = "0.4.19", default-features = false }
filetime = "0.2.0"
deflate = { version = "0.9", optional = true, features = ["gzip"] }
Expand Down
5 changes: 3 additions & 2 deletions src/content_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn gzip(response: &mut Response) {}

#[cfg(feature = "brotli")]
fn brotli(response: &mut Response) {
use brotli2::read::BrotliEncoder;
use brotli::enc::reader::CompressorReader;
use std::mem;
use ResponseBody;

Expand All @@ -141,7 +141,8 @@ fn brotli(response: &mut Response) {
.push(("Content-Encoding".into(), "br".into()));
let previous_body = mem::replace(&mut response.data, ResponseBody::empty());
let (raw_data, _) = previous_body.into_reader_and_size();
response.data = ResponseBody::from_reader(BrotliEncoder::new(raw_data, 6));
// Using default Brotli parameters: 0 buffer_size == 4096, compression level 6, lgwin == 22
response.data = ResponseBody::from_reader(CompressorReader::new(raw_data, 0, 6, 22));
}

#[cfg(not(feature = "brotli"))]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
#![deny(unsafe_code)]

extern crate base64;
#[cfg(feature = "brotli2")]
extern crate brotli2;
#[cfg(feature = "brotli")]
extern crate brotli;
extern crate chrono;
#[cfg(feature = "gzip")]
extern crate deflate;
Expand Down

0 comments on commit a799b49

Please sign in to comment.