Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/http/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,25 @@ pub(crate) fn header_map_from_wasi(wasi_fields: Fields) -> Result<HeaderMap, Err
pub(crate) fn header_map_to_wasi(header_map: &HeaderMap) -> Result<Fields, Error> {
let wasi_fields = Fields::new();
for (key, value) in header_map {
// Unwrap because `HeaderMap` has already validated the headers.
wasi_fields
.append(key.as_str(), value.as_bytes())
.with_context(|| format!("wasi rejected header `{key}: {value:?}`"))?
if !FORBIDDEN_HEADERS.contains(key) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while technically HTTP headers are case sensitive, ones like Content-Length are not usually handled that way.

I recommend normalizing every entry in FORBIDDEN_HEADERS to be lowercase and also to use key.to_ascii_lowercase() here in this contains call as well.

wasi_fields
.append(key.as_str(), value.as_bytes())
.with_context(|| format!("wasi rejected header `{key}: {value:?}`"))?
}
}
Ok(wasi_fields)
}

const FORBIDDEN_HEADERS: [HeaderName; 11] = [
http::header::CONNECTION,
HeaderName::from_static("keep-alive"),
http::header::PROXY_AUTHENTICATE,
http::header::PROXY_AUTHORIZATION,
HeaderName::from_static("proxy-connection"),
http::header::TRANSFER_ENCODING,
http::header::UPGRADE,
http::header::HOST,
HeaderName::from_static("http2-settings"),
http::header::EXPECT,
http::header::CONTENT_LENGTH,
];