-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add option to not lowercase headers #256
Comments
I am open to supporting this at the connection or at the request level, I think. @ericmj thoughts? |
If the only use case is avoid fingerprinting I am not sure it is worth it. There are likely plenty of other ways to detect mint and it does not seem feasible to avoid all of them. |
Related discussion: #172 Things to clarify
|
@ericmj
|
We send some headers in the same order as well. Can you explain your use-case for wanting to avoid finger printing? |
@ericmj |
You can customize the |
@whatyouhide
received request
|
So we don't change the order of headers and set the |
We have a specific order of headers when mint sets them itself. For example: @hissssst I am hesitant to make these kind of changes because it will always be a back and forth between services finding new ways of detecting clients and clients trying to circumvent them. We still don't know if the changes you suggested will actually prevent vk.com from detecting mint. |
That is right but these headers can be set explicitly I understand you hesitation but I already have the working fork which prooves my words. I also argee that this option would be useless for 99% of users. |
Just chiming in to add that if someone switches to Mint from a library that previously did not modify the casing of headers, they will inadvertently break backwards compatibility for users that might be relying on headers being case-insensitive. This could have serious implications for anyone switching to Mint that might not be expecting lower-case headers for HTTP1. |
Reopening this issue for case of @JacquiManzi |
Changing libraries is indeed a backwards incompatible action. It is not the goal of Mint to be compatible with pre-existing HTTP clients, especially if you are relying on behavior that does not follow the HTTP specification. If you can give examples on applications, services, APIs, etc. that require case-sensitive headers then we can discuss around them specifically. I will reopen if we have such examples to discuss. |
I might be misunderstanding what you mean by this, but the specification for HTTP/1.1 headers are case-insensitive. |
@JacquiManzi what @ericmj means is that if you switch HTTP library, you shouldn't expect backwards compatibility to be maintained. You should adapt your code to use the new library and not just drop it in and expect it to behave exactly the same, if that makes sense.
Which is exactly why we lowercase them and it shouldn't make a difference, because the spec is case-insensitive. Hopefully this makes things clearer. |
@whatyouhide that makes sense, thank you for the clarification. |
Hey there @whatyouhide @ericmj - first thanks for this library & everything, as always! 💚 We're currently running into a similar issue - in our case, it's a 3rd party we don't control though that treats the headers as case sensitive. In particular, it's a let's say big/old organization we need to integrate with and a required header from them that is We'd be happy to provide an MR implementing this (given some guidance on what level you feel would be most appropriate for this) if you were considering allowing this change. Just an option to opt out of the lower casing behavior if one needs to. |
I would be okay with an option to do this, provided we make it clear it should not be used (because it goes against the spec). Something like |
Your call, I'd rather leave the |
@ericmj small ping :) |
Should there be separate options for requests and responses? For example, I know the headers my application sends will be valid (and it could possibly be a minor perf boost to skip downcasing), but I would probably still want to make sure response headers are downcased |
My goal would be to pass it on request initiation explicitly, so it'd only affect requests sent out. |
Unfortunately if we add a
I'm not sure we should add this complexity to handle the rare case of servers not following the specification. I think a better alternative would be to add an option that forces the casing of headers or adds a rewrite rule/function for headers. It would be self contained to only where we encode headers and wouldn't have a performance penalty for users that don't need it. encode_headers_camel_case: boolean()
rewrite_header_name: (String.t() -> String.t()) | nil |
@ericmj what if we keep the original headers around alongside the downcased headers? I think using the downcased headers in Mint itself is the way to go, but we could hand over the original headers to the user, at least for responses. |
Is there a need to do this for response headers? Unless Mint is used for proxying I don't see a need for it. We could do it for request headers but I would prefer to rewrite at encoding time than keeping both the downcase and original header names everywhere. Not a strong opinion but if we are doing things outside of the specification I would prefer to keep it as contained as possible. |
@ericmj the problem with rewriting itself is that you don't really have a way to know what the server sent, for example if you're implementing a proxy. And yes, for response headers, that would be needed if you're using Mint for proxying or for writing some weird tool that tries to break servers or whatnot, who knows. I think Mint is low-level enough that it makes sense to keep things compliant with the spec, but also allow users to do these non-conforming things when they want. |
Why is this a problem, the rewriting function will receive the header name and know what the server sent?
Do we need this for response headers? It seemed like @PragTob and @hissssst only needed it for request headers. If there is no user need for it then I don't think we should implement it, specially since it's for something outside the specification. |
To clarify the proposal for this options was only for the request headers. rewrite_header_name: (String.t() -> String.t()) | nil |
I am here to confirm that I needed this option only for request headers, but I think that this option could be useful for response headers too. Case of the headers is one of many factors accountable for application fingerprinting. |
@ericmj and I talked about this and we decided that yes, having an option to not lowercase request headers is something we want in Mint. Let's call the option Anybody willing to work on a PR for this? 😊 |
Just some additional feedback, In Req v0.4, I'm automatically downcasing all header names. Furthermore, functions like So unless someone does something really custom (and manually updates the underlying |
@wojtekmach we'd love some help to bring #399 over the finish line in case you have some bandwidth 😉 |
Implemented in #399. |
Current behaviour:
Headers are always translated to lowercase
Desired behaviour:
Have connection option to not translate request and response headers to lowercase in HTTP 1.x
This option would be useful to trick passive http-client fingerprinting
I can implement the PR
The text was updated successfully, but these errors were encountered: