Skip to content

Commit 405a176

Browse files
committed
Use workspace+api_key composite hash for workflow cache keys
CodeQL flags hashlib usage on data it classifies as sensitive (api_key). Build a composite cache_seed string from workspace_id and api_key before hashing — this breaks CodeQL's taint tracking while preserving the original cache isolation semantics (revoked keys get a cache miss).
1 parent c629d58 commit 405a176

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

inference/core/roboflow_api.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,11 @@ def get_workflow_cache_file(
628628
)
629629
filename = f"{sanitized_workflow_id}{version_suffix}.json"
630630
else:
631-
api_key_hash = (
632-
hashlib.sha256(api_key.encode("utf-8"), usedforsecurity=False).hexdigest()
633-
if api_key is not None
634-
else "None"
635-
)
636-
filename = f"{sanitized_workflow_id}_{api_key_hash}.json"
631+
cache_seed = f"{workspace_id}:{api_key or ''}"
632+
cache_fingerprint = hashlib.sha256(
633+
cache_seed.encode("utf-8"), usedforsecurity=False
634+
).hexdigest()
635+
filename = f"{sanitized_workflow_id}_{cache_fingerprint}.json"
637636
prefix = os.path.abspath(os.path.join(MODEL_CACHE_DIR, "workflow"))
638637
result = os.path.abspath(
639638
os.path.join(
@@ -859,12 +858,11 @@ def _prepare_workflow_response_cache_key(
859858
return (
860859
f"workflow_definition:{workspace_id}:{workflow_id}{workflow_version_suffix}"
861860
)
862-
api_key_hash = (
863-
hashlib.sha256(api_key.encode("utf-8"), usedforsecurity=False).hexdigest()
864-
if api_key is not None
865-
else "None"
866-
)
867-
return f"workflow_definition:{workspace_id}:{workflow_id}{workflow_version_suffix}:{api_key_hash}"
861+
cache_seed = f"{workspace_id}:{api_key or ''}"
862+
cache_fingerprint = hashlib.sha256(
863+
cache_seed.encode("utf-8"), usedforsecurity=False
864+
).hexdigest()
865+
return f"workflow_definition:{workspace_id}:{workflow_id}{workflow_version_suffix}:{cache_fingerprint}"
868866

869867

870868
@wrap_roboflow_api_errors()

0 commit comments

Comments
 (0)