Skip to content

Commit

Permalink
fix(ext/node): prevent panic in http2.connect with uppercase header n…
Browse files Browse the repository at this point in the history
…ames (#24780)

Closes #24678
  • Loading branch information
satyarohith committed Jul 29, 2024
1 parent ad5cec2 commit 8bab761
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/node/ops/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub async fn op_http2_send_response(
}
for (name, value) in headers {
response.headers_mut().append(
HeaderName::from_lowercase(&name).unwrap(),
HeaderName::from_bytes(&name).unwrap(),
HeaderValue::from_bytes(&value).unwrap(),
);
}
Expand Down Expand Up @@ -317,7 +317,7 @@ pub async fn op_http2_client_request(

for (name, value) in headers {
req.headers_mut().unwrap().append(
HeaderName::from_lowercase(&name).unwrap(),
HeaderName::from_bytes(&name).unwrap(),
HeaderValue::from_bytes(&value).unwrap(),
);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/unit_node/http2_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,35 @@ Deno.test("[node/http2 client] write 512kb buffer on request stream works", asyn
await endPromise.promise;
assertEquals(receivedData!, buffer);
});

// https://github.com/denoland/deno/issues/24678
Deno.test("[node/http2 client] deno doesn't panic on uppercase headers", async () => {
const url = "http://127.0.0.1:4246";
const client = http2.connect(url);
client.on("error", (err) => console.error(err));

// The "User-Agent" header has uppercase characters to test the panic.
const req = client.request({
":method": "POST",
":path": "/",
"User-Agent": "http2",
});
const endPromise = Promise.withResolvers<void>();

let receivedData = "";

req.write("hello");
req.setEncoding("utf8");

req.on("data", (chunk) => {
receivedData += chunk;
});
req.on("end", () => {
req.close();
client.close();
endPromise.resolve();
});
req.end();
await endPromise.promise;
assertEquals(receivedData, "hello world\n");
});

0 comments on commit 8bab761

Please sign in to comment.