Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic with npm:fetch-http2 when using headers with Uppercase characters #24678

Closed
arkei1 opened this issue Jul 22, 2024 · 0 comments · Fixed by #24780
Closed

Panic with npm:fetch-http2 when using headers with Uppercase characters #24678

arkei1 opened this issue Jul 22, 2024 · 0 comments · Fixed by #24780
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@arkei1
Copy link

arkei1 commented Jul 22, 2024

Version: Deno 1.45.2

So, I got a panic when I tried to use http2 fetch like so:

import { fetch } from 'npm:fetch-http2'

const response = await fetch('https://google.com', {
  headers: {
    'User-Agent': 'fetch-http2'
  }
})

However such a code results in a panic:

$ deno run --allow-net main.ts

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.45.2
Args: ["deno", "run", "--allow-net", "main.ts"]

thread 'main' panicked at ext/node/ops/http2.rs:320:41:
called `Result::unwrap()` on an `Err` value: InvalidHeaderName
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The error message refers to this line:

HeaderName::from_lowercase(&name).unwrap(),

Which uses from_lowercase from http crate:

https://github.com/hyperium/http/blob/f4e8c0c3159b18b8b7e4a6a3762c55528483d25a/src/header/name.rs#L1166-L1193

As seen from the function's code InvalidHeaderName can only occur if any of the characters is 0 according to HEADER_CHARS_H2 array:

https://github.com/hyperium/http/blob/f4e8c0c3159b18b8b7e4a6a3762c55528483d25a/src/header/name.rs#L1040-L1068

One might also notice that this array ain't got uppercase characters. That lead me to try a fully lowercase header:

import { fetch } from 'npm:fetch-http2'

const response = await fetch('https://google.com', {
  headers: {
    'user-agent': 'fetch-http2'
  }
})

And this works fine (it doesn't panic). I think the issue here is that deno uses a function intended for lowercase strings without ensuring that the string is indeed lowercase.

@bartlomieju bartlomieju added bug Something isn't working correctly node compat labels Jul 22, 2024
crowlKats pushed a commit that referenced this issue Jul 31, 2024
nyannyacha added a commit to nyannyacha/edge-runtime that referenced this issue Sep 14, 2024
nyannyacha added a commit to supabase/edge-runtime that referenced this issue Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants