Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gateway/platforms/wecom_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import base64
import hashlib
import hmac
import os
import secrets
import socket
Expand Down Expand Up @@ -87,7 +88,12 @@ def verify_url(self, msg_signature: str, timestamp: str, nonce: str, echostr: st

def decrypt(self, msg_signature: str, timestamp: str, nonce: str, encrypt: str) -> bytes:
expected = _sha1_signature(self.token, timestamp, nonce, encrypt)
if expected != msg_signature:
# Constant-time comparison to avoid a timing side-channel on the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current main no longer tracks this path: commit 5600105478ffde29d7566b45421b100eaa29c4ef moved the active implementation to plugins/platforms/wecom/wecom_crypto.py, where the unsafe comparison still exists. Please retarget this change there.

# callback signature. Consistent with hmac.compare_digest used in
# webhook.py and api_server.py for the same purpose.
if not isinstance(msg_signature, str) or not hmac.compare_digest(
expected, msg_signature
):
raise SignatureError("signature mismatch")
try:
cipher_text = base64.b64decode(encrypt)
Expand Down