pingap icon indicating copy to clipboard operation
pingap copied to clipboard

Feature: JA4 TLS client fingerprint as a header variable and log field

Open mehdyhaghy opened this issue 2 months ago • 1 comments

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, for proxy_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 PreTlsProcess hook. It reads the ClientHello from the raw TCP stream, computes JA4, then calls L4Stream::rewind so the TLS handshake reads the same bytes. It reads at most 16 KiB with a short timeout, and always returns Ok(()), 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::set is 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 into ctx.conn. Idle entries are evicted and the map has a size cap. The per-request cost is one lookup and an Arc clone, with no allocation.
  • Config: ja4 = true on a server. It has no effect on non-TLS servers.
  • Deps: none new (sha2, hex, dashmap are 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

  1. Is this feature something you would accept?
  2. Should the parser be a new pingap-ja4 crate or a module inside pingap-proxy?
  3. Is a per-server ja4 option right, or would you prefer a global one?
  4. Are the names $ja4 and {:ja4} fine?

I can open the PR once the direction is agreed.

mehdyhaghy avatar Sep 27 '26 05:09 mehdyhaghy

@mehdyhaghy

This feature is already supported in the latest version.

vicanso avatar Oct 04 '26 11:10 vicanso