Commit Graph

3703 Commits

Author SHA1 Message Date
alt-glitch
3af473c312 feat: install the module-rename compat finder in every Hermes process
hermes_agent.compat.install() puts a non-strict Finder(MOVES) at the front
of sys.meta_path once per process. It runs from hermes_bootstrap (which
covers the CLI, gateway, TUI gateway, ACP, MCP server, workers and the
plugin host child), from the cron scheduler's __main__, from the two
by-path update entry points, and at the top of the `plugins validate`
probe script. MOVES is empty, so nothing changes yet.

The plugin loader now finds a parent package's folder from the package's
own import spec instead of counting dots in its name, and the bundled
plugin discovery packages build their module and parent names from
__package__. The plugin host child looks up a provider base class under
both its old and current module name.

hermes_agent is added to update-startup-files, and the test fixtures that
copy a minimal checkout now copy hermes_agent too.
2026-11-13 18:45:31 +00:00
Maciej Lisiewski
a982f96cf6 Merge pull request #154489 from NousResearch/sec/148961-a2a-peer-token-fail-closed
fix(a2a): fail closed when A2A_PEER_TOKENS holds no name:token pair; read startup tokens through the profile scope
2026-11-13 17:45:55 +01:00
Maciej Lisiewski
3ab3b20b48 Merge pull request #154503 from NousResearch/sec/126755-a2a-callback-ssrf
fix(a2a): put push callbacks behind the shared SSRF guard
2026-11-13 17:30:19 +01:00
Maciej Lisiewski
342b54fa53 Merge pull request #154614 from NousResearch/sec/46006-no-user-content-at-info
fix(gateway): keep user content and identities out of INFO+ logs (HX017)
2026-11-13 17:17:09 +01:00
Maciej Lisiewski
ce17de1350 docs(a2a): say push callbacks go through the operator's proxy when one is set
Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 16:56:11 +01:00
Maciej Lisiewski
c7e1bafbf0 docs(a2a): say allow_private_urls governs push callbacks
The callback check follows security.allow_private_urls outside literal
loopback; the docstring claimed loopback was localhost-only-mode only and
the security guide did not list A2A callbacks under the setting.

Refs #126755

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 16:56:11 +01:00
Maciej Lisiewski
5d9ba3477f fix(a2a): read only the status of a push callback response
client.post() downloads the whole response body before returning, and the
callback server is the peer's: a 200 with an endless body pinned the push
thread (the RPC reply waits on it) and grew memory without bound, since
the timeout bounds each read, not the total. Stream the POST and leave the
block without reading the body, as the base's urlopen did.

Refs #126755

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 16:56:10 +01:00
Maciej Lisiewski
437bf12ad9 fix(a2a): check and send push callbacks in the adapter's profile scope
The push runs on ThreadingHTTPServer's per-connection threads, which carry
no profile scope, so the shared SSRF guard read the launch profile's
security.allow_private_urls / fake_ip_ranges for every profile's adapter.
Capture the context at construction (it runs inside the profile scope) and
run the pre-check and the POST in a fresh copy of it per push, as
google_chat does.

Refs #126755

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 16:56:10 +01:00
Maciej Lisiewski
7d94f141b7 fix(a2a): put push callbacks behind the shared SSRF guard
is_safe_callback_url compared the host text against private prefixes, so
integer/hex IPv4 literals (http://2852039166/) and DNS names resolving to
metadata or RFC1918 passed; urlopen then followed redirects the check never
saw and re-resolved the name for the socket.

Non-loopback callbacks now go through tools.url_safety: is_safe_url for the
pre-flight (resolves and checks every answer) and create_ssrf_safe_client for
the POST (connect-time re-validation, dials the vetted IP). Redirects are not
followed. Loopback stays allowed only in localhost-only mode, proxy-free.
create_ssrf_safe_client joins the published plugin API next to its async twin.

Fixes #126755
2026-11-13 16:56:09 +01:00
Maciej Lisiewski
5368a403ef fix(a2a): don't claim localhost-only on setup re-run while tokens stay in .env; docs: shared bearer still accepted
Re-running the wizard over a stored A2A_PEER_TOKENS/A2A_BEARER_TOKEN and
saving nothing new printed 'staying localhost-only' although the stored
token stays in effect. The 401 docs line now says a value with no
name:token pair refuses every caller unless A2A_BEARER_TOKEN is set.

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 16:52:06 +01:00
Maciej Lisiewski
7fb94ff974 fix(a2a): setup wizard refuses to save A2A_PEER_TOKENS with no name:token pair
Validates with the runtime's _parse_peer_tokens, so a bare token is caught at
entry instead of surfacing as refuse-every-caller 401s; docs' 401 entry names
the name:token form.
2026-11-13 16:52:06 +01:00
Maciej Lisiewski
80b1cf87ad docs(a2a): state what the _startup_env scope rung adds, not the unreproduced env-scrub theory
The gateway's own os.environ keeps profile .env values (#151468 premise check);
the rung only adds the profile secret scope (.env + external sources) on a miss.

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 16:52:05 +01:00
Teknium
cd582f7e3a fix(a2a): word the malformed-peer-token error by what is still accepted
With a usable shared A2A_BEARER_TOKEN alongside a bare A2A_PEER_TOKENS value,
the bearer still authenticates, so the ERROR now says only the shared token is
accepted instead of claiming every request is refused (review). The A2A_HOST
warning says "no usable" token, which covers the bare-token case too.
2026-11-13 16:52:05 +01:00
Teknium
c1c7d9a430 fix(a2a): refuse every caller when A2A_PEER_TOKENS holds no name:token pair
A bare token (A2A_PEER_TOKENS=vibe_<hex>) parsed to zero pairs, so the
listener read it as "no token configured" and served every request that
reached the port unauthenticated, behind a tunnel included (#148961). The
operator asked for auth, so that state now fails closed: localhost_only()
is False, authenticate() refuses everyone (401), the bind never widens,
and connect() logs one ERROR naming the expected format. The warning-only
log is replaced by that ERROR; the two invariant tests (token in
the profile .env resolves; a bare token fails closed) move to
test_a2a_startup_tokens.py so test_a2a_plugin.py stays under the file cap.
2026-11-13 16:52:05 +01:00
heyseere
f269030a1b fix(a2a): resolve startup tokens through the profile secret scope when the env is scrubbed
A systemd-style launch loads A2A_* credentials into the secret store and
scrubs the secret-named vars from the process env, so _startup_env()'s bare
os.getenv rung saw an empty token at gateway startup: capture() yielded no
peer/bearer tokens, localhost_only() was True, and every inbound request
through a tunnel or reverse proxy was served unauthenticated while the
audit log recorded ip:127.0.0.1 (#148961).

The unscoped rung now goes through the shared get_scoped_secret accessor
with external_fallback — the same startup gate the adapter already uses for
A2A_PORT/A2A_PUBLIC_URL — so a token written to the profile .env by
`hermes gateway setup` (or an external secret source) resolves at startup
even after the env var is gone. A token that exists nowhere still yields ""
: localhost-only stays fail-closed, unchanged.

capture() also warns once when A2A_PEER_TOKENS is set but parses to zero
name:token pairs (e.g. a bare vibe_<hex> value without name:token colons)
— the same silent localhost-only trap, now diagnosable from the log.

Sensitive-verified: the new regression tests fail on the pre-fix code.

Fixes #148961

From ZCode
2026-11-13 16:52:05 +01:00
Maciej Lisiewski
68471c204c Merge pull request #154561 from NousResearch/sec/143370-discord-webhook-bots
fix(gateway): flag bot authors on Discord webhooks, Matrix notices and Slack bot users
2026-11-13 16:43:43 +01:00
Maciej Lisiewski
f3819ddd50 Merge pull request #154560 from NousResearch/sec/143792-slack-connect-identity
fix(slack): resolve Connect event identity against authenticated installs and refuse external-org DMs
2026-11-13 16:29:18 +01:00
Maciej Lisiewski
49f889b66e Merge pull request #154480 from NousResearch/sec/123231-attachments-before-auth
fix(gateway): fetch inbound attachments only for authorized senders
2026-11-13 16:23:29 +01:00
Maciej Lisiewski
edeeb1f9b2 Merge pull request #154606 from NousResearch/sec/147659-refused-provider-dispatch
fix(memory): a refused memory provider's ctx-registered tools fail closed too (#147659)
2026-11-13 16:22:55 +01:00
Maciej Lisiewski
13f0fd8e51 Merge pull request #154512 from NousResearch/sec/126294-media-redirect-ssrf
fix(gateway): re-check every redirect hop for Mattermost and Weixin media downloads
2026-11-13 16:21:27 +01:00
Maciej Lisiewski
6ae0d02652 fix(google_chat): pass the session thread to the attachment auth check
Under multiplex, a thread-scoped route only matches a source carrying the
thread_id (profile_routing.RouteRule.matches); without it the attachment gate
consulted a different profile's pairing store than dispatch. Compute
session_thread_id first (unchanged, still one thread-count increment) and forward it.

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 14:42:38 +01:00
Maciej Lisiewski
f2daec75b9 docs(signal): the attachment gate stops Hermes' copy, not signal-cli's
signal-cli's daemon downloads received attachments into its data dir unless
started with --ignore-attachments (signal-cli(1)); getAttachment returns those
bytes. The gate prevents Hermes' cache copy, the ffmpeg remux and the agent seeing it.

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 14:42:38 +01:00
Maciej Lisiewski
e6bacc010b fix(simplex): /freceive XFTP files only for authorized senders
rcvFileDescrReady and the deferred voice-note path told the daemon to fetch
every sender-chosen XFTP file before the runner's authorization ran, and
auto_accept is on by default, so any stranger could make the host download
files. Gate both on _is_sender_authorized(...) is True, the same rule the
other adapters use; the message still dispatches so deny/pairing runs.

Refs #123231
2026-11-13 14:42:37 +01:00
Maciej Lisiewski
2de02b75a7 fix(mattermost): pass is_bot to the attachment auth check
A bot peer admitted via MATTERMOST_ALLOW_BOTS is authorized on the message
path but got False from the callback (is_bot defaulted), so its attachments
were silently dropped. Compute is_bot once and use it for both.

Refs #123231
2026-11-13 14:42:37 +01:00
Maciej Lisiewski
fe66107bc5 fix(gateway): BlueBubbles, Google Chat and Teams fetch attachments only for authorized senders
Same defect as Mattermost/Signal: each adapter downloaded and cached a sender's
attachments with its own credentials before the runner's authorization ran.
Gate the fetch on the runner-wired _is_sender_authorized, fetching only on an
explicit True; the message still dispatches so the runner can deny or pair.

Refs #123231, #143977
2026-11-13 14:42:37 +01:00
Maciej Lisiewski
b6c74a597c fix(signal): gate attachment fetch on the gateway's auth verdict, failing closed
dm_allow_from is the raw SIGNAL_ALLOWED_USERS ("*" when unset), so it admitted
every stranger on an unset allowlist, missed pairing-approved and
GATEWAY_ALLOWED_USERS senders, and waved through any member of an allowed group.
Use the runner-wired _is_sender_authorized callback, as Mattermost and Buzz do,
and fetch only on an explicit True.

Fixes #143977

Co-authored-by: liuhao1024 <liuhao1024@users.noreply.github.com>
2026-11-13 14:42:37 +01:00
cf3901646
d35d167550 fix(signal): gate attachment download on sender authorization
Signed-off-by: cf3901646 <cf3901646@users.noreply.github.com>
2026-11-13 14:42:36 +01:00
John Paul Soliva
81fea9c913 fix(mattermost): download attachments only for authorized senders, under the media cap
The inbound post handler fetched and cached every attachment (file info plus
body, up to 10 per post) before the runner authorized the sender, so anyone
able to DM the bot spent its token, bandwidth and disk without being on the
allowlist. The body was read with resp.read(), bypassing
gateway.max_inbound_media_bytes, and documents were cached at any size.

Fetch attachments only when the gateway's authorization check returns an
explicit True (the Buzz adapter's rule); the post still dispatches so the
runner applies denial or pairing. Stream the body through
_read_httpx_body_with_limit, which now takes an aiohttp chunk iterator.
2026-11-13 14:42:36 +01:00
Kevin Rajan
26c271d7ea fix(memory): gate subclass-fallback ctx tools on provider claim (#147659)
When register(ctx) adds tools without registering the memory provider, subclass discovery returns the provider but leaves the collector without it. The PR's guard then bypasses the claim and exposes the owning profile's rows. Bind the discovered provider to its collector in both user-dir and entry-point loaders and add a focused multiplex regression.

Builds on c2h5oh's PR #154606.
2026-11-13 14:38:15 +01:00
Maciej Lisiewski
88c55b2fde fix(memory): read a positional is_async from its real register_tool slot 2026-11-13 14:38:15 +01:00
Maciej Lisiewski
9e59334331 fix(memory): gate a memory provider's ctx-registered tools on its instance claim
A provider refused for a profile (claim_instance: another profile already
bound this same instance) was only dropped from that profile's
MemoryManager. Tools its register(ctx) put in the tool registry still
dispatched to the shared instance, so a refused profile's read returned
the owning profile's rows (mnemosyne-hermes 0.7.1's process-wide
singleton). _ProviderCollector.register_tool now wraps the handler so it
refuses any caller whose profile is not the one the instance is bound to.

Fixes #147659
2026-11-13 14:38:15 +01:00
Maciej Lisiewski
a5af509e5a Merge pull request #154499 from NousResearch/sec/nit-154135-bridge-token-off-loop
fix(whatsapp): mint the bridge token off the event loop
2026-11-13 14:11:18 +01:00
Maciej Lisiewski
05a7823198 fix(gateway): keep the vetted first hop of Weixin CDN media off the DNS check
_download_bytes' callers already vet the first URL (is_safe_url for reply
URLs, the CDN allowlist or the operator's cdn_base_url for inbound media),
which is all main did; DNS-checking it again drops every inbound image on a
fake-ip proxy host (198.18.0.0/15). Redirect hops stay checked.

Mattermost's 4xx text fallback now runs after the download loop, outside the
chain timeout, so a late error cannot cancel the post and retry. Drop the
stray trailing blank line in tools/url_safety.py.

Refs #126294

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 14:08:32 +01:00
Maciej Lisiewski
fa94c45670 fix(slack): treat sibling-install members as local; gate DM reaction handoffs
The Connect resolver prefers authorizations[0].team_id, which Slack documents
as "one installation of your app that the event is visible to" — on a gateway
with two installs in one Grid org it can name the sibling install, so the
external-DM and file_shared sharer gates refused members of an authenticated
workspace. An author is foreign only when their T… team is outside every
install. A reaction in a channel handed off to a D… reaction_trigger_target
now also stamps the reactor's team so the external-DM gate can judge it.

Refs #143792

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 14:01:10 +01:00
Kevin Rajan
a5556bd1fe fix(slack): verify file sharer before trusting Connect event team
Slack file_shared events may carry the receiving install as event.team.
Verify the actual sharer's workspace with users.info before treating that
routing hint as the author; otherwise an external-org video DM synthesizes
a host-team message and escapes the external-DM gate (#143792).

Test: file_shared host event.team with foreign users.info is refused.
Credits: original PR author c2h5oh; reporter doudoujay.
2026-11-13 14:01:06 +01:00
Maciej Lisiewski
880a24897a fix(slack): judge reaction-trigger DM turns by the reactor's workspace
The synthetic reaction event stamps the install team and carried no
user_team, so the external-org DM gate in _prefilter_inbound never fired
for reaction_triggers: an allowlisted external user reacting in a DM got
a turn with the refused DM thread hydrated. Resolve the reactor's T… team
via cached users.info (shared with the file_shared sharer lookup) and
stamp it as user_team, so the single prefilter gate covers both synthetic
paths; a reaction handoff target keeps the DM source in scope. Lookup
failure stays the gate's documented empty-author fail-open.

Fixes #143792
2026-11-13 14:01:02 +01:00
Kevin Rajan
ef1a155864 fix(slack): reject unresolvable multi-install events before DM intake
The authenticated-install resolver correctly returns an empty team for
foreign-only events on multi-install gateways, but the prefilter still
accepted those events with an empty scope. Drop them before deduplication
and the external-DM guard; pin the bypass with one regression test.

Salvage for guvengursel's PR #151460. Original report: doudoujay;
production evidence: KCAYAAI; resolver contribution: liuhao1024.
2026-11-13 14:01:01 +01:00
Güven Gürsel
adec8363c3 fix(slack): resolve events against authenticated installs; close file_shared DM re-entry
_event_team_id now collects candidates in Bolt's shared-channel order
(authorizations[0].team_id, envelope team_id, inner event.team) and, when the
authenticated install set (_team_clients) is available, only a candidate
inside it may win: with exactly one authenticated workspace that install wins
outright (a Connect pair collapses even when every Slack field names the
partner org), otherwise empty — a foreign team never scopes a session or a
dedupe id (#143792). Callers without an install set keep the field order.

The DM gate now compares only T… workspace ids (user_team can be an
enterprise E… id), and _handle_slack_file_shared refuses an external-org
file-share DM before building the synthetic host-team message that would
slip past that gate.

Tests: contract rows (foreign envelope + single install, Grid
authorizations-vs-envelope example, multi-install no-match, legacy order),
enterprise user_team fallback, allowlisted-external-user refusal, and the
file_shared DM pair (external refused / host synthesizes).

Co-authored-by: liuhao1024 <liuhao1024@users.noreply.github.com>
2026-11-13 14:00:56 +01:00
liuhao1024
6ccc64092c fix(slack): resolve Connect events to the installing workspace, refuse external-org DMs
In a Slack Connect channel, one external @mention arrives as two same-ts
events (message + app_mention) whose inner event.team differs (sender's
org vs host workspace) while the envelope team_id is the installing
workspace on both. _event_team_id checked the inner event first, so the
dedup key and session scope split across two teams: the user got two
replies and one session was keyed to a workspace the app is not
installed in (#143792). Resolve the envelope first.

External-org users can also DM the bot; refuse those DMs at intake when
the event's sender team does not match the installing workspace,
regardless of allowlists.
2026-11-13 14:00:53 +01:00
Maciej Lisiewski
2ec407fb2c fix(gateway): document notice loop-guard limit, pin flagless webhook is_bot
Matrix docs now say a notice sender gets one reply per exchange under the
bot loop guard's reply_to_reply rule, and how to allow back-and-forth.
The Slack early-auth comment no longer promises a cache hit: the team key
can differ from _drop_bot_sender's. A Discord test pins
SessionSource.is_bot for a webhook post without author.bot.

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 14:00:31 +01:00
Maciej Lisiewski
bfccf86504 fix(qqbot): keep the signed download URL out of the voice STT WARNING
httpx's HTTPStatusError/TransportError text carries the full request URL,
signed query included. Log the exception type and HTTP status at WARNING
and the detail at DEBUG.

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
2026-11-13 13:59:41 +01:00
Maciej Lisiewski
efe69bcc0b fix(qqbot): keep the voice STT failure URL out of WARNING logs
Same class as the attachment[%d] INFO line (#46006): log the URL length at WARNING, the URL prefix at DEBUG.
2026-11-13 13:59:40 +01:00
Kevin Rajan
02ef1204f8 fix(qqbot): omit inbound attachment metadata from INFO logs
One red-on-carrier regression test for QQ C2C attachments; logs still show metadata lengths and keep raw details at DEBUG.
Follow-up to c2h5oh's gateway privacy fix in NousResearch/hermes-agent#154614.
Refs NousResearch/hermes-agent#46006.
2026-11-13 13:59:40 +01:00
Maciej Lisiewski
46e6db2892 fix(gateway): HX017 sees transcripts, user_display and getattr names; persist salt without link()
Extend HX017 to transcript/user_display and getattr(obj, "<name>", ...) and move the five INFO
sites it then flags (Discord/run_voice transcript, Discord mention-only display name, Telegram
approval/clarify first name + choice text) to lengths/ids. The Discord expired-interaction
WARNING logs only the slash verb. Where link() is refused the salt is created with O_EXCL, and
a failed salt read is cached per home so log calls stop retrying file I/O.

Refs #46006
2026-11-13 13:59:40 +01:00
Maciej Lisiewski
62149277bb fix(gateway): salt hash_for_log per install; photon preview label to DEBUG
An unsalted sha256 prefix of a phone number or guessable email is
recoverable from a shared log by hashing candidates. Key the digest with
a 32-byte per-install salt (HERMES_HOME/log_hash_salt, 0600, created
atomically); fall back to a process-random salt so a log call never raises.

Refs #46006
2026-11-13 13:59:40 +01:00
Maciej Lisiewski
53a5c32f18 fix(gateway): keep user content and identities out of INFO+ logs
Gateway and adapter logs reach `hermes debug share` uploads, whose redaction covers
secrets only, so message bodies, subjects, display names, e-mail addresses and the
inbound-message preview were being published verbatim. INFO+ lines now carry lengths,
platform ids or a short `hash_for_log` digest; the raw value moves to DEBUG.

HX017 (scripts/code_health/py_rules_log_content.py) flags INFO+ log calls in gateway/
and plugins/platforms/ whose args are content-named values (text, body, subject,
user_name, display_name, sender_addr, ...). It is name-based on purpose: ids are not
matched, and transport payloads (resp.text, error_text) are skipped. Every existing
hit is fixed or waived with a reason, none baselined. Policy documented in
gateway/AGENTS.md and ADDING_A_PLATFORM.md.

Refs #46006
2026-11-13 13:59:39 +01:00
Maciej Lisiewski
a5093daff3 fix(slack): resolve early-auth bot verdict via the cached probe helper
Reading _user_is_bot_cache directly broke adapters built without
__init__ (test_slack_mention fixtures) and diverged from the probe
condition _drop_bot_sender uses. Call _resolve_user_is_bot under the
same client_msg_id condition; it is a cache hit for the same event.

Refs #143370
2026-11-13 13:57:49 +01:00
Kevin Rajan
f3e0efd915 fix(slack): carry cached bot identity through early authorization
Avoid rejecting users.info-detected bot peers as unlisted humans before
SLACK_ALLOW_BOTS can apply. Preserve the cached bot verdict at the early
authorization seam and pin the bot-only grant with a regression test.

PR #154561 by c2h5oh; issue #143370.
2026-11-13 13:57:49 +01:00
Maciej Lisiewski
bbfcf16ec5 fix(matrix): keep m.notice bot flag narrowing-only, drop MATRIX_ALLOW_BOTS
msgtype is chosen by the sender, so any Matrix user (federated strangers in
DMs included) can send m.notice. With MATRIX_ALLOW_BOTS=mentions|all and
process_notices on, that let an unlisted sender skip MATRIX_ALLOWED_USERS,
and 'mentions' was never enforced by the Matrix adapter anyway.

Keep m.notice -> is_bot (loop guard, no pairing reply), but don't declare
allow_bots_env until Matrix has an unspoofable bot identity; notice senders
still need a human rung.

Refs #143370
2026-11-13 13:57:48 +01:00
Maciej Lisiewski
a662a925c7 fix(slack): flag users.info-detected peer bots on the session source
A peer agent posting as a bot user (no bot_id/subtype/app_id markers) was
recognised as a bot by the drop gates via the cached users.info verdict,
but the SessionSource only used the payload markers, so under
allow_bots=mentions|all it reached the gateway as a person: the bot loop
guard never counted it. Reuse the same cached verdict for is_bot.

Also document that processed Matrix notices are flagged as bots.

Refs #143370
2026-11-13 13:57:48 +01:00