Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
Merge remote-tracking branch 'origin/main' into depth/7.1-7.3-phishing
Beenu Arora3474c3e8ada4
diff --cc CHANGELOG.mdindex 65e7e092c,59b54ed67..1e88b9011--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -191,50 -231,6 +231,50 @@@ and this project adheres to [Semantic V### Added+- **Reported phish now goes from intake to purge (depth 7.1).** The gap was+ not that phishing was unhandled — `POST /phishing/submit` has triaged+ artefacts since migration 015 — but that nothing in the product could+ *remove a message*. The live-action registry held 79 builtin arms and not+ one could touch a mailbox, so governed dispatch answered+ `executor_not_found` for `purge_email`: a response that could block the+ sender's domain at the firewall and could not take back the mail. Five+ verbs enter both halves of the capability vocabulary (`search_mailboxes`,+ `purge_email`, `restore_email`, `block_sender`, `unblock_sender`) with ten+ vendor arms over Microsoft Graph and the Gmail API. Only what the vendors+ document: purge is a move to `recoverableitemsdeletions` or to Trash, never+ a hard delete, and `restore_email` is a real reverse rather than a declared+ one. There is deliberately **no tenant-wide blocked-sender verb**, because+ neither vendor exposes its organisation-level block list through these+ APIs; the sender block is per mailbox and says so in the summary an analyst+ reads, not only in a docstring. Reported-message intake normalises three+ sources into one record — an M365 report mailbox over Graph, Workspace user+ reports, and the existing `email_inbox` connector — and the hard case is+ the common one: a user who reports by forwarding becomes the *sender*, so+ the adapter reads the original sender and recipients out of the preserved+ headers and leaves the sender empty rather than naming the victim as the+ attacker. Campaign grouping is a five-step ladder and `grouping_basis`+ records which step matched, because four are facts about the message and+ subject similarity is a judgement. The purge is **one proposal and one+ dispatch per mailbox**: handing a single executor twenty-five addresses+ would be one approval covering a list the approver never read.+ `scaled_impact` turns the recipient count into the tier — MODERATE at one,+ HIGH at five, SEVERE at twenty-five, where `NEVER_AUTONOMOUS` makes it+ mandatory-human at any confidence and any autonomy tier — and the proposal+ and every dispatch under it read the same function, so the approver and the+ executor cannot see different actions. Verification re-queries the mailbox,+ and that probe is the one in the service whose confirming answer is an+ *absence*. Everything ships **off**: `AISOC_FEATURE_MAILBOX_REMEDIATION`+ and `PHISHING_INTAKE_WORKER_ENABLED` both default false, and a disabled+ deployment answers FAILED naming the setting rather than simulating a purge+ — `NotifySlackExecutor` reporting `message_sent: true` for a message it- never sent is the precedent. Migration `104`. Gates:++ never sent is the precedent. Migration `110`. Gates:+ `check_action_contract.py` (86 → 97 executors), `check_module_reachability.py`+ (981 → 986 reachable), `check_vendor_catalog_ids.py`,+ `test_mailbox_remediation.py` (60 cases through real `respx` HTTP) and+ `test_phishing_campaign_purge_live.py` (17 cases against a real Postgres+ with the full chain). **No Microsoft 365 or Google Workspace tenant was+ exercised**: every vendor claim rests on the documented request shape and a+ mock.- `services/api/app/models/detection_rule.py` maps the `author` column, whichhas existed since `001_init.sql` and was mapped by nothing — while fusion'stenant overlay reads it on every reload to say *who* silenced a rule when itdiff --cc DEPTH_PROGRESS.mdindex a275ab0da,a75a88df4..daed72e35--- a/DEPTH_PROGRESS.md+++ b/DEPTH_PROGRESS.md@@@ -58,18 -58,23 +58,35 @@@ is written. Next free at capture: migra| ADR `0010` | 2.7 — entity and session context in CORE | **landed**, `docs/decisions/0010-entity-and-session-context-in-core.md`, accepted || migration `102` | 2.4 — `102_sessions.sql` | claimed || migration `103` | 2.5 — `103_posture_snapshots.sql` | claimed |- | migration `104` | 7.1 — `104_phishing_campaigns.sql` | claimed |- | migration `105` | 7.2 — `105_phishing_message_analysis.sql` | claimed |+ | migration `104` | 9.1 — `104_mcp_access.sql` | claimed |+ | migration `105` | 9.2 — `105_semantic_memory.sql` | claimed |+ | migration `106` | 9.3 — `106_case_depth.sql` | claimed |+ | migration `107` | 9.4 — `107_case_war_rooms.sql` | claimed |+ | migration `108` | 9.5 — `108_hunt_reports.sql` | claimed |+ | migration `109` | 9.6 — `109_push_devices.sql` | claimed |++| migration `110` | 7.1 — `110_phishing_campaigns.sql` | claimed |++| migration `111` | 7.2 — `111_phishing_message_analysis.sql` | claimed |Highest migration on `main` at claim time was `101_audit_immutable_nullify.sql`,so `095`--`101` were taken by sibling lanes between the capture above and thisclaim; re-read `services/api/migrations/` rather than trusting the capture row.- Phase 7 re-read `services/api/migrations/` on 2026-10-11 before claiming: the- highest on `main` was still `101_audit_immutable_nullify.sql`, and `102`/`103`- were held by the rows above, so `104` and `105` were the first free pair. 7.3- is detection content and claims no number.+ Phase 9 re-read `services/api/migrations/` on 2026-10-11 before claiming:+ `101_audit_immutable_nullify.sql` was still the highest on `main`, and `102`+ and `103` were already spoken for in the table above, so Phase 9 takes `104`+ through `109`, one per item. A number left unused at the end of the phase is+ released by striking its row rather than by silently leaving a gap.+++Phase 7 claimed `104` and `105` on the same day and **lost the race**: Phase 9++merged to `main` first, so Phase 7 renumbered to `110` and `111` rather than++leaving two files with one number each. Both lanes re-read the directory++before claiming and both read `101`, which is the shape a claim table cannot++prevent on its own — the table is the tiebreak, and whoever lands second++moves. Recorded because the next lane will hit it too: re-read++`DEPTH_PROGRESS.md` on `origin/main`, not only the migrations directory, and++expect to renumber if a sibling merged between the claim and the pull++request.+## Phase 0: Kickoff- [x] **0.1** `DEPTH_PROGRESS.md` exists (this file), modelled ondiff --cc services/api/migrations/110_phishing_campaigns.sqlindex 398d3688b,000000000..d598ddc7cmode 100644,000000..100644--- a/services/api/migrations/110_phishing_campaigns.sql+++ b/services/api/migrations/110_phishing_campaigns.sql@@@ -1,198 -1,0 +1,198 @@@- -- 104_phishing_campaigns.sql — reported-message intake, campaign grouping and++-- 110_phishing_campaigns.sql — reported-message intake, campaign grouping and+-- the per-recipient purge ledger.+--+-- Depth plan 7.1 (gap-closure Phase 10, parity 6.4). Phishing submissions have+-- existed since migration 015 and they record one artefact at a time: a body,+-- a sender, a subject, a list of URLs and a verdict. Nothing in that shape can+-- answer the two questions a phishing response actually turns on — **who else+-- got this**, and **is this the same message somebody reported an hour ago** —+-- so a campaign of twenty-five was twenty-five unrelated rows and the purge+-- had no list to work from.+--+-- Three additions, each answering one of those.+--+-- 1. Columns on the existing submissions table+-- --------------------------------------------+-- `internet_message_id` is the join key. It is the one identifier that+-- survives a message being delivered to many mailboxes, and it is what+-- Microsoft Graph filters on and what Gmail's `rfc822msgid:` operator+-- searches. Without it a purge cannot find the copies.+--+-- `recipients` is who received it, as reported. `reported_by` is who told us,+-- which is a different person and is the one an analyst thanks or asks a+-- follow-up question. `intake_source` records which of the three doors the+-- report came through, because "the M365 report mailbox has gone quiet" is a+-- diagnosis nobody can make from a table that does not distinguish them.+--+-- 2. `aisoc_phishing_campaigns`+-- -----------------------------+-- One row per group of submissions that are the same message. `grouping_key`+-- is a hash of whichever attribute grouped them and `grouping_basis` names+-- which one, so a reader can see *why* two reports were joined rather than+-- having to trust that they were. That matters because subject-similarity+-- grouping is a judgement and the other three are facts, and an analyst+-- about to purge across forty mailboxes is entitled to know which kind of+-- claim they are acting on.+--+-- `recipient_count` is stored rather than computed on read, because it is the+-- input to the approval tier: `capability_contracts.scaled_impact` turns it+-- into MODERATE, HIGH or SEVERE, and a count that changes between the+-- proposal being graded and the approver reading it would mean the two saw+-- different actions. It is recomputed from the recipient rows whenever one is+-- added, in the same transaction.+--+-- 3. `aisoc_phishing_campaign_recipients`+-- ---------------------------------------+-- One row per (campaign, mailbox). This is the purge ledger and it is a+-- table rather than a JSONB column for one reason: the purge is dispatched+-- **one request per mailbox**, each graded, audited and reversible on its+-- own, so each needs its own state and its own restore handle. A list inside+-- a document could record the outcome; it could not record twenty-five+-- outcomes that a rollback has to read back individually.+--+-- `purge_state` is a closed vocabulary and its default is `not_attempted`,+-- not `pending`. "Nobody has tried" and "a try is in flight" are different+-- facts and only one of them should make an operator wait.+--+-- `restore_message_id` and `restore_folder_id` are what the rollback needs and+-- cannot recover later: Microsoft's move gives the message a new id in the+-- destination folder, and the folder it came from is only knowable before the+-- move. Storing them is the difference between a declared rollback and a real+-- one.+--+-- Reversible: DROP TABLE IF EXISTS (children first), then DROP COLUMN.++ALTER TABLE aisoc_phishing_submissions+ ADD COLUMN IF NOT EXISTS internet_message_id TEXT;++ALTER TABLE aisoc_phishing_submissions+ ADD COLUMN IF NOT EXISTS recipients TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[];++ALTER TABLE aisoc_phishing_submissions+ ADD COLUMN IF NOT EXISTS reported_by TEXT;++-- `manual` is the honest default for every row that already exists: they came+-- through POST /phishing/submit, which is a person or a scripted caller, and+-- backfilling them as though they arrived from a report mailbox would invent+-- provenance.+ALTER TABLE aisoc_phishing_submissions+ ADD COLUMN IF NOT EXISTS intake_source TEXT NOT NULL DEFAULT 'manual';++ALTER TABLE aisoc_phishing_submissions+ ADD COLUMN IF NOT EXISTS campaign_id UUID;++CREATE INDEX IF NOT EXISTS aisoc_phishing_submissions_message_idx+ ON aisoc_phishing_submissions (tenant_id, internet_message_id)+ WHERE internet_message_id IS NOT NULL;++CREATE INDEX IF NOT EXISTS aisoc_phishing_submissions_campaign_idx+ ON aisoc_phishing_submissions (campaign_id)+ WHERE campaign_id IS NOT NULL;+++CREATE TABLE IF NOT EXISTS aisoc_phishing_campaigns (+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),+ tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,++ -- Hash of the grouping attribute. Hashed rather than stored raw because+ -- the attribute may be a 998-character subject line and because it is+ -- only ever compared for equality.+ grouping_key TEXT NOT NULL,+ grouping_basis TEXT NOT NULL+ CHECK (grouping_basis IN ('internet_message_id', 'attachment_hash', 'url', 'sender', 'subject')),++ sender TEXT,+ subject TEXT,++ report_count INTEGER NOT NULL DEFAULT 0,+ recipient_count INTEGER NOT NULL DEFAULT 0,++ -- `open` -> `purge_proposed` -> `purging` -> `purged` | `partially_purged`+ -- -> `restored`, or `dismissed` at any point. `partially_purged` exists+ -- because a fan-out across forty mailboxes routinely succeeds on most and+ -- fails on some, and collapsing that into `purged` publishes a claim the+ -- deployment cannot support.+ status TEXT NOT NULL DEFAULT 'open'+ CHECK (status IN ('open', 'purge_proposed', 'purging', 'purged',+ 'partially_purged', 'restored', 'dismissed')),++ first_reported_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ last_reported_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),++ UNIQUE (tenant_id, grouping_key)+);++CREATE INDEX IF NOT EXISTS aisoc_phishing_campaigns_tenant_idx+ ON aisoc_phishing_campaigns (tenant_id, last_reported_at DESC);++COMMENT ON COLUMN aisoc_phishing_campaigns.grouping_basis IS+ 'Which attribute joined these reports. Three of the five are facts about the message; '+ 'subject similarity is a judgement. An analyst about to purge across forty mailboxes is '+ 'entitled to know which kind of claim they are acting on.';+++CREATE TABLE IF NOT EXISTS aisoc_phishing_campaign_recipients (+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),+ campaign_id UUID NOT NULL REFERENCES aisoc_phishing_campaigns(id) ON DELETE CASCADE,+ tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,++ recipient TEXT NOT NULL,+ internet_message_id TEXT NOT NULL DEFAULT '',++ -- Mirrors the step vocabulary in `playbook_step_dispatch.NOT_EXECUTED_STATES`+ -- plus the two terminal mailbox states. `not_attempted` is the default+ -- rather than `pending`: "nobody has tried" and "a try is in flight" are+ -- different facts and only one of them should make an operator wait.+ purge_state TEXT NOT NULL DEFAULT 'not_attempted'+ CHECK (purge_state IN ('not_attempted', 'simulated', 'pending_approval',+ 'purged', 'not_found', 'failed', 'restored')),+ purge_detail TEXT NOT NULL DEFAULT '',++ -- What a rollback needs and cannot recover afterwards.+ restore_message_id TEXT NOT NULL DEFAULT '',+ restore_folder_id TEXT NOT NULL DEFAULT '',+ vendor TEXT NOT NULL DEFAULT '',++ last_action_at TIMESTAMPTZ,+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),++ UNIQUE (campaign_id, recipient)+);++CREATE INDEX IF NOT EXISTS aisoc_phishing_recipients_campaign_idx+ ON aisoc_phishing_campaign_recipients (campaign_id, purge_state);++COMMENT ON TABLE aisoc_phishing_campaign_recipients IS+ 'The purge ledger: one row per mailbox, because the purge is dispatched one request per '+ 'mailbox and each is graded, audited and reversible on its own. A JSONB list could record '+ 'the outcome; it could not record twenty-five outcomes a rollback has to read back.';++-- Written out per table rather than looped with `format()`, so the policy is+-- visible to `grep` and to `scripts/check_tenant_query_predicates.py`, which+-- reads migrations to learn which tables carry one.+DO $$+BEGIN+ EXECUTE 'ALTER TABLE aisoc_phishing_campaigns ENABLE ROW LEVEL SECURITY';+ EXECUTE 'ALTER TABLE aisoc_phishing_campaigns FORCE ROW LEVEL SECURITY';+ EXECUTE 'DROP POLICY IF EXISTS tenant_isolation ON aisoc_phishing_campaigns';+ EXECUTE+ 'CREATE POLICY tenant_isolation ON aisoc_phishing_campaigns '+ 'USING (tenant_id = current_tenant_id() OR current_tenant_id() IS NULL) '+ 'WITH CHECK (tenant_id = current_tenant_id())';++ EXECUTE 'ALTER TABLE aisoc_phishing_campaign_recipients ENABLE ROW LEVEL SECURITY';+ EXECUTE 'ALTER TABLE aisoc_phishing_campaign_recipients FORCE ROW LEVEL SECURITY';+ EXECUTE 'DROP POLICY IF EXISTS tenant_isolation ON aisoc_phishing_campaign_recipients';+ EXECUTE+ 'CREATE POLICY tenant_isolation ON aisoc_phishing_campaign_recipients '+ 'USING (tenant_id = current_tenant_id() OR current_tenant_id() IS NULL) '+ 'WITH CHECK (tenant_id = current_tenant_id())';++ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'aisoc_app') THEN+ EXECUTE 'GRANT SELECT, INSERT, UPDATE, DELETE ON aisoc_phishing_campaigns TO aisoc_app';+ EXECUTE 'GRANT SELECT, INSERT, UPDATE, DELETE ON aisoc_phishing_campaign_recipients TO aisoc_app';+ END IF;+END+$$;