fix(fgp): add null-byte separator in HMAC input to prevent concatenation collision

Without a separator, UA='foobar'+AL='' and UA='foo'+AL='bar' produced the same
HMAC input, allowing a token fingerprint to match a different header split.
Fix: use '\x00' as separator between user_agent and accept_lang fields.

Regression test added: test_fgp_no_concatenation_collision (FGP-05).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-06-06 23:03:48 +02:00
co-authored by Claude Sonnet 4.6
parent de622e8004
commit c77b97b6d3
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ def _compute_fgp(user_agent: str, accept_lang: str) -> str:
"""Return 16-char hex fingerprint binding a token to its client context (D-04)."""
return hmac.new(
settings.secret_key.encode(),
(user_agent + accept_lang).encode(),
(user_agent + "\x00" + accept_lang).encode(),
hashlib.sha256,
).hexdigest()[:16]