Skip to content

Commit c17efa7

Browse files
authored
wasi:http: Restrict valid set of HTTP response codes to 100-599 (#12149)
For wasip3, ensure that response codes are in the RFC 9110-specified ranges. See WebAssembly/WASI#849.
1 parent a511435 commit c17efa7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

crates/wasi-http/src/p3/host/types.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,13 @@ impl HostResponse for WasiHttpCtxView<'_> {
679679
status_code: StatusCode,
680680
) -> wasmtime::Result<Result<(), ()>> {
681681
let res = get_response_mut(self.table, &res)?;
682-
let Ok(status) = http::StatusCode::from_u16(status_code) else {
683-
return Ok(Err(()));
684-
};
685-
res.status = status;
686-
Ok(Ok(()))
682+
match http::StatusCode::from_u16(status_code) {
683+
Ok(status) if matches!(status_code, 100..=599) => {
684+
res.status = status;
685+
Ok(Ok(()))
686+
}
687+
_ => Ok(Err(())),
688+
}
687689
}
688690

689691
fn get_headers(&mut self, res: Resource<Response>) -> wasmtime::Result<Resource<Headers>> {

tests/wasi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use wit_component::ComponentEncoder;
1616

1717
const KNOWN_FAILURES: &[&str] = &[
1818
"filesystem-hard-links",
19-
"http-response",
2019
"filesystem-read-directory",
2120
// FIXME(#11524)
2221
"remove_directory_trailing_slashes",

0 commit comments

Comments
 (0)