plabayo / rama

modular service framework to move and transform network packets
https://ramaproxy.org
Apache License 2.0
153 stars 15 forks source link

proxy web client: support opt-in client hints (http headers) #67

Open GlenDC opened 7 months ago

GlenDC commented 7 months ago

Client hints are sourced from either client request or more likely the emulation data.

By default only the following hints are expected to be allowed:

All other headers should be only allowed if:

GlenDC commented 7 months ago

Sec-Fetch headers can always be sent AFAIK.

GlenDC commented 7 months ago

Noted that some CH headers do not follow the sec-ch patterns. The ones I know of as "standard" are:

GlenDC commented 7 months ago

Todo: read carefully again through the client header RFC to see if we miss some details. As Anti-bot wise I don't think the instructions in this issue cover the desired behaviour 100%.

GlenDC commented 7 months ago

RFC, still in Draft, can be found here: https://wicg.github.io/client-hints-infrastructure/

GlenDC commented 7 months ago

Ok the RFC is not as nice as standard RFC's, but I start to get it.

A proxy is however not a regular web client ,and so it might well be that the user of the proxy knows that the server for the given request in a usual flow already would have given a list of headers to accept. As such the allow list written about earlier would essentially allow a request to modify the CH storage, similar to how the response Accept-Ch is allowed to do so.

All client hints, including the ones with non-standard names are mentioned in the above RFC so we can make a static list.

Client hints can also be specified in the HTML of a page... E.g.:

<meta http-equiv="Accept-CH" content="Width, Downlink, Sec-CH-UA" />

This is however only possible if we read the full body and thus I do not think we should do this by default. However it might make sense to have an opt-in flag to allow this to be taken into account as well. It should be opt-in enabled when creating the layer, and optionally it can also be configured to be only done if on top of that the user requests it via some kind of header... As it is a bit expensive to do, compared to just piping the content.

GlenDC commented 7 months ago

Note that these hints also should be considered for caching layers. E.g. Vary: Accept, Width, ECT header has impact on the content served and thus in order to serve appropriate content one has to consider this. #45 .

GlenDC commented 7 months ago

There's also the concept of critical client hints, but that's to do with compatibility of requests, and so we can ignore this.

GlenDC commented 7 months ago

Client hints are still provesional so according to the unconfirmed policy found in https://github.com/hyperium/http/issues/573 it will mean we cannot contribute the client hint headers and ACCEPT-CH to those http/headers crates. These header constants can therefore better be added to rama directly.

GlenDC commented 5 months ago

Tasks to be done:

GlenDC commented 5 months ago

Other requirements / deliverables: good testing + doctest example.