Xray-core: More robust browser header masquerading (chrome, firefox, edge)#5802
Xray-core: More robust browser header masquerading (chrome, firefox, edge)#5802
Conversation
|
Added default headers for both Chrome and Firefox. I don't have either Edge or Safari for their headers, but I'd be quite delighted if anyone's capable of adding them. |
|
I've gone forward and fully implemented the brand GREASE algorithm from the Chromium project. Header masquerading should now be pretty close to a real Chromium-based browser. |
|
Apart from gRPC, user agent fields in other web-based transports already had null values allowed yesterday. I did add special values in the UA field in gRPC, but it's entirely not recommended. The question currently is, would GUI clients like v2rayN(G), OneXray etc actually allow setting the UA field without writing raw config files? And the lack of such field in the sharable link standard would also be encouraging the incoherence problem, especially when the uTLS fingerprint is not set to Edit: Oh, and I forgot to mention, but I just added |
|
|
|
|
It does in an implicit way. Current code detects if the header hasn't been set so that Chrome can be used as default, and empty strings used to prevent UA from being set entirely will be set one step before the special value handling, so nothing is needed for that specific use case. No idea how to deal with null UA for gRPC though. Hopefully the exclamation mark removal wouldn't get Go to scream at me again. |
主要是从真实性的角度来看chrome不可能去发出一个grpc请求 这样的流量绝对是诡异的 只是从面向CF编程的角度这样可以解决问题 |
|
UseDefaultHeadersWith和ApplyDefaultHeaders应该没必要拆开 Use 就是判断一下用户是否输入UA是否存在以及根据里面的预设值选择header组合调用ApplyDefaultHeaders 对用户没法自定义的外部请求UA本来就是空的就是走的第一条自动进chrome分支 都可以用一个UseDefaultHeadersWith |
|
|
|
空的话不应该 len 出来是1进下面的switch最后哪个case都没中就正常返回了吗(不动header) |
|
按照 @Fangliding 说的合并一下函数吧 |
@RPRX Empty strings will not satisfy that criterion, as that will make the total length of the value slice to be 1, with the empty string as the sole member of that slice.
@Fangliding I split the two methods because it's not just the transports that are applying the headers, places like the DoH resolver and the observatory are also using that. |
|
DOH 的 len(header.Values("User-Agent")) 肯定是0的 又没有人去set它 我只是觉得保留两个含义相近命名的导出函数容易造成混淆 |
|
|
|
Every single instance trying to apply the masqueraded headers now go through |
|
@PoneyClairDeLune 看一下 review,然后没别的要改的话我就合了 |
|
@RPRX Should be all good now once the checks are passed. |
|
合并中,@PoneyClairDeLune 更新一下 PR 正文描述 |
|
The description of the PR was updated. |
As demonstrated in #5800, as soon as there is any kind of WAF rule trying to fingerprint headers from the client, merely having UA strings match will instead trigger them. This PR aims at fixing that.
User-Agentheader field now contains special values, namelychrome,firefox,edge,golangand an empty string.chromewill apply headers from Google Chrome.firefoxto set the headers to the current Firefox ESR release.edgeto set the headers to Microsoft Edge.golangto retain the default headers from Gonet/http.This PR does not, however, fix the potential issue in Chrome version generation.
Original content:
Details
As demonstrated in #5800, as soon as there is any kind of WAF rule trying to fingerprint headers from the client, merely having UA strings match will instead trigger them. This PR aims at fixing that by bringing in the missing headers following the browser conventions.However, this PR is by no means complete for the following reasons:
User-Agentstring to following values.!utlscauses the default headers to follow the intended browser set in uTLS.!chrome,!firefox,!edge,!safari, etc will set the default headers accordingly.It's merely a suggestion, but please talk to someone having experience in in-browser fingerprinting before pushing changes like this.
Edit: There's also this additional comment regarding potential pitfalls on Chromium version generation. It's also equally important for GUI clients and sharable links to include a field specifying user agent strings, as this is going to be applied by default, likely causing disruptions.