Registry Mirror
Skip to content

Conversation

@mgkvibez

@mgkvibez mgkvibez commented Nov 7, 2026

Copy link
Copy Markdown

Closes #435, scoped to what you described: opt-in, off by default, ClientHello only via a pluggable dialer in buildTransport, with the h2 mismatch as a documented gap.

What it does. -fingerprint chrome (or firefox, safari, edge, ios, android) drives the outbound TLS handshake through uTLS so the ClientHello matches the profile. With no flag, buildTransport is untouched and behaviour is identical for every scanner.

Where the seam is. One dialer composed into buildTransport, as mapped on the issue. The socks5 branch now feeds the same dial function the TLS layer wraps, so proxying and fingerprinting compose instead of competing.

Two decisions I made rather than leaving implicit.

An http/https proxy plus a fingerprint is refused at startup. That proxy performs the origin handshake itself from tls.Config, where DialTLSContext is never consulted, so the flag would be a silent no-op: the user would believe the hello changed when it did not. socks5 is the supported combination.

An unknown profile is a startup error, not a warning. Every other bad HTTP option warns and continues, which is right for a proxy that might be transient, but a mistyped profile would run a whole scan with Go's hello while the command line claimed otherwise.

The gap, stated plainly. net/http only negotiates h2 when it performs the handshake, so taking it over forces HTTP/1.1. A Chrome hello over HTTP/1.1 is a real match on the hello and a real mismatch on anything that fingerprints h2 behaviour (SETTINGS ordering, WINDOW_UPDATE, priority frames). That is written into the flag help, docs/usage.md, and the comment on buildTransport so nobody discovers it by surprise.

Verification. Five unit tests in internal/httpx/fingerprint_test.go: off-by-default leaves DialTLSContext nil and h2 attempted; a set fingerprint installs the dialer, clears both h2 switches and TLSNextProto; the http-proxy refusal names the working alternative; profile names resolve and unknown ones fail; Configure fails before installing a half-built transport. Plus one real handshake against an httptest TLS server, which I confirmed bites by disabling the uTLS dialer and watching it fail. go build ./..., go vet and both affected packages are clean; go mod tidy promotes uTLS from indirect to direct.

I could not exercise the CLI end to end here: the binary hangs without a TTY in my sandbox even with no flags, and the control run does the same, so it says nothing about this change. The flag parses, -h lists it, and the wiring is three lines into the existing Configure call.

Happy to drop the fingerprint-plus-proxy refusal if you would rather warn than fail.

Adds -fingerprint, which drives the outbound TLS handshake through uTLS so the
ClientHello matches a browser profile. Off by default: with no flag the
transport is untouched and every scanner keeps the existing behaviour.

The seam is buildTransport, which is where the plan in vmfunc#435 pointed: one dialer,
composed rather than replacing the proxy path. socks5 keeps working because the
TLS layer wraps the proxy's dialer instead of racing it, and an http(s) proxy is
refused when a fingerprint is set, since that proxy performs the origin
handshake from tls.Config where DialTLSContext is never consulted - the flag
would otherwise be a silent no-op.

Known gap, documented in the flag, the doc page and the code: this is the hello
only. net/http negotiates h2 only when it performs the handshake itself, so
taking it over forces HTTP/1.1, and a full browser-coherent JA4 plus h2 (correct
SETTINGS, WINDOW_UPDATE, priority frames) is deliberately out of scope. A target
that fingerprints on h2 behaviour will still see a mismatch.

uTLS was already an indirect dependency; this promotes it to direct, go mod tidy
included. Behaviour is covered by four unit tests plus one real handshake against
a TLS server, which fails if the uTLS dialer is disabled.
@mgkvibez
mgkvibez requested a review from vmfunc as a code owner November 7, 2026 19:31
@github-actions github-actions Bot added size/l <500 lines changed docs documentation changes tests test changes config configuration changes deps dependency updates labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

pr summary

8 files changed (+368 -29)

category files
go source 6
tests 2
deps 1

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. It's scoped the way #435 asked: opt-in, off by default, one dialer seam in buildTransport, and the h2 gap is documented. The no-flag path looks unchanged to me, and refusing an http/https proxy combined with an unknown profile is a reasonable call.

CI / verification status

  • On head a62b21a, only ci-summary, size and label have run. The required workflows (lint, build-and-test, build (1.26)) haven't run, most likely because a maintainer still has to approve workflows for a fork/first-time contributor. That isn't a failure in the PR.
  • I couldn't run go build ./..., go vet ./... or go test ./... locally for this review because my sandbox has no Go 1.26 toolchain and can't download one. Everything below comes from reading the code, so please treat the uTLS ALPN point as something to confirm with the test I suggest.

Main concern (correctness): ALPN may still advertise h2
With a non-custom ClientHelloID such as HelloChrome_Auto, uTLS builds the hello from the preset spec. My understanding is that its ALPNExtension writes the spec's protocols (h2, http/1.1) into the config when the preset is applied, which would override cfg.NextProtos = []string{"http/1.1"}. If so, any h2-capable server (most CDNs) will pick h2. The transport would then send HTTP/1.1 on an h2 connection, because it only consults TLSNextProto for a *tls.Conn, and *utls.UConn isn't one. That would break most real HTTPS targets whenever -fingerprint is set.

The current handshake test can't catch this: httptest.NewTLSServer advertises only http/1.1 unless EnableHTTP2 is set. Please see the inline comments for a test that would fail, and for possible fixes.

Other items

  • HTTPS_PROXY/HTTP_PROXY from the environment get around the http-proxy refusal (inline comment).
  • The case-insensitivity test passes a lowercase value (inline comment).
  • Minor: the copied tls.Config only carries RootCAs, InsecureSkipVerify, Min/MaxVersion and CipherSuites. That's fine today because nothing else sets TLSClientConfig. If you keep it, a short comment saying the other fields are deliberately dropped would help.

Not merging. This needs the required CI to run and a maintainer approval.

Written by Devin

// Advertise http/1.1 only, matching the transport. Advertising h2 here
// without then sending h2 SETTINGS frames would make the handshake
// claim something the connection cannot do.
cfg.NextProtos = []string{"http/1.1"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this has no effect for the *_Auto presets. When uTLS applies a preset, the spec's ALPNExtension (h2, http/1.1 for Chrome/Firefox/Edge/Safari) overwrites config.NextProtos, so the hello still offers h2. Two possible fixes:

  1. Build the spec yourself and rewrite ALPN before applying it: spec, _ := utls.UTLSIdToSpec(id), find the *utls.ALPNExtension, set AlpnProtocols = []string{"http/1.1"}, then utls.UClient(raw, cfg, utls.HelloCustom) and conn.ApplyPreset(&spec). This keeps the rest of the fingerprint and only changes ALPN, which a JA4 hash will show, so document it.
  2. Keep the hello as it is, then after the handshake check conn.ConnectionState().NegotiatedProtocol. If it's h2, close the connection and return a clear error. Otherwise hand it to an http2.Transport (golang.org/x/net/http2 is already a dependency) and drop the HTTP/1.1-only restriction.

At minimum, the dialer should refuse to return a connection where NegotiatedProtocol == "h2", because that connection will fail later with a confusing error.

// and a completed uTLS handshake on the other end. If uTLS cannot drive the
// connection this fails rather than erroring somewhere quiet.
func TestFingerprintHandshakeReachesServer(t *testing.T) {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

httptest.NewTLSServer only advertises http/1.1, so this test passes whatever the client offers in ALPN. Please add a variant that more closely matches real targets:

srv := httptest.NewUnstartedServer(handler)
srv.EnableHTTP2 = true
srv.StartTLS()

and assert the request succeeds over HTTP/1.1. I expect it to fail with the current dialer, as described on fingerprint.go:99.

}
}
if _, err := clientHelloID("chrome"); err != nil {
t.Errorf("matching should be case-insensitive: %v", err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This passes "chrome" in lowercase, so it doesn't test case-insensitivity. It should be something like clientHelloID(" Chrome ") to cover both ToLower and TrimSpace.

Comment thread internal/httpx/httpx.go
return nil, fmt.Errorf("unsupported proxy scheme %q (want http/https/socks5)", parsed.Scheme)
}

if fingerprint != "" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When -proxy is empty, transport.Proxy is still http.ProxyFromEnvironment, inherited from the DefaultTransport clone. If HTTPS_PROXY is set, net/http dials the proxy, sends CONNECT and does the origin handshake itself from TLSClientConfig, skipping DialTLSContext. That's the same silent no-op this PR refuses for -proxy http://....

For consistency, either set transport.Proxy = nil when fingerprinting with no explicit proxy (and document that env proxies are ignored), or fail at startup when http.ProxyFromEnvironment would return a proxy for https. A unit test using t.Setenv("HTTPS_PROXY", ...) would pin down whichever you choose.

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

Labels

config configuration changes deps dependency updates docs documentation changes size/l <500 lines changed tests test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tls fingerprint impersonation for requests

1 participant