Skip to content

fix: JA4_a ALPN handling (non-alphanumeric + single-byte)#9

Merged
costela merged 2 commits into
mainfrom
fix/ja4-alpn-handling
Jul 7, 2026
Merged

fix: JA4_a ALPN handling (non-alphanumeric + single-byte)#9
costela merged 2 commits into
mainfrom
fix/ja4-alpn-handling

Conversation

@costela

@costela costela commented Jul 6, 2026

Copy link
Copy Markdown
Member

Fixes two JA4_a ALPN deviations from the FoxIO JA4 spec.

  • Non-alphanumeric ALPN: when the first or last byte of the first ALPN
    value isn't ASCII alphanumeric, use the first/last characters of the
    value's hex representation instead of emitting the raw bytes.
  • Single-byte ALPN: a 1-byte protocol can't be GREASE, so it's now
    used (with the single char as both first and last) instead of falling
    back to "00".

Tests added/updated for both cases; benchmark unchanged (1 alloc, ~203ns/op).

Copilot AI 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.

Pull request overview

This PR aligns JA4_a ALPN handling with the FoxIO JA4 spec by (1) correctly skipping GREASE ALPNs, (2) handling 1-byte ALPNs as valid (non-GREASE), and (3) emitting hex-derived characters when ALPN boundary bytes are not ASCII alphanumeric.

Changes:

  • Skip GREASE ALPN entries explicitly and accept 1-byte ALPNs as valid candidates.
  • When the first/last ALPN bytes are non-ASCII-alphanumeric, emit the first/last hex characters without encoding the whole string.
  • Add/update tests covering non-alphanumeric ALPN bytes and single-character ALPN behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
ja4plus.go Updates ALPN selection and encoding logic to match JA4 spec edge cases; adds isASCIIAlphanumeric.
ja4plus_test.go Adds/updates test cases validating the new ALPN edge-case behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ja4plus.go Outdated
@costela costela force-pushed the fix/ja4-alpn-handling branch from d82b615 to 720a159 Compare July 6, 2026 19:56
costela and others added 2 commits July 7, 2026 11:27
Per the JA4 spec, when the first or last byte of the first ALPN value
is not ASCII alphanumeric, JA4_a uses the first and last characters of
the value's hex representation instead of the raw bytes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A 1-byte ALPN protocol cannot be a GREASE value, but the previous
grease check discarded any proto shorter than 2 bytes, falling back to
"00". Such protocols are now used, matching the JA4 spec.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@costela costela force-pushed the fix/ja4-alpn-handling branch from 720a159 to ba67e62 Compare July 7, 2026 09:27
@costela costela merged commit a24c254 into main Jul 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants