Threat model

The primary threat is indirect prompt injection carried inside untrusted Telegram content: incoming messages, channel posts, captions, forward headers, reply quotes, inline bot cards, and user bios.

Attack vectors and deterministic defenses

Attack scenario How gramcp stops it Refusal code
Exfiltrating private chats to an attacker's handle or group send_whitelist defaults to strict mode (empty); forward_messages checks both source blacklist and destination whitelist atomically. not_whitelisted
Reading a sensitive chat via search, forwards, reply quotes, or alternate IDs (-100..., me, migrated supergroup ID) CanonicalChatId normalizes IDs; chat_migrations pairs upgraded groups; ReadBlacklistGuard strips blocked peers before serialization and redacts reply quotes from blocked parents. read_blacklisted
Username reassignment on a whitelisted peer Live resolve_username verifies the handle still points to the pinned peer_id in SQLite. username_mismatch
Escalating to delete_messages, leave_chat, moderate_member, terminate_session, or stars_action Startup hard_ceiling defaults to read, organize, and send. The /settings panel cannot raise it. hard_ceiling_exceeded
Leaking data through URL previews or inline bot queries get_web_preview and inline_query sit in the send tier: governed by kill switch and audit log; get_web_preview ships off, and inline_query requires the bot in send_whitelist. tool_disabled / not_whitelisted
Reading ~/.ssh or state.db via send_media traversal or symlinks PathSandbox canonicalizes inside outbox_dir, rejects .., sibling-prefix paths, and escaping symlinks, opens with O_NOFOLLOW, and hides existence outside root behind path_forbidden. path_forbidden
Suppressing the — Sent by AI footer via unclosed tags or mid-text [nosig] Signature appends after body UTF-16 entities finalize; opt_out_token matches only at the trailing end (and can be disabled in /settings). Handled structurally
Flooding whitelisted chats or resetting limits across restarts SQLite rolling 1-hour buckets (60/hr global, 20/hr per chat) count every message and disarm rollback once MTProto dispatch starts. rate_limit_exceeded
Cross-account pivot from a low-trust account to a personal account No stateful switch_account tool; calls pass account explicitly or use a pinned /mcp/<alias> endpoint with isolated OAuth scopes. invalid_input / 403

Refusal codes (_meta.reason)

Policy refusals return MCP CallToolResult with isError: true, a readable explanation, and a machine-readable code in _meta.reason:

Code Meaning
unknown_toolTool name is not in the 68-tool catalog.
tool_disabledTool is switched off for this account in SQLite settings.
hard_ceiling_exceededTool tier is excluded from startup hard_ceiling.
read_blacklistedTarget chat, sender, forward source, or reply parent is on read_blacklist.
not_whitelistedDestination is not in send_whitelist under strict mode.
username_mismatchA pinned @username now resolves to a different peer ID.
destination_missing, destination_ambiguousTarget could not be resolved to one peer.
path_forbidden, file_not_foundMedia path escapes sandbox or does not exist inside outbox_dir.
length_exceededFormatted text plus signature exceeds 4096 chars (1024 for captions).
rate_limit_exceededRolling hourly global or per-chat message budget is exhausted.
sending_pausedAccount kill switch is active.
safe_delete_violationMessage was not sent by gramcp or is older than safe_delete_window_mins.
audit_failedSQLite audit write failed, so the mutating call was aborted before execution.
flood_wait, upstream_errorTelegram rate-limited or rejected the MTProto RPC.
invalid_input, storage_errorSchema validation failed (unknown fields rejected) or SQLite returned an error.

What gramcp does not stop

Tool-level policy limits what a fooled model can do, not what it can write or claim inside permitted boundaries:

If you whitelist a chat and a poisoned message tricks the model, it can still send a wrong or awkward reply to that allowed chat. Rate limits cap the volume, the — Sent by AI footer flags it to recipients, and audit_log records it, but the text itself is up to the model.

A poisoned message can also distort a summary the model returns to you inside your AI client. And because gramcp connects as a personal account over MTProto, Telegram's own anti-spam controls still apply if you grant broad sending rights.

An attacker who already has shell access to config.toml, state.db, or session.db is inside the host trust boundary and out of scope.

Found a bypass of any in-scope check? Report it privately via GitHub Security Advisories (SECURITY.md).