Files
gstack/supabase/migrations/004_attack_telemetry.sql
T
Garry Tanandcapy-ai[bot] 12cc21872d Telemetry backend only accepts writes through its own endpoint, and tests stop sending to it (GST-3234) (#4537)
The telemetry backend now takes writes only through its validated
endpoint, signed-in Supabase users can read or write nothing, and
gstack's tests can no longer send telemetry to the live project.

Why: a signed-in prober read two views on 2026-11-19, probes wrote about
2,000 junk rows through the open insert policy, and 41% of all skill-run
rows were test-suite traffic.

Nothing changes for users until the migrations and edge functions are
deployed; the deploy order is under Deploy.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: supabase/migrations/008_close_anon_writes.sql:9:published-number reader=core
Review-Finding: p2/outside-voice#3 reader=outside-voice
2026-11-19 20:31:31 +00:00

48 lines
2.2 KiB
SQL

-- gstack attack telemetry — schema extension for prompt injection events.
--
-- Ships alongside the gstack-telemetry-log `--event-type attack_attempt`
-- flag (bin/gstack-telemetry-log, commits 28ce883c + f68fa4a9). These
-- columns are nullable so the existing skill_run events continue inserting
-- unchanged.
--
-- Fields (1:1 with gstack-telemetry-log flags):
-- security_url_domain — hostname only, never path/query
-- security_payload_hash — salted SHA-256 hex
-- security_confidence — 0..1 numeric, clamped client-side
-- security_layer — stackone_content | testsavant_content
-- | transcript_classifier | aria_regex | canary
-- | deberta_content
-- security_verdict — block | warn | log_only
--
-- Indices:
-- * (security_url_domain, event_timestamp) — for "top domains last 7 days"
-- * (security_layer, event_timestamp) WHERE event_type='attack_attempt'
-- — for layer-distribution queries
--
-- Privacy rules (enforced client-side, documented here):
-- * domain only, never path or query string
-- * payload_hash is a salted hash, not the payload
-- * salt is per-device local file (~/.gstack/security/device-salt) —
-- preventing cross-device rainbow table attacks
-- IF NOT EXISTS: this migration was not applied to the live project until
-- after 006 was written, so it must be safe to run twice. It must run before
-- 006, whose view and function read these columns.
ALTER TABLE telemetry_events
ADD COLUMN IF NOT EXISTS security_url_domain TEXT,
ADD COLUMN IF NOT EXISTS security_payload_hash TEXT,
ADD COLUMN IF NOT EXISTS security_confidence NUMERIC,
ADD COLUMN IF NOT EXISTS security_layer TEXT,
ADD COLUMN IF NOT EXISTS security_verdict TEXT;
-- Top-domains query: ORDER BY count DESC WHERE event_type='attack_attempt'
-- AND event_timestamp > now() - interval '7 days'
CREATE INDEX IF NOT EXISTS idx_telemetry_attack_domain
ON telemetry_events (security_url_domain, event_timestamp)
WHERE event_type = 'attack_attempt';
-- Layer-distribution query
CREATE INDEX IF NOT EXISTS idx_telemetry_attack_layer
ON telemetry_events (security_layer, event_timestamp)
WHERE event_type = 'attack_attempt';