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.
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>
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>
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>
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
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>
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.
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>
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.
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.
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
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>
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>
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
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
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
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>
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.
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.
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
_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>
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>
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.
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
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.
_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>
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.
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>
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>
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
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
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
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
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.
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
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