Repository navigation
Description
Problem
Bot tokens for external messaging integrations are stored as plaintext in SQLite, violating Architectural Invariant #13 (Credentials: never stored in DB; transient secrets in Redis; encrypted exports use AES-256-GCM).
Confirmed plaintext storage
slack_link_connections.slack_bot_token—TEXT NOT NULL(src/backend/db/schema.py:539,db/migrations.py:537)slack_workspaces.bot_token—TEXT NOT NULL(db/migrations.py:863)telegram_chat_linksbot tokens — plaintext (seeadapters/telegram_adapter.pyanddb.get_telegram_bot_token)
Writes happen in db/slack.py:create_slack_connection and matching Telegram paths without any encryption layer.
Architecture doc is inaccurate
docs/memory/architecture.md claims slack_workspaces stores "encrypted bot tokens (encrypted at application layer)" — this is false and should be corrected as part of this fix.
Impact
Slack/Telegram bot tokens grant full workspace messaging access. A DB leak (backup exfil, SQLite file access, read-only replica exposure) reveals live credentials that can impersonate Trinity agents in user workspaces. Trinity already has an encryption primitive: services/credential_encryption.py (AES-256-GCM, used for .credentials.enc).
Scope
- Encrypt bot tokens at write, decrypt at read for:
slack_link_connections.slack_bot_tokenslack_workspaces.bot_token- Telegram bot token storage (
telegram_chat_linksor equivalent)
- Reuse
services/credential_encryption.py(AES-256-GCM) or add an equivalent helper keyed offSECRET_KEY/ dedicated env var. - Migration strategy for existing rows:
- Option 1: one-shot migration that encrypts in place at startup (needs versioned migration in
db/migrations.py). - Option 2: lazy migration — encrypt on next write, tolerate both formats on read. Simpler but leaves plaintext around until rotation.
- Option 1: one-shot migration that encrypts in place at startup (needs versioned migration in
- Update
docs/memory/architecture.mdto reflect actual state (either correct the "encrypted" claim with the real implementation, or remove it if Option 2 lazy migration).
Acceptance Criteria
- Bot tokens for Slack (both tables) and Telegram are encrypted at rest
- Existing rows migrate cleanly (no service disruption after backend restart)
- Tests cover: create → read round-trip, decryption failure handling, legacy plaintext row migration (if one-shot approach)
-
architecture.mdcredentials section is accurate -
/validate-architectureno longer flagsslack_bot_tokenunder Invariant feat: SMARTS trading pipeline with Telegram notifications and Miro visualization #13
References
- Parent issue: Architecture Validation: 4 critical violations found (2026-04-22) #447 (automated architecture validation, 2026-04-22)
- Invariant feat: SMARTS trading pipeline with Telegram notifications and Miro visualization #13: @docs/memory/architecture.md#architectural-invariants
- Existing encryption primitive:
src/backend/services/credential_encryption.py
Activity
pavshulin commentedon May 5, 2026
/claim
github-actions commentedon May 5, 2026
Claimed by @pavshulin. Label
status-in-progressadded.Next steps:
feature/453-<short-slug>Fixes #453pavshulin commentedon May 5, 2026
Implementation status — PR #667
PR #667 is open against
devand will close this issue on merge.Scope refinement vs. the original issue body
The issue body listed three plaintext storage sites; investigation reduced this to one site needing new code plus one site needing a backfill migration:
slack_link_connections.slack_bot_tokenplaintextdb/slack.py+ one-shot migrationslack_workspaces.bot_tokenplaintexttelegram_chat_linksbot tokens plaintexttelegram_bindings.bot_token_encrypted, already AES-256-GCM via the same primitiveArchitecture doc said
slack_workspaces.bot_tokenwas "encrypted at application layer" — that was only half-true (encrypt-on-write was correct; the legacy backfill claim was aspirational). The migration in this PR makes it true at the row level.Acceptance criteria
schema_migrationsrowslack_bot_token_encryptionapplied 2026-05-05; both DB rows now JSON envelopesarchitecture.mdInvariant fix: Add ARM64 Alpine compatibility for frontend Docker build #12 reworded to acknowledge channel/subscription tokens as a documented encryption exception (not a "never stored" claim that was already false)slack_link_connectionsDDL andslack_workspacesDDL annotated with the encrypted-JSON-envelope-in-TEXT-column contractNote on invariant numbering
Issue title says "Invariant #13"; current
architecture.mdnumbers this rule as #12. The PR description and updated docs use #12.Follow-up
Encryption test backfill for
db/slack_channels.py(SLACK-002),db/telegram_channels.py, anddb/whatsapp_channels.pyis tracked separately in #664 — they all shipped without dedicated test coverage and adding it retroactively is a clean hygiene ticket separate from this security fix.fix(security): Encrypt Slack bot tokens at rest (#453)
docs(req): annotate SLACK-001 bot token as encrypted at rest (#453)
fix(security): encrypt SLACK-001 bot tokens at rest (#453) (#667)
test(security): backfill encryption tests for Telegram/WhatsApp/Slack…
test(security): backfill encryption tests for Telegram/WhatsApp/Slack…
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).
Release: v0.6.1 (#1171)
fix(security): encrypt credential-bearing system_settings rows at res…