Files
loki/scripts
CatoandClaude Opus 5 6be463cd3f fix(telegram): the self-only allowlist was a caller obligation nobody performed (#519)
sendTelegramMessage's docblock said "the caller is responsible for the self-only
allowlist check BEFORE calling this". Eight call sites, zero checks —
isAllowedTelegramTarget had no caller anywhere in the repo.

Nothing leaked, and that is the uncomfortable part: it held only because every
call site happens to pass selfTelegramTarget(). The blast radius the guard was
written to bound was bounded by coincidence instead. The first flow that lets a
recipient be requested — a Loki action, an operator-typed target — would have
inherited an unguarded send to an arbitrary chat, with a docblock saying someone
else had already checked.

The guard now runs inside the send. An empty chatId resolves to the operator's
own chat, which is what isAllowedTelegramTarget has always meant by "empty =>
default to self", and with no chat id configured every send is refused rather
than guessed at. No behaviour change for the eight existing callers, verified
one by one: all pass selfTelegramTarget().

scripts/test/telegram-allowlist.ts — 15 assertions, in the unit suite by
discovery (139/139). Both configurations run in child processes with their own
env, the shape activity-time-zone-stable.ts already uses and for the same
reason: tsx compiles to CJS and cannot `await import`. TELEGRAM_BOT_TOKEN is
left unset on purpose, so a send that REACHES the transport fails on the missing
token — that is what separates "refused by the allowlist" from "attempted", and
the mutation shows it: removing the guard turns both refusals into
"no TELEGRAM_BOT_TOKEN configured".

TWO THINGS THE TEST CAUGHT IN ITSELF.

The first version silently tested the wrong path. It set TELEGRAM_CHAT_ID, but
the constant is envAlias("TELEGRAM_CHAT_ID"), which reads APP_ / FLEETCROWN_ /
COCKPIT_ prefixed names and never the bare one — so the "configured" probe was
exercising the UNCONFIGURED path. Five assertions failed and that is how it was
found; a test asserting only refusals would have passed while proving nothing.

The module's own comment was wrong for the same reason ("Sourced from
TELEGRAM_CHAT_ID (env, via constants)"). Corrected to name the real keys, since
setting the bare name configures nothing and looks like it worked.

isAllowedTelegramTarget removed from the dead-export ratchet BASELINE. 12 -> 3.

verify green (13 steps, exit 0, 139/139 unit files).


Claude-Session: https://claude.ai/code/session_01UvjGNAS9CMfEGNW26tUR4P

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 12:03:30 +00:00
..
2026-08-31 09:23:30 +00:00
…
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
…
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00