@@ -70,23 +70,35 @@ def compare_signature(url: str, body: bytes, signature: str) -> bool:
70
70
if not signature .startswith ("rpc0:" ):
71
71
return False
72
72
73
- # We aren't using the version bits currently.
74
- body = orjson .dumps (orjson .loads (body ))
75
- _ , signature_data = signature .split (":" , 2 )
76
- # TODO: For backward compatibility with the current Seer implementation, allow all signatures
77
- # while we deploy the fix to both services
73
+ if not body :
74
+ logger .error ("Seer RPC signature validation failed: no body" )
75
+ # TODO: For stability and backward compatibility, we are allowing all signatures
76
+ # while we deploy the fix to both services. But we are logging an error if it fails.
77
+ return True
78
+
79
+ try :
80
+ # We aren't using the version bits currently.
81
+ body = orjson .dumps (orjson .loads (body ))
82
+ _ , signature_data = signature .split (":" , 2 )
83
+
84
+ signature_input = body
85
+
86
+ for key in settings .SEER_RPC_SHARED_SECRET :
87
+ computed = hmac .new (key .encode (), signature_input , hashlib .sha256 ).hexdigest ()
88
+ is_valid = hmac .compare_digest (computed .encode (), signature_data .encode ())
89
+ if is_valid :
90
+ logger .info ("Seer RPC signature validated" )
91
+ return True
92
+ except Exception :
93
+ logger .exception ("Seer RPC signature validation failed" )
94
+ return True
95
+
96
+ logger .error ("Seer RPC signature validation failed" )
97
+
98
+ # TODO: For stability and backward compatibility, we are allowing all signatures
99
+ # while we deploy the fix to both services. But we are logging an error if it fails.
78
100
return True
79
101
80
- # signature_input = body
81
-
82
- # for key in settings.SEER_RPC_SHARED_SECRET:
83
- # computed = hmac.new(key.encode(), signature_input, hashlib.sha256).hexdigest()
84
- # is_valid = hmac.compare_digest(computed.encode(), signature_data.encode())
85
- # if is_valid:
86
- # return True
87
-
88
- # return False
89
-
90
102
91
103
@AuthenticationSiloLimit (SiloMode .CONTROL , SiloMode .REGION )
92
104
class SeerRpcSignatureAuthentication (StandardAuthentication ):
0 commit comments