The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(email): warn when a mis-pinned authserv_id drops an admitted sender
kshitijk4poora4dadad7cda1
diff --git a/plugins/platforms/email/adapter.py b/plugins/platforms/email/adapter.pyindex 664e41010e2..653b5ada421 100644--- a/plugins/platforms/email/adapter.py+++ b/plugins/platforms/email/adapter.py@@ -65,6 +65,7 @@ _AUTH_METHOD_RE = re.compile(r"\s*(dmarc|dkim|spf)\s*=\s*([a-z]+)", re.IGNORECAS# Verdict reason when the message carries no Authentication-Results at all: the one failure that points at a mail# server which never stamps the header (the opt-out case), rather than at the message itself._NO_AUTH_RESULTS_REASON = "no Authentication-Results header"+_UNTRUSTED_AUTHSERV_REASON = "no Authentication-Results from trusted authserv-id"# One token of a clause: a property we read (``header.from=x``; the value may be or contain a quoted-string), or# any other whitespace-delimited token consumed whole, so text inside quotes or other values is never read as a prop._QUOTED = r'"(?:[^"\\]|\\.)*"'@@ -351,7 +352,7 @@ def _verify_sender_authentication(msg: email_lib.message.Message, from_addr: strtrusted = next((v for v in values if not authserv_id or (serv := v.split(";", 1)[0].strip().lower()) == authserv_id.lower()or _domains_aligned(serv, authserv_id)), None)if trusted is None:- return False, "no Authentication-Results from trusted authserv-id"+ return False, _UNTRUSTED_AUTHSERV_REASON# Each verdict comes from the head of its own clause (split outside quotes/comments) and its domains only from that# clause: a quoted local part or comment can otherwise smuggle ``spf=pass``/``header.d=`` (GHSA-rxqh-5572-8m77).if (clauses := _ar_clauses(trusted)) is None:@@ -729,7 +730,7 @@ class EmailAdapter(BasePlatformAdapter):# code or decline is mailed back to it; fail-closed. Open access is no exception: the session and every reply# key on From:, so a forged one lands in that address's conversation and makes the agent mail it. Only a granted# sender's mail with no Authentication-Results at all warns, since that suggests a server that never stamps it and- # the opt-out hint fits. An explicit failing verdict (dmarc=fail, misaligned SPF/DKIM, ...) is routine forgery,+ # the opt-out hint fits; so does one whose only stamp is from another authserv-id (a mis-pinned authserv_id). An explicit failing verdict (dmarc=fail, misaligned SPF/DKIM, ...) is routine forgery,# even when From: is an allowlisted address or open access grants everyone; the hint would be wrong advice.if self._require_authenticated_sender and not msg_data.get("sender_authenticated", False):auth_reason = msg_data.get("auth_reason", "no verdict")@@ -737,6 +738,10 @@ class EmailAdapter(BasePlatformAdapter):logger.warning("[Email] Dropping sender with unauthenticated From: %s (%s). If your mail server does not ""stamp Authentication-Results, set platforms.email.require_authenticated_sender: false ""(or EMAIL_TRUST_FROM_HEADER=true) to accept the risk.", sender_addr, auth_reason)+ elif granted and auth_reason == _UNTRUSTED_AUTHSERV_REASON:+ logger.warning("[Email] Dropping sender with unauthenticated From: %s (%s). Check that "+ "platforms.email.authserv_id (EMAIL_AUTHSERV_ID) names your mail server.",+ sender_addr, auth_reason)else:logger.debug("[Email] Dropping %s sender with unauthenticated From: %s (%s)","authorized" if granted else "unknown", sender_addr, auth_reason)diff --git a/tests/gateway/test_email.py b/tests/gateway/test_email.pyindex 8d02cd389b2..5070920210f 100644--- a/tests/gateway/test_email.py+++ b/tests/gateway/test_email.py@@ -378,11 +378,19 @@ class TestDispatchDefersToGatewayAuthorization(unittest.TestCase):def test_only_a_missing_auth_results_header_warns_with_the_opt_out_hint(self):"""A granted sender's mail with no Authentication-Results suggests a server that never stamps it, so the drop- warns with the opt-out hint; an explicit failing verdict is routine forgery and stays at debug."""+ warns with the opt-out hint; a stamp only from another authserv-id warns to check authserv_id; an explicit+ failing verdict is routine forgery and stays at debug."""+ from plugins.platforms.email.adapter import _UNTRUSTED_AUTHSERV_REASON+adapter_log = "plugins.platforms.email.adapter"with self.assertLogs(adapter_log, level="WARNING") as logs:self.assertEqual(self._reached_gateway(authenticated=False, env={"EMAIL_ALLOW_ALL_USERS": "true"}), [])self.assertIn("require_authenticated_sender: false", logs.output[0])+ with self.assertLogs(adapter_log, level="WARNING") as logs:+ self.assertEqual(self._reached_gateway(authenticated=False, auth_reason=_UNTRUSTED_AUTHSERV_REASON,+ env={"EMAIL_ALLOWED_USERS": self.STRANGER}), [])+ self.assertIn("authserv_id", logs.output[0])+ self.assertNotIn("require_authenticated_sender", logs.output[0])for label, env in {"open access": {"EMAIL_ALLOW_ALL_USERS": "true"},"listed sender": {"EMAIL_ALLOWED_USERS": self.STRANGER}}.items():with self.subTest(label), self.assertNoLogs(adapter_log, level="WARNING"):diff --git a/website/docs/user-guide/messaging/email.md b/website/docs/user-guide/messaging/email.mdindex 95980d7cd07..c9ffb197014 100644--- a/website/docs/user-guide/messaging/email.md+++ b/website/docs/user-guide/messaging/email.md@@ -177,7 +177,7 @@ Email access is stricter by default than chat-style platforms:Allowlist entries match whole addresses. A bare entry such as `alice` (a chat username in `GATEWAY_ALLOWED_USERS`, say) never admits `alice@` at any domain, and mail from such an address is dropped rather than paired or declined.-Hermes acts on a message only when the `Authentication-Results` header stamped by your receiving server authenticates its `From:` domain (DMARC, or aligned SPF/DKIM). This applies with open access (`EMAIL_ALLOW_ALL_USERS` / `GATEWAY_ALLOW_ALL_USERS`) too: open access admits any sender, but each conversation and every reply is keyed on `From:`, so a forged `From:` would put the attacker's text into that address's session and make Hermes mail it. Pairing codes and declines likewise need an authenticated `From:`, so neither is mailed to a forged address. If your mail server does not stamp that header, set `platforms.email.require_authenticated_sender: false` (or `EMAIL_TRUST_FROM_HEADER=true`) to accept the risk; otherwise mail from an admitted sender that carries no such header is dropped with a `Dropping sender with unauthenticated From` warning in the gateway log. Mail whose header records a failing verdict (a forged `From:`, say) is dropped quietly, logged at debug level only.+Hermes acts on a message only when the `Authentication-Results` header stamped by your receiving server authenticates its `From:` domain (DMARC, or aligned SPF/DKIM). This applies with open access (`EMAIL_ALLOW_ALL_USERS` / `GATEWAY_ALLOW_ALL_USERS`) too: open access admits any sender, but each conversation and every reply is keyed on `From:`, so a forged `From:` would put the attacker's text into that address's session and make Hermes mail it. Pairing codes and declines likewise need an authenticated `From:`, so neither is mailed to a forged address. If your mail server does not stamp that header, set `platforms.email.require_authenticated_sender: false` (or `EMAIL_TRUST_FROM_HEADER=true`) to accept the risk; otherwise mail from an admitted sender that carries no such header is dropped with a `Dropping sender with unauthenticated From` warning in the gateway log. The same warning, pointing at `platforms.email.authserv_id` (`EMAIL_AUTHSERV_ID`) instead, fires when the only stamp comes from a server other than the pinned `authserv_id`. Mail whose header records a failing verdict (a forged `From:`, say) is dropped quietly, logged at debug level only.:::warning**Use a dedicated inbox and configure `EMAIL_ALLOWED_USERS` for normal operation.** Email pairing is opt-in because shared inboxes often contain unrelated unread messages, and Hermes should not reply to those contacts by default.