Feature: JA4 TLS client fingerprint as a header variable and log field
Summary
Add JA4 TLS client fingerprinting. For each TLS connection, Pingap would compute the JA4 fingerprint of the ClientHello and expose it as:
- a header variable,
$ja4, forproxy_set_headers/proxy_add_headers - an access log field,
{:ja4}
It only observes and never blocks a request. It is off by default and works with both OpenSSL and rustls builds.
Why
JA4 identifies the client's TLS stack, not the User-Agent it claims. A script that sends a browser User-Agent through Python, Go or curl still has a non-browser fingerprint. Users can forward the value to their backend or log it for bot detection and analytics. Today the only way to get it is a packet sniffer running next to the proxy.
Proposed design
- Capture: implement Pingora 0.9.0's
PreTlsProcesshook. It reads the ClientHello from the raw TCP stream, computes JA4, then callsL4Stream::rewindso the TLS handshake reads the same bytes. It reads at most 16 KiB with a short timeout, and always returnsOk(()), so it can never fail or change a handshake. - Pass to the request: Pingora has no per-connection slot the hook can write to (
SslDigestExtension::setis crate-private). So the hook stores the value in a small map keyed by(local_addr, peer_addr), and the request looks it up once when it copies TLS details intoctx.conn. Idle entries are evicted and the map has a size cap. The per-request cost is one lookup and anArcclone, with no allocation. - Config:
ja4 = trueon a server. It has no effect on non-TLS servers. - Deps: none new (
sha2,hex,dashmapare already in the workspace).
[servers.https]
addr = "0.0.0.0:443"
ja4 = true
[locations.api]
upstream = "backend"
proxy_set_headers = ["X-JA4:$ja4"]
Scope
- Only JA4 for TLS over TCP. It is published under BSD-3-Clause. Written from the format description, with no third-party code or test data copied.
- Not included: blocking or rate limiting by fingerprint, the other JA4+ methods (non-commercial license), JA3, QUIC.
- Includes tests (unit, both TLS backends, handshake safety, fuzzing), the admin UI field, and English and Chinese docs.
Questions
- Is this feature something you would accept?
- Should the parser be a new
pingap-ja4crate or a module insidepingap-proxy? - Is a per-server
ja4option right, or would you prefer a global one? - Are the names
$ja4and{:ja4}fine?
I can open the PR once the direction is agreed.
@mehdyhaghy
This feature is already supported in the latest version.