Skip to content

@target-uri not working for HTTP/1.0 #32

Description

@KrausMatthias

Hi,

apparently signature validation fails for valid signatures when @target-uri is used on HTTP/1.0 requests.

In HTTP/1.0 the host is provided in the separate HOST header instead of in the uri, see following longstanding issue in hyper: hyperium/hyper#1612

Just checking the request.uri() as in

DerivedComponentName::TargetUri => vec![req_or_res.uri()?.to_string()],
does therefore not work for HTTP/1.0.

I have following horrendous hack in place to make it work with httpsig-hyper, but would be happy to add a PR if you have any idea on how to solve this cleanly within httpsig-hyper.

trait EffectiveUri {
    fn reconstruct_effective_uri(self, scheme: &Scheme) -> Self ;
}

impl EffectiveUri for http::request::Parts {
    fn reconstruct_effective_uri(mut self, scheme: &Scheme) -> Self {
        if self.uri.host().is_none()
            && let Some(host) = self.headers.get(HOST)
        {
            let mut parts = self.uri.into_parts();
            parts.scheme = Some(parts.scheme.unwrap_or(scheme.clone()));
            let host = host.to_str().ok();
            parts.authority = host.and_then(|host| Authority::from_str(host).ok());
            let effective_uri: Uri = parts.try_into().unwrap();
            self.uri = effective_uri;
        }
        self
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions