Files
lotherkandClaude Opus 5.5 6fe30f4787 security: the authorization model holds where the model writes the input
A review found the tool classes - the core of the harness - bypassable in
several places where model output was pasted into a shell or trusted as an id.
Each fix below has a test that reproduces the original failure.

No shell for model data
- webfetch put the URL between '...' and ran it through popen: a quote in the
  URL ran any command, from a tool that needed no consent. curl is now exec'd
  with an argv, http(s) only, HTML stripped in C, stderr off the curses screen.
- webfetch is mutate: with read free, "read a key, fetch evil/?k=..." left the
  machine without anybody being asked. websearch stays read (fixed host).
- kids: the parent-approval command got the model's arguments inside '...'
  via system(); they are now "$1". The domain check reads the URL with the
  same parser as the tool (duplicate keys) and refuses user@host URLs.
- delegate: the two copies of the child argv are one (exec_delegate). The ssh
  path exec'd splinter with "ssh" as argv[0]; it now runs ssh and quotes every
  word for the remote shell. A single delegate to a host now really runs there.

Approvals (ack)
- The id was the pid: a late yes stayed on disk and approved the next request
  unseen. Ids are random, requests 0600 with O_EXCL, deleted when answered or
  expired; an answer is refused after expiry; the first answer wins (link(2)).
- An ack dir owned by someone else or writable by others is refused.
- --ack accepted every word but "no" as yes ("nein" approved). Now strict.
- The terminal thread blocked in fgets after a phone answer; it is stoppable.

Secrets
- API key and Telegram token were in curl's argv, readable via ps. src/curl.c
  passes URL and auth headers as a -K config on stdin (transport, telegram,
  tg-ask.sh; its dead eval fallback is gone).
- 'run' and task_start no longer inherit splinter's keys ("run env"). 'run' got
  its own process group, stdin /dev/null and SPLINTER_RUN_TIMEOUT (300 s).

MCP server
- Beyond 127.x it refuses to start without SPLINTER_MCP_TOKEN; connections
  must begin with "AUTH <token>". SIGPIPE ignored, idle connections closed.

Crashes
- task_kill sent kill(-0) - SIGTERM to splinter's own process group - because
  popen gave no pid. Tasks now have a pid and a process group; integer ids work.
- ui: a 3- or 4-byte UTF-8 character overflowed char[2] on every redraw
  (now sp_ui_ascii_char, tested); the scroll offset was taken from one buffer
  and applied to another, reading past its end.

Repo
- The test binaries are no longer tracked (.gitignore already said so).

make check: 23 test binaries, green, also under ASan/UBSan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 20:19:01 +00:00

61 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
#
# tg-ask -- push an approval request to a Telegram chat.
#
# Copyright (c) 2026 Konrad Lother
# SPDX-License-Identifier: BSD-3-Clause
#
# Called by the ack mechanism as one of the channels:
#
# SPLINTER_ACK_CHANNELS="$HOME/.splinter/bin/tg-ask"
#
# It sends and returns; it never waits. The answer comes back through the
# gateway, which is the one reader of that chat and drops the answer file when it
# sees "ok <id>" or "no <id>". Two pollers on one chat would eat each other's
# updates - that is why this script only writes.
#
# SPLINTER_TELEGRAM_TOKEN bot token (else ~/.splinter/telegram.token)
# SPLINTER_ACK_CHAT chat id of the parent
#
set -u
msg="${1:-Zustimmung angefordert}"
token="${SPLINTER_TELEGRAM_TOKEN:-}"
# the same file the gateway reads; the old key_env lookup matched a line that
# splinter.conf does not allow, and fed it to eval
if [ -z "$token" ] && [ -r "${HOME}/.splinter/telegram.token" ]; then
token=$(head -n 1 "${HOME}/.splinter/telegram.token")
fi
chat="${SPLINTER_ACK_CHAT:-}"
if [ -z "$chat" ]; then
echo "tg-ask: SPLINTER_ACK_CHAT is not set" >&2
exit 1
fi
if [ -z "$token" ]; then
echo "tg-ask: no bot token (SPLINTER_TELEGRAM_TOKEN)" >&2
exit 1
fi
# The message carries the id, so the reply can name it.
# The URL carries the token, and argv is readable by every user (ps -ef): curl
# gets the URL as a config on stdin instead. A token has no quotes or
# backslashes; one that does is refused rather than escaped.
case "$token" in
*'"'*|*\\*) echo "tg-ask: the token contains a quote or backslash" >&2; exit 1 ;;
esac
out=$(printf 'url = "https://api.telegram.org/bot%s/sendMessage"\n' "$token" |
curl -sS --max-time 15 \
--data-urlencode "chat_id=${chat}" \
--data-urlencode "text=${msg}" \
-K - 2>&1) || {
echo "tg-ask: curl failed: ${out}" >&2
exit 1
}
case "$out" in
*'"ok":true'*) printf 'tg-ask: sent (%s)\n' "$msg" ;;
*) printf 'tg-ask: telegram rejected: %s\n' "$out" >&2; exit 1 ;;
esac