Let Hermes' gateway reach only a Matrix server you've allowed
sandbox/setup.sh allowed Hermes' gateway the host in MATRIX_HOMESERVER from ~/.hermes/.env, which Hermes can write from inside its sandbox. On the next update, Hermes could have opened the way out to any host it chose. The allowed server is now in ~/.config/coredesktop/sandbox/hermes.json, which no sandbox can write. configure hermes is to do while Hermes names a server you haven't allowed, and asks about only that; update says so. Only a plain host name counts, so it can't be a wildcard or carry escape codes into the question. A migration carries over the server the gateway's systemd drop-in allows now, so a working gateway keeps working. sandbox/agent no longer takes domains from COREDESKTOP_SANDBOX_DOMAINS, which nothing else used. The security checks skill now records step 3 as done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+3
-6
@@ -11,9 +11,7 @@
|
||||
#
|
||||
# The config is sandbox/config/base.json, then sandbox/config/<agent>.json,
|
||||
# then your own ~/.config/coredesktop/sandbox/base.json and <agent>.json, in
|
||||
# the same format. Later files add to the lists in earlier ones. Domains in
|
||||
# COREDESKTOP_SANDBOX_DOMAINS (space-separated) are allowed too; setup.sh uses
|
||||
# it for Hermes' gateway, whose messaging server differs on each machine.
|
||||
# the same format. Later files add to the lists in earlier ones.
|
||||
|
||||
# Wrapped in { ...; exit; } so bash reads the whole script up front; update
|
||||
# replaces this file (git pull) while agents are running.
|
||||
@@ -114,9 +112,8 @@ done
|
||||
|
||||
# Outside the sandbox's writable paths, so the agent can't change its own rules
|
||||
settings="$SETTINGS_DIR/$agent.$$.json"
|
||||
if ! jq -s --arg domains "$COREDESKTOP_SANDBOX_DOMAINS" --arg socket "$gui_socket" \
|
||||
"$MERGE"' | .network.allowedDomains += ($domains | split(" ") | map(select(. != "")))
|
||||
| if $socket != "" then .filesystem.allowRead += [$socket] else . end' \
|
||||
if ! jq -s --arg socket "$gui_socket" \
|
||||
"$MERGE"' | if $socket != "" then .filesystem.allowRead += [$socket] else . end' \
|
||||
"${configs[@]}" > "$settings"; then
|
||||
echo "Couldn't read the sandbox config: ${configs[*]}"
|
||||
exit 1
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : The Matrix server Hermes' gateway talks to, and whether you've let
|
||||
# its sandbox reach it. Source this file; used by sandbox/setup.sh,
|
||||
# configure hermes and a migration.
|
||||
#
|
||||
# Hermes' settings (~/.hermes/.env) name the server, but Hermes can change them
|
||||
# from inside its sandbox, so they say only what Hermes wants to reach. The
|
||||
# server it may reach is in your own hermes.json, which no sandbox can write;
|
||||
# configure hermes asks you before adding it there.
|
||||
|
||||
HERMES_ENV="$HOME/.hermes/.env"
|
||||
HERMES_SANDBOX_CONF="$HOME/.config/coredesktop/sandbox/hermes.json"
|
||||
|
||||
# The host in MATRIX_HOMESERVER, e.g. matrix.example.org, or nothing. Only a
|
||||
# plain host name or IPv4 address counts, so it can't be a wildcard or carry
|
||||
# characters that would change what a terminal shows when it's asked about.
|
||||
hermes_homeserver() {
|
||||
local host
|
||||
host="$(sed -nE "s#^MATRIX_HOMESERVER=[\"']?https?://([^/:\"']+).*#\1#p" "$HERMES_ENV" 2> /dev/null | head -n 1)"
|
||||
[[ "$host" =~ ^[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?$ ]] && echo "$host"
|
||||
}
|
||||
|
||||
# hermes_homeserver_allowed HOST: true if Hermes' sandbox may reach HOST
|
||||
hermes_homeserver_allowed() {
|
||||
[ -n "$1" ] && jq -e --arg host "$1" '(.network.allowedDomains // []) | index($host) != null' \
|
||||
"$HERMES_SANDBOX_CONF" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# hermes_allow_homeserver HOST: let Hermes' sandbox reach HOST
|
||||
hermes_allow_homeserver() {
|
||||
source "${COREDESKTOP:-$HOME/.local/share/coredesktop}/configure.d/lib/json.sh"
|
||||
edit_json "$HERMES_SANDBOX_CONF" '{}' --arg host "$1" \
|
||||
'.network.allowedDomains = ((.network.allowedDomains // []) - [$host] + [$host])'
|
||||
}
|
||||
+9
-4
@@ -5,7 +5,7 @@
|
||||
# Claude Code's built-in sandbox. Run by install.sh and on every
|
||||
# update (updates.d/72-sandbox.sh).
|
||||
|
||||
COREDESKTOP="$HOME/.local/share/coredesktop"
|
||||
COREDESKTOP="${COREDESKTOP:-$HOME/.local/share/coredesktop}"
|
||||
STATUS=0
|
||||
|
||||
# npm's global prefix is under /usr, so install to ~/.local; srt lands in ~/.local/bin.
|
||||
@@ -66,18 +66,18 @@ fi
|
||||
# Hermes' gateway acts on messages from outside this machine, so it runs in
|
||||
# the sandbox too: a systemd drop-in starts it through sandbox/bin/hermes. It
|
||||
# also needs to reach the Matrix server in Hermes' settings, which differs on
|
||||
# each machine; for other messaging services, add their domains to
|
||||
# each machine. Hermes can change those settings itself, so the server isn't
|
||||
# allowed from them; configure hermes asks you (see sandbox/hermes-homeserver.sh).
|
||||
# For other messaging services, add their domains to
|
||||
# ~/.config/coredesktop/sandbox/hermes.json.
|
||||
GATEWAY_UNIT="$HOME/.config/systemd/user/hermes-gateway.service"
|
||||
if [ -f "$GATEWAY_UNIT" ]; then
|
||||
if [ -x "$HOME/.local/bin/srt" ]; then
|
||||
homeserver="$(sed -nE "s#^MATRIX_HOMESERVER=[\"']?https?://([^/:\"']+).*#\1#p" "$HOME/.hermes/.env" 2> /dev/null | head -n 1)"
|
||||
dropin="$GATEWAY_UNIT.d/coredesktop-sandbox.conf"
|
||||
tmp="$(mktemp)"
|
||||
cat > "$tmp" << EOF
|
||||
# Written by CoreDesktop (sandbox/setup.sh): run Hermes' gateway in the sandbox
|
||||
[Service]
|
||||
Environment="COREDESKTOP_SANDBOX_DOMAINS=$homeserver"
|
||||
ExecStart=
|
||||
ExecStart=%h/.local/share/coredesktop/sandbox/bin/hermes gateway run
|
||||
EOF
|
||||
@@ -88,6 +88,11 @@ EOF
|
||||
mkdir -p "$(dirname "$dropin")" && mv -f "$tmp" "$dropin" && chmod 644 "$dropin" \
|
||||
&& systemctl --user daemon-reload || STATUS=1
|
||||
fi
|
||||
source "$COREDESKTOP/sandbox/hermes-homeserver.sh"
|
||||
homeserver="$(hermes_homeserver)"
|
||||
if [ -n "$homeserver" ] && ! hermes_homeserver_allowed "$homeserver"; then
|
||||
echo "Hermes' settings name the Matrix server $homeserver, which its gateway can't reach until you allow it: configure hermes"
|
||||
fi
|
||||
else
|
||||
echo "Hermes' gateway isn't sandboxed yet: the sandbox (srt) isn't installed."
|
||||
STATUS=1
|
||||
|
||||
Reference in New Issue
Block a user