mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-21 16:18:55 +00:00
fix(security): widen non-ASCII compare_digest crash fix to all sibling sites
Same bug class as the salvaged #65305/#65307: hmac.compare_digest (and secrets.compare_digest) raise TypeError when given a str containing non-ASCII characters, and these call sites feed it raw request input. Compare as UTF-8 bytes everywhere: - gateway/platforms/msgraph_webhook.py: clientState from request body - gateway/platforms/whatsapp_cloud.py: hub.verify_token query param + X-Hub-Signature-256 header (comment claimed 'works on str' — it doesn't for non-ASCII) - plugins/platforms/feishu: verification token + x-lark-signature - plugins/platforms/raft: bridge token header - plugins/platforms/line: X-Line-Signature - plugins/platforms/sms: X-Twilio-Signature - tools/code_execution_tool.py: sandbox RPC token (both loops) Regression tests for the two gateway-core sites (msgraph, whatsapp).
This commit is contained in:
parent
4ccb232af9
commit
a6d9d1d2cf
9 changed files with 76 additions and 13 deletions
|
|
@ -596,7 +596,10 @@ def _rpc_server_loop(
|
|||
continue
|
||||
|
||||
if not rpc_token or not secrets.compare_digest(
|
||||
str(request.get("token") or ""), rpc_token
|
||||
# Compare as bytes: compare_digest raises TypeError on a
|
||||
# str with non-ASCII characters, and the token comes from
|
||||
# sandbox-script-supplied JSON.
|
||||
str(request.get("token") or "").encode(), rpc_token.encode()
|
||||
):
|
||||
resp = json.dumps({"error": "Unauthorized RPC request"})
|
||||
conn.sendall((resp + "\n").encode())
|
||||
|
|
@ -881,7 +884,10 @@ def _rpc_poll_loop(
|
|||
continue
|
||||
|
||||
if not rpc_token or not secrets.compare_digest(
|
||||
str(request.get("token") or ""), rpc_token
|
||||
# Compare as bytes: compare_digest raises TypeError on a
|
||||
# str with non-ASCII characters, and the token comes from
|
||||
# sandbox-script-supplied JSON.
|
||||
str(request.get("token") or "").encode(), rpc_token.encode()
|
||||
):
|
||||
logger.debug("Unauthorized RPC request in %s", req_file)
|
||||
env.execute(f"rm -f {quoted_req_file}", cwd="/", timeout=5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue