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

Unrecognized schemas interpreted as HTTP #919

Closed
jsha opened this issue May 24, 2020 · 1 comment · Fixed by #921
Closed

Unrecognized schemas interpreted as HTTP #919

jsha opened this issue May 24, 2020 · 1 comment · Fixed by #921

Comments

@jsha
Copy link
Contributor

jsha commented May 24, 2020

Steps to reproduce:

  1. Parse a URL containing an invalid schema, e.g. "hxxp".
  2. Request that URL.

Expected result:

Receive an error.

Actual result:

A request is made to the hostname and path from that URL, via HTTP.

This is a bit of a safety problem, since someone could typo the https schema as "htttps:", and the requests would silently be downgraded to HTTP.

use reqwest::{blocking, Url};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let url = Url::parse("hxxp://example.com").unwrap();
    let mut resp = blocking::get(url)?;
    resp.copy_to(&mut std::io::stdout())?;
    Ok(())
}
@jsha
Copy link
Contributor Author

jsha commented May 24, 2020

Spent some time poking at this. It looks like hyper requires that URLs have the "http:" scheme, but reqwest turns that off with enforce_http(false):

http.enforce_http(false);

http.enforce_http(false);

I tried removing those lines in a local checkout and confirmed that I got errors on unrecognized schemes. Of course, this causes hyper to reject "https:" URLs because it doesn't recognize them. It seems like reqwest needs some extra logic to enforce valid schemes, since it turns off hyper's validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant