fix(gateway): fingerprint full auth token in agent cache signature (#3247)
Previously _agent_config_signature() used only the first 8 characters of the API key, which causes false cache hits for JWT/OAuth tokens that share a common prefix (e.g. 'eyJhbGci'). This led to cross-account cache collisions when switching OAuth accounts in multi-user gateway deployments. Replace the 8-char prefix with a SHA-256 hash of the full key so the signature is unique per credential while keeping secrets out of the cache key. Salvaged from PR #3117 by EmpireOperating. Co-authored-by: EmpireOperating <EmpireOperating@users.noreply.github.com>
This commit is contained in:
@@ -4684,10 +4684,18 @@ class GatewayRunner:
|
||||
prompt cache hits.
|
||||
"""
|
||||
import hashlib, json as _j
|
||||
|
||||
# Fingerprint the FULL credential string instead of using a short
|
||||
# prefix. OAuth/JWT-style tokens frequently share a common prefix
|
||||
# (e.g. "eyJhbGci"), which can cause false cache hits across auth
|
||||
# switches if only the first few characters are considered.
|
||||
_api_key = str(runtime.get("api_key", "") or "")
|
||||
_api_key_fingerprint = hashlib.sha256(_api_key.encode()).hexdigest() if _api_key else ""
|
||||
|
||||
blob = _j.dumps(
|
||||
[
|
||||
model,
|
||||
runtime.get("api_key", "")[:8], # first 8 chars only
|
||||
_api_key_fingerprint,
|
||||
runtime.get("base_url", ""),
|
||||
runtime.get("provider", ""),
|
||||
runtime.get("api_mode", ""),
|
||||
|
||||
Reference in New Issue
Block a user