forked from kenzuya/unshackle
fix(remote): harden serve API access control and input handling
Bind sessions and download jobs to the API key (not source IP), reject path-traversal cache keys, bound decompression of peer-supplied blobs, gate the CDM device before the vault fallback, and compare API keys in constant time.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import hmac
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
@@ -135,7 +136,9 @@ def serve(
|
||||
secret_key = request.headers.get("X-Secret-Key")
|
||||
if not secret_key:
|
||||
return web.json_response({"status": 401, "message": "Secret Key is Empty."}, status=401)
|
||||
if secret_key not in request.app["config"]["users"]:
|
||||
# Constant-time compare against every configured key so a valid key can't be
|
||||
# recovered byte-by-byte from response timing.
|
||||
if not any(hmac.compare_digest(secret_key, k) for k in request.app["config"]["users"]):
|
||||
return web.json_response({"status": 401, "message": "Secret Key is Invalid."}, status=401)
|
||||
return await handler(request)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user