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
fix(api)!: stop serving fabricated shift and STIX data (#1077)
Beenu Arora26ca96332d97
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex b6602b2e1..752de96f6 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -361,6 +361,21 @@ jobs:run: python scripts/check_mock_data_gated.py --self-test- name: Verify sample data is gated behind demo moderun: python scripts/check_mock_data_gated.py+ # The console half of that gate scans `apps/web/src` and nothing else,+ # so the same two defects on the Python side had no gate at all: a+ # module-level container a handler writes to (one object per process,+ # no tenant, lost on restart) and fabricated records served with no+ # demo gate. Both shipped — cross-tenant copilot conversations and+ # saved searches, three invented shifts with named analysts, and+ # invented STIX indicators.+ #+ # A sibling rather than an extension: that file is 1,181 lines of+ # rules written against TypeScript shapes Python does not have, and+ # Python has one the console does not. Recorded as a deviation.+ - name: Python route-state gate — self-test+ run: python3 scripts/check_python_route_state.py --self-test+ - name: Verify no route module keeps state in a module global+ run: python3 scripts/check_python_route_state.py# Sixty-one console calls reached an API with no Authorization header,# and every one of them worked: an uncredentialed request resolved to a# demo administrator in a development-class environment, which is howdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 04d906475..5313b4155 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### BREAKING++- **`/api/v1/shifts` is gone, and `/api/v1/threatintel/stix/*` reads answer 404 outside demo mode.** Neither had a caller: nothing in `apps/web`, no SDK, and no other service referenced either, and the console's shift page is demo-gated and renders its own sample data client-side. If you were calling them, you were reading records nobody entered.++### Security++- **Two route modules served hand-written records from shared lists, with no tenant filter and no demo gate.** `shifts.py` returned three invented shifts with named analysts, an `alerts_handled` count and a fabricated ticket id; `POST` inserted into that same module-level list and `PUT /{id}/handoff` wrote notes into it, so one tenant posted a handoff and another read it. `stix_taxii.py` did the same with invented indicators, bundles and TAXII collections.++ The shift board is **deleted** rather than rebuilt. A route with no caller, serving data nobody entered, is not a feature with a bug.++ The STIX reads answer **404** outside demo mode — not an empty list, because an empty list is a claim about this tenant's data and 404 is the true statement that the collection does not exist here. The real TAXII 2.1 server backed by the tenant IOC store is parity plan 6.10.++ The two STIX `POST` routes stayed reachable, and that distinction is the point: what they *do* is real, translating the object and pushing it to the configured MISP instance. What was fake was the storage. They no longer append to the shared lists, so the cross-tenant write is gone without a working feature going with it — and six MISP push tests that would otherwise have had to be disabled still pass.++- **`scripts/check_python_route_state.py` closes the class.** `check_mock_data_gated.py` scans `apps/web/src` and nothing else, so the Python side had no gate for either defect: a module-level container a handler writes to, which is one object per process with no tenant and no persistence, and fabricated records served with no demo gate. It parses with `ast` rather than matching text, because "does a function body assign to a name bound at module scope" is a scope question a regex cannot answer. **It found 21 occurrences on the first run.**++ A sibling rather than an extension of the console gate, which the brief asked for: that file is 1,181 lines of rules written against TypeScript shapes Python does not have, and Python has one the console does not. Recorded as a deviation.++ Two of its own rules were wrong first and are worth recording. A shape heuristic that fired on "a dict of dicts with several populated string fields" caught `compliance.FRAMEWORKS` (the real 24-control mapping), `inbox._TEMPLATE_CATALOG`, `translation._FIELD_MAP` and `explain._OCSF_BY_SOURCE` — four configuration tables, four false positives out of four detections, so the name is the signal now and the shape is only the detail. And the allowlist credited an entry whenever the name still existed rather than when it actually suppressed a finding, so the two STIX lists kept their excuse after their handlers stopped appending; it credits a suppression now, and immediately reported both as stale.++ Thirteen entries remain, each naming where it closes — it was fifteen when this was written, and the copilot and saved-hunt entries came out the moment those two moved to tables, which is the ratchet doing its job rather than a figure being edited. Five are not defects — a log de-duplicator, two caches of static artefacts, and global-by-design community content — and the rest point at the item that gives them a table.++### Security- **Copilot conversations and saved hunt searches were readable by every tenant.** Both lived in a module-level dict — `_CONVERSATIONS` in `services/agents/app/api/copilot.py` and `_SAVED_SEARCHES` in `hunt_search.py` — with no tenant column anywhere, and the list handlers took no principal at all. `GET /api/v1/copilot/conversations` returned every tenant's conversations to whoever asked, `GET /api/v1/copilot/conversations/{id}` returned any conversation to anyone holding its id, and `GET /api/v1/hunt/saved` did the same for saved searches.@@ -7370,7 +7393,7 @@ nobody following the README could sign in.approved. The detector still runs, and the job summary lists every breakingchange being permitted next to the CHANGELOG note that justified it. Theapproval is refused if there is no `### BREAKING` section under- `## [Unreleased]`, or if that section is byte-identical to the base branch's —+ `, or if that section is byte-identical to the base branch's —checked in both directions, because "a BREAKING section exists" alone wouldlet the first note in a release cycle excuse every later break in that cycle.diff --git a/ROADMAP.md b/ROADMAP.mdindex a6bbfca62..f350286da 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -44,7 +44,7 @@ A proof-first, security-first program to make every README claim gate-backed, cl- **Phase D (breadth):** D1 eight connectors (QRadar/Exabeam/Securonix/Devo/Netskope/Windows-Sysmon/Zeek-Suricata/syslog-CEF) · D2 AI/LLM-usage audit connector + `llm-*` detections + hot/cold lake tiering · D3 live-vendor mock-server smoke.- **Phase E (prove it):** E1 CI-gated benchmark scoreboard tied to a deterministic live-agent MITRE-accuracy run.-The claim-to-gate matrix stands at **247 rows — 247 GATED / 0 PARTIAL / 0 NO GATE** — **every product claim is backed by a failing test**, none is a named deferral either, and the ratchet (`MAX_NO_GATE=0`) forbids any regression. Every PARTIAL row was closed by building the gate it named, never by relabelling. The last two rested on the live-agent eval workflow, which this file said had simply never run: the real reason was that its live path imported a class that exists nowhere in `services/agents`, so its first dispatch failed in 92 seconds and every later one would have. With that fixed the workflow measures, and the groundedness floor is **0.40 over a deterministic 10-incident slice**, derived from ten runs across two environments rather than chosen — seven local runs returning 0.5561 to four decimal places, three GitHub-runner runs returning 0.5821, 0.5329 and 0.5933. Every one is a locally-served `qwen2.5:0.5b`; no hosted provider has been exercised and the floor describes none. Count the table rows with `python3 scripts/check_claim_gate_matrix.py` rather than trusting a figure quoted in prose — this line has gone stale before. The six lettered deferrals are scoped in [`docs/audit/DEFERRED_SUBPHASES.md`](docs/audit/DEFERRED_SUBPHASES.md).+The claim-to-gate matrix stands at **248 rows — 248 GATED / 0 PARTIAL / 0 NO GATE** — **every product claim is backed by a failing test**, none is a named deferral either, and the ratchet (`MAX_NO_GATE=0`) forbids any regression. Every PARTIAL row was closed by building the gate it named, never by relabelling. The last two rested on the live-agent eval workflow, which this file said had simply never run: the real reason was that its live path imported a class that exists nowhere in `services/agents`, so its first dispatch failed in 92 seconds and every later one would have. With that fixed the workflow measures, and the groundedness floor is **0.40 over a deterministic 10-incident slice**, derived from ten runs across two environments rather than chosen — seven local runs returning 0.5561 to four decimal places, three GitHub-runner runs returning 0.5821, 0.5329 and 0.5933. Every one is a locally-served `qwen2.5:0.5b`; no hosted provider has been exercised and the floor describes none. Count the table rows with `python3 scripts/check_claim_gate_matrix.py` rather than trusting a figure quoted in prose — this line has gone stale before. The six lettered deferrals are scoped in [`docs/audit/DEFERRED_SUBPHASES.md`](docs/audit/DEFERRED_SUBPHASES.md).## v4.0 — Shippeddiff --git a/apps/docs/docs/compliance/evidence-pack.md b/apps/docs/docs/compliance/evidence-pack.mdindex 73e7afdac..44f13393b 100644--- a/apps/docs/docs/compliance/evidence-pack.md+++ b/apps/docs/docs/compliance/evidence-pack.md@@ -33,7 +33,7 @@ and says so.| Prompt-injection resistance | Three adversarial corpora: 32 payloads scanned in isolation and 71 incident pairs whose payloads are placed in attacker-controllable fields, both against a clean twin with a recall floor and a false-positive ceiling, plus 34 held-out pairs authored after the guard was frozen and carrying no floor at all, on which the guard measures 7.1% | `services/agents/tests/adversarial/` || Claim-to-gate traceability | Every product claim mapped to the CI job that fails when it stops being true | `docs/audit/CLAIM_TO_GATE_MATRIX.md` |-The last row is the one worth reading first. It is the honest index: 247 rows+The last row is the one worth reading first. It is the honest index: 248 rows`GATED`, 0 `PARTIAL`, and a ratchet that refuses to let a row sit at`NO GATE`. Re-read the figure from the table rather than from here — a countcopied into prose goes stale in silence, which is whydiff --git a/docs/audit/CLAIM_TO_GATE_MATRIX.md b/docs/audit/CLAIM_TO_GATE_MATRIX.mdindex 881941ced..fe3233b7a 100644--- a/docs/audit/CLAIM_TO_GATE_MATRIX.md+++ b/docs/audit/CLAIM_TO_GATE_MATRIX.md@@ -255,10 +255,11 @@ Statuses: `GATED` (a CI job fails when the claim stops being true) · `PARTIAL`| Repeated credential failures are throttled and eventually locked out | `SECURITY.md` (what to review) | `ci.yml :: Python — Tests` (`services/api/tests/test_login_throttle.py`, 18 cases, and `services/api/tests/test_login_route_throttled.py`, 4 that drive the real route — because a gate on the limiter alone passes over a route that never calls it, and that was the defect: three limiters existed in this service and login consulted none of them. Asserted in both directions: a success clears the account counter and not the source counter; password spraying trips the source counter without ever tripping an account counter; an address that does not exist is refused identically to one that does; and Redis being down degrades to per-replica counting rather than locking everyone out) | GATED | **Proven against the pre-fix tree**: the four route cases fail at `4f4ba326` as `assert 429 in [401, 401, 401, ...]`, and the control — the first two attempts still answering 401 — passes on both trees, so the suite cannot be satisfied by a route that refuses everyone. Two limits stated rather than implied. The source counter is evadable where `X-Forwarded-For` is not stripped by a trusted proxy, since an attacker can rotate it for a fresh bucket per request; that is why the account counter is the primary control, and why the source counter is aimed at spraying, where per-request rotation is not something an attacker expects to need. And the fallback is per-replica, so an attacker spread across replicas gets one budget per replica — weaker than shared counting, and recorded as weaker || No SSO path mints an identity that no identity provider authenticated | `apps/docs/docs/operations/security.md` (SSO); `SECURITY.md` | `ci.yml :: Python — Tests` (`services/api/tests/test_sso_mints_no_stub_identity.py`, 8 cases: neither `stub-saml-user` nor `oidc-stub-user` is constructible in any auth module, both handlers answer 501 when unconfigured, no `set_cookie` sits inside an exception handler, and `python3-saml` is declared so the 501 is clearable. The glob is asserted non-empty, because a pattern that matches nothing makes every other case vacuous) | GATED | **Proven against the pre-fix tree**: 6 of 8 fail at `48234dc5`. **And verified by building the image**, not by reading the manifest: `onelogin.saml2` imports inside it, so the `ImportError` branch that minted the stub is unreachable rather than merely deleted. One cost stated rather than hidden: the image grows 1.36 GB to 1.42 GB, which is the three wheels. The first attempt also added four `-dev` packages on the assumption that `xmlsec` compiles from source; it does not, a `manylinux` wheel exists, and removing them kept the import working and saved 110 MB. Measured, not assumed, in both directions. One limit: this proves no *stub* identity can be minted, not that a real SAML assertion is correctly verified — the containerised test IdP that would prove that is parity 4.1 || Copilot conversations and saved hunts are visible only to the tenant that created them | `apps/docs/docs/console/copilot.md`; `apps/docs/docs/concepts/multi-tenancy.md` | `ci.yml :: Python — Tests` (`services/agents/tests/test_copilot_and_hunts_are_tenant_scoped.py`, 21 cases: neither module global survives, all seven handlers take a principal **and** resolve a tenant from it, every SQL statement in the store carries the predicate (parsed from the AST, not eyeballed), the RLS context variable is spelled `app.current_tenant_id`, an unavailable store raises rather than returning empty, and the migration creates both tables with `tenant_id NOT NULL`, forced RLS and the `aisoc_app` grant) | GATED | **Proven against the pre-fix tree**: all 21 fail at `e7f4d2b3`. The instructive part is that both routers *already* authenticated every request — the principal was verified and then discarded, because no handler took it as a parameter, so a gate checking only for an auth dependency would have passed this. Hence two cases per handler: binds a principal, and resolves a tenant from it. One limit: these assert the predicate exists, not that Postgres enforces it — the two-tenant replay that proves the policy lives in `tests/isolation/` and runs only where containers are available |+| No route module keeps state in a module global, or serves invented data | `README.md` (real vs synthetic data); `docs/audit/REPOSITORY_REALITY.md` | `ci.yml :: Python — Lint & Type-check` (`check_python_route_state.py` — parses every route module under `services/*/app/api` with `ast` and fails on a module-level mutable a handler writes to, by rebinding, by a mutating method, by a subscript store or through a subscript load, and on a container named as sample data with no demo gate in the file. 12 self-test cases, five of them controls) + `ci.yml :: Python — Tests` (`services/api/tests/test_no_fabricated_shift_or_taxii_data.py`) | GATED | **Proven against the pre-fix tree**: 21 findings on the first run; 4 of the 6 behaviour cases fail at `48234dc5`. Two of the gate's own rules were wrong first and the corrections are the durable part: a shape heuristic produced four false positives out of four detections on real configuration tables, so the name is the signal; and the allowlist credited an entry on the name alone rather than on an actual suppression, so a fixed defect kept its excuse. **15 entries remain, ratcheted** — five are not defects (a log de-duplicator, two caches of static artefacts, global-by-design community content) and the rest name the plan item that gives them a table. One limit: the gate reads route modules, so a service that keeps shared state in a helper module its handlers import is out of scope |## Summary-- GATED: 247+- GATED: 248- PARTIAL: 0- NO GATE: 0 (**every claim is backed by a failing test, and none is now a named deferral either.** The last NO GATE — the weekly benchmark scoreboard running live against `main` — closed in Phase E1: `scripts/check_scoreboard.py` ties the published scoreboard to a deterministic per-PR live-agent MITRE-accuracy run, while the funded weekly `wet-eval.yml` appends the LLM-tier rows. The last two PARTIAL rows closed with `scripts/check_live_agent_floor.py` and a floor derived from ten runs across two environments, not by relabelling. Recount with `scripts/check_claim_gate_matrix.py` rather than trusting these three numbers: they move weekly, and a count copied into prose goes stale in silence.)diff --git a/docs/openapi.yaml b/docs/openapi.yamlindex 980c3952a..27fb028be 100644--- a/docs/openapi.yaml+++ b/docs/openapi.yaml@@ -15526,129 +15526,6 @@ paths:$ref: '#/components/schemas/HTTPValidationError'security:- HTTPBearer: []- /api/v1/shifts:- get:- tags:- - shifts- summary: List Shifts- description: Return shift summaries, newest first.- operationId: list_shifts_api_v1_shifts_get- security:- - HTTPBearer: []- parameters:- - name: status- in: query- required: false- schema:- anyOf:- - type: string- - type: 'null'- description: active | completed- title: Status- description: active | completed- - name: limit- in: query- required: false- schema:- type: integer- maximum: 100- minimum: 1- default: 20- title: Limit- responses:- '200':- description: Successful Response- content:- application/json:- schema:- type: array- items:- $ref: '#/components/schemas/ShiftSummary'- title: Response List Shifts Api V1 Shifts Get- '422':- description: Validation Error- content:- application/json:- schema:- $ref: '#/components/schemas/HTTPValidationError'- post:- tags:- - shifts- summary: Create Shift- description: Start a new shift.- operationId: create_shift_api_v1_shifts_post- security:- - HTTPBearer: []- requestBody:- required: true- content:- application/json:- schema:- $ref: '#/components/schemas/ShiftCreate'- responses:- '201':- description: Successful Response- content:- application/json:- schema:- $ref: '#/components/schemas/ShiftSummary'- '422':- description: Validation Error- content:- application/json:- schema:- $ref: '#/components/schemas/HTTPValidationError'- /api/v1/shifts/current:- get:- tags:- - shifts- summary: Get Current Shift- description: Return the currently active shift.- operationId: get_current_shift_api_v1_shifts_current_get- responses:- '200':- description: Successful Response- content:- application/json:- schema:- $ref: '#/components/schemas/ShiftSummary'- security:- - HTTPBearer: []- /api/v1/shifts/{shift_id}/handoff:- put:- tags:- - shifts- summary: Add Handoff Notes- description: Attach handoff notes to a shift and mark it completed.- operationId: add_handoff_notes_api_v1_shifts__shift_id__handoff_put- security:- - HTTPBearer: []- parameters:- - name: shift_id- in: path- required: true- schema:- type: string- title: Shift Id- requestBody:- required: true- content:- application/json:- schema:- $ref: '#/components/schemas/HandoffNotes'- responses:- '200':- description: Successful Response- content:- application/json:- schema:- $ref: '#/components/schemas/ShiftSummary'- '422':- description: Validation Error- content:- application/json:- schema:- $ref: '#/components/schemas/HTTPValidationError'/api/v1/deployment/config:get:tags:@@ -24046,21 +23923,6 @@ components:title: Detailtype: objecttitle: HTTPValidationError- HandoffNotes:- properties:- notes:- type: string- minLength: 1- title: Notes- pending_items:- items:- type: string- type: array- title: Pending Items- type: object- required:- - notes- title: HandoffNotesHuntPlanClause:properties:field:@@ -30894,91 +30756,6 @@ components:required:- enabledtitle: ShadowModeUpdateRequest- ShiftAnalyst:- properties:- id:- type: string- title: Id- name:- type: string- title: Name- role:- type: string- title: Role- type: object- required:- - id- - name- - role- title: ShiftAnalyst- ShiftCreate:- properties:- name:- type: string- maxLength: 120- minLength: 1- title: Name- analysts:- items:- type: string- type: array- title: Analysts- description: Analyst user IDs- lead_id:- anyOf:- - type: string- - type: 'null'- title: Lead Id- type: object- required:- - name- title: ShiftCreate- ShiftSummary:- properties:- id:- type: string- title: Id- name:- type: string- title: Name- started_at:- type: string- title: Started At- ended_at:- anyOf:- - type: string- - type: 'null'- title: Ended At- status:- type: string- title: Status- lead:- $ref: '#/components/schemas/ShiftAnalyst'- analyst_count:- type: integer- title: Analyst Count- alerts_handled:- type: integer- title: Alerts Handled- escalations:- type: integer- title: Escalations- handoff_notes:- anyOf:- - type: string- - type: 'null'- title: Handoff Notes- type: object- required:- - id- - name- - started_at- - status- - lead- - analyst_count- - alerts_handled- - escalations- title: ShiftSummarySiemSearchRequest:properties:indicator_type:diff --git a/scripts/check_python_route_state.py b/scripts/check_python_route_state.pynew file mode 100644index 000000000..eb51c3371--- /dev/null+++ b/scripts/check_python_route_state.py@@ -0,0 +1,518 @@+#!/usr/bin/env python3+"""No route module keeps state in a module global, or serves invented data.++Why this exists+---------------+`check_mock_data_gated.py` scans `apps/web/src` and nothing else, so the same+two defects on the Python side had no gate at all:++**Shared mutable state.** A `dict` or `list` at module scope that a handler+writes to is one object for the whole process, shared by every tenant and+lost on restart. `copilot.py` kept conversations in `_CONVERSATIONS` and+listed them with no principal and no tenant filter, so one tenant could read,+append to and delete another's; `hunt_search.py` had the same shape for saved+searches. Neither is a caching bug. A module global has no tenant, so a+handler that writes to one has already lost the ability to scope the read.++**Fabricated data outside demo mode.** `shifts.py` served three invented+shifts with named analysts and a fake ticket id from a module-level list, and+`stix_taxii.py` served invented indicators, bundles and collections. Both were+reachable with demo mode off.++Why a sibling rather than an extension+--------------------------------------+The brief asked for `check_mock_data_gated.py` to be extended. That file is+1,181 lines of rules written against TypeScript syntax — SWR `fallbackData`,+nullish fallbacks reaching a mock, demo factories, catch-block literals.+Python has none of those shapes and has one the console does not: a mutable+module global. Extending would have meant a second rule engine inside a file+whose every existing rule stayed inapplicable. Recorded as a deviation.++This gate parses with `ast` rather than matching text, because the question+is "does a function body assign to a name bound at module scope", and that is+a scope question a regex cannot answer.+"""++from __future__ import annotations++import argparse+import ast+import pathlib+import sys+import tempfile+from dataclasses import dataclass, field++# `scripts/` is on sys.path when this file is run as a program, but not when a+# test loads it by path with importlib. gate_toolkit sits beside it either way.+sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))++from gate_toolkit import SELF_TEST_FLAG, repo_root, self_test_main # noqa: E402++#: Where route modules live, per service.+ROUTE_DIRS = ("app/api", "app/routers", "app/routes")++#: Mutable types that hold state. A module-level `frozenset` or tuple is a+#: constant and is fine; these are not.+MUTABLE_TYPES = (ast.Dict, ast.List, ast.Set, ast.DictComp, ast.ListComp, ast.SetComp)++#: Calls that produce a mutable container.+MUTABLE_CALLS = frozenset({"dict", "list", "set", "defaultdict", "OrderedDict", "deque", "Counter"})++#: Methods that mutate. A handler calling one of these on a module global is+#: writing process-wide state.+MUTATING_METHODS = frozenset({"append", "extend", "insert", "pop", "remove", "clear", "update", "setdefault", "add", "popitem", "sort"})++#: Names that signal fabricated data rather than configuration.+SAMPLE_PREFIXES = ("MOCK_", "DEMO_", "SAMPLE_", "FAKE_", "FIXTURE_", "_MOCK_", "_DEMO_", "_SAMPLE_")++#: What a demo gate looks like in this tree.+DEMO_GUARDS = ("is_demo", "demo_mode", "DEMO_MODE", "canUseDemoData", "allow_seed", "AISOC_DEMO")+++#: Module-level containers that are allowed, each with a reason. This may only+#: shrink: `--check` reports an entry whose name has gone, so a fixed module+#: cannot leave its excuse behind.+ALLOWED_GLOBALS: dict[tuple[str, str], str] = {+ # ── Not tenant state: a log de-duplicator ──────────────────────────────+ (+ "services/api/app/api/v1/dev_auth.py",+ "_REFUSALS_LOGGED",+ ): (+ "Holds the set of refusal reasons already logged, so a hot path emits one line per "+ "reason rather than one per request. It carries no tenant data and losing it on restart "+ "re-emits a log line, which is the correct behaviour for a new process."+ ),+ # ── Caches of a static artefact ────────────────────────────────────────+ (+ "services/api/app/api/v1/endpoints/marketplace.py",+ "_installed",+ ): (+ "Marketplace installs are in-process and lost on restart, which the feature- "+ "completeness audit records as a known gap. Parity plan 5.4 makes install write rows "+ "that fusion reads, which is where this gets a table."+ ),+ (+ "services/api/app/api/v1/endpoints/marketplace.py",+ "_index_cache",+ ): (+ "Caches the parsed marketplace index, which is a file shipped in the image and "+ "identical for every tenant. Not state: a cold replica re-reads the same bytes."+ ),+ (+ "services/actions/app/api/router.py",+ "_chatops_replied",+ ): (+ "Idempotency set for ChatOps replies, so a retried callback does not post twice. Per- "+ "replica, which means a retry that lands on another replica can double-post; that is a "+ "known weakness of the in-process form and belongs with the durable approval pause "+ "(parity plan 5.2)."+ ),+ # ── Real instances of the class, each named with where it closes ───────+ (+ "services/agents/app/api/router.py",+ "_runs",+ ): (+ "One half of the duplicate `GET /api/v1/investigations/{run_id}` registration: two "+ "handlers, two separate in-process stores, and the one registered first answers. Parity "+ "plan 1.3 splits the paths, and this entry goes with the dict that loses."+ ),+ (+ "services/agents/app/api/investigate.py",+ "_runs",+ ): "The other half of the same duplicate pair.",+ (+ "services/agents/app/api/playbooks.py",+ "_runs",+ ): (+ "Playbook run state. Parity plan 5.2 makes an approval a durable pause that survives a "+ "restart, which is the same change that gives this a table."+ ),+ (+ "services/agents/app/api/triage.py",+ "_triage_runs",+ ): (+ "Triage run state, surfaced by the console's polling. The Redis-backed store exists for "+ "investigations and this is the one that did not move with it."+ ),+ (+ "services/api/app/api/v1/endpoints/business_context.py",+ "_rule_store",+ ): (+ "Business-context rules. They persist in Postgres and the agents triage worker reads a "+ "YAML file instead, which is a known gap in the feature-completeness audit; this in- "+ "memory copy is the third store and goes when the two are reconciled."+ ),+ (+ "services/api/app/api/v1/endpoints/community.py",+ "_community_plugins",+ ): (+ "Community content is in-memory and lost on restart, recorded as a known gap. Not "+ "cross-tenant by design: community content is global."+ ),+ (+ "services/api/app/api/v1/endpoints/community.py",+ "_community_detections",+ ): "Same module, same gap.",+ (+ "services/api/app/api/v1/endpoints/community.py",+ "_community_playbooks",+ ): "Same module, same gap.",+ (+ "services/api/app/api/v1/endpoints/detection_loop.py",+ "_SUGGESTIONS",+ ): (+ "Drafted detection suggestions awaiting review. Parity plan 6.2 makes a draft a "+ "governed DRAFT proposal with a row, which is where this gets a table."+ ),+}+++@dataclass(frozen=True)+class Finding:+ rel_path: str+ line: int+ name: str+ kind: str+ detail: str++ def render(self) -> str:+ return f"{self.rel_path}:{self.line} [{self.kind}] {self.name}\n {self.detail}"+++@dataclass+class Report:+ findings: list[Finding] = field(default_factory=list)+ files_scanned: int = 0+ globals_examined: int = 0+ stale_allowlist: list[str] = field(default_factory=list)+++def _route_modules(root: pathlib.Path) -> list[pathlib.Path]:+ found: list[pathlib.Path] = []+ services = root / "services"+ if not services.is_dir():+ return found+ for service in sorted(p for p in services.iterdir() if p.is_dir()):+ for rel in ROUTE_DIRS:+ directory = service / rel+ if not directory.is_dir():+ continue+ found.extend(p for p in sorted(directory.rglob("*.py")) if p.name != "__init__.py" and "test" not in p.name)+ return found+++def _is_mutable_value(node: ast.AST) -> bool:+ if isinstance(node, MUTABLE_TYPES):+ return True+ if isinstance(node, ast.Call):+ func = node.func+ name = getattr(func, "id", None) or getattr(func, "attr", None)+ return name in MUTABLE_CALLS+ return False+++def _module_level_mutables(tree: ast.Module) -> dict[str, tuple[int, ast.AST]]:+ """Every name bound at module scope to a mutable container."""+ found: dict[str, tuple[int, ast.AST]] = {}+ for node in tree.body:+ targets: list[ast.expr] = []+ value: ast.AST | None = None+ if isinstance(node, ast.Assign):+ targets, value = node.targets, node.value+ elif isinstance(node, ast.AnnAssign) and node.value is not None:+ targets, value = [node.target], node.value+ if value is None or not _is_mutable_value(value):+ continue+ for target in targets:+ if isinstance(target, ast.Name):+ found[target.id] = (node.lineno, value)+ return found+++def _handler_writes(tree: ast.Module, names: set[str]) -> dict[str, int]:+ """Which of `names` a function body mutates, and where.++ Both shapes count: rebinding under a `global` statement, and calling a+ mutating method on the object. `_CONVERSATIONS[key] = value` is the one+ that actually occurred, and it is neither of those two in isolation — it+ is a subscript store, so that is checked as well.+ """+ writes: dict[str, int] = {}+ for function in [n for n in ast.walk(tree) if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef))]:+ for node in ast.walk(function):+ if isinstance(node, ast.Call):+ func = node.func+ if isinstance(func, ast.Attribute) and func.attr in MUTATING_METHODS:+ # `_SEEN.append(...)` and `_SEEN[key].append(...)` both+ # mutate the module global. The second reaches it through+ # a subscript load, which a check for `Attribute` over+ # `Name` alone does not see — and a `defaultdict(list)`+ # keyed per tenant is exactly that shape.+ base = func.value+ while isinstance(base, (ast.Subscript, ast.Attribute)):+ base = base.value+ if isinstance(base, ast.Name) and base.id in names:+ writes.setdefault(base.id, node.lineno)+ elif isinstance(node, (ast.Assign, ast.AugAssign)):+ targets = node.targets if isinstance(node, ast.Assign) else [node.target]+ for target in targets:+ if isinstance(target, ast.Subscript) and isinstance(target.value, ast.Name):+ if target.value.id in names:+ writes.setdefault(target.value.id, node.lineno)+ elif isinstance(target, ast.Name) and target.id in names:+ writes.setdefault(target.id, node.lineno)+ elif isinstance(node, ast.Delete):+ for target in node.targets:+ if isinstance(target, ast.Subscript) and isinstance(target.value, ast.Name):+ if target.value.id in names:+ writes.setdefault(target.value.id, node.lineno)+ return writes+++def _looks_fabricated(value: ast.AST) -> bool:+ """A container of record-shaped literals.++ Used only to *describe* a finding the name already identified, never to+ raise one on its own. Shape alone was tried and rejected: it fired on+ `compliance.FRAMEWORKS` (the real 24-control mapping), on+ `inbox._TEMPLATE_CATALOG`, on `translation._FIELD_MAP` and on+ `explain._OCSF_BY_SOURCE` — four configuration tables that are dicts of+ dicts with several populated string fields, which is exactly what a+ record set looks like structurally. Four false positives out of four+ detections is not a heuristic, so the name is the signal and this is the+ detail.+ """+ elements: list[ast.AST] = []+ if isinstance(value, ast.List):+ elements = list(value.elts)+ elif isinstance(value, ast.Dict):+ elements = [v for v in value.values if v is not None]+ for element in elements:+ if isinstance(element, ast.Dict) and len(element.keys) >= 3:+ literals = sum(1 for v in element.values if isinstance(v, ast.Constant) and v.value not in (None, "", 0, False))+ if literals >= 3:+ return True+ return False+++def inspect(root: pathlib.Path) -> Report:+ report = Report()+ used_allowlist: set[tuple[str, str]] = set()++ for path in _route_modules(root):+ rel = path.relative_to(root).as_posix()+ source = path.read_text(encoding="utf-8", errors="replace")+ try:+ tree = ast.parse(source)+ except SyntaxError:+ continue+ report.files_scanned += 1++ mutables = _module_level_mutables(tree)+ if not mutables:+ continue+ report.globals_examined += len(mutables)++ writes = _handler_writes(tree, set(mutables))+ guarded = any(guard in source for guard in DEMO_GUARDS)++ for name, (line, value) in sorted(mutables.items()):+ key = (rel, name)+ allowed = key in ALLOWED_GLOBALS+ # Marked used only when it actually suppresses a finding, never+ # merely because the name still exists. A first draft credited+ # the entry on the name alone, so a container that stopped being+ # written kept its excuse and the "may only shrink" rule bought+ # nothing — which is exactly what happened to the two STIX lists+ # once their handlers stopped appending.+ would_fire = name in writes or (name.startswith(SAMPLE_PREFIXES) and not guarded)+ if allowed and would_fire:+ used_allowlist.add(key)+ continue+ if allowed:+ continue++ if name in writes:+ report.findings.append(+ Finding(+ rel,+ writes[name],+ name,+ "written-module-global",+ "a route handler writes to a module-level container, which is one "+ "object for the whole process. It has no tenant, so the read cannot "+ "be scoped and a restart loses it.",+ )+ )+ continue++ if name.startswith(SAMPLE_PREFIXES) and not guarded:+ shape = " It holds record-shaped literals." if _looks_fabricated(value) else ""+ report.findings.append(+ Finding(+ rel,+ line,+ name,+ "ungated-sample-data",+ f"named as sample data and served from a route module with no demo "+ f"gate in the file.{shape} Guard it with one of {DEMO_GUARDS[:3]}, "+ "or serve real rows.",+ )+ )++ report.stale_allowlist = [f"{path} :: {name}" for (path, name) in ALLOWED_GLOBALS if (path, name) not in used_allowlist]+ return report+++def _verdict(report: Report) -> int:+ if report.files_scanned == 0:+ print(+ "check_python_route_state: no route modules found under services/*/app/api — "+ "refusing to report a tree with nothing in it as clean",+ file=sys.stderr,+ )+ return 2++ if report.stale_allowlist:+ print("check_python_route_state: allowlist entries whose global has gone:", file=sys.stderr)+ for entry in report.stale_allowlist:+ print(f" {entry}", file=sys.stderr)+ print("Remove them; the allowlist may only shrink.", file=sys.stderr)+ return 1++ if report.findings:+ print(+ f"check_python_route_state: {len(report.findings)} route module(s) keep state in a module global or serve invented data:",+ file=sys.stderr,+ )+ for finding in report.findings:+ print(f" {finding.render()}", file=sys.stderr)+ return 1++ print(+ f"check_python_route_state: OK — {report.globals_examined} module-level container(s) "+ f"across {report.files_scanned} route module(s); none is written by a handler or "+ f"serves ungated sample data ({len(ALLOWED_GLOBALS)} allowlisted with a reason)."+ )+ return 0+++# ── Self-test ───────────────────────────────────────────────────────────────+++@dataclass(frozen=True)+class Case:+ description: str+ source: str+ expect: str | None+++def self_test_cases() -> tuple[Case, ...]:+ return (+ Case(+ "a dict a handler stores into by key — the copilot shape",+ "_CONVERSATIONS: dict = {}\nasync def chat(body):\n _CONVERSATIONS[body.id] = body\n return body\n",+ "written-module-global",+ ),+ Case(+ "a list a handler appends to — the STIX shape",+ "DEMO_INDICATORS = []\nasync def add(i):\n DEMO_INDICATORS.append(i)\n",+ "written-module-global",+ ),+ Case(+ "a list a handler inserts into — the shifts shape",+ "_MOCK_SHIFTS = []\nasync def create(s):\n _MOCK_SHIFTS.insert(0, s)\n",+ "written-module-global",+ ),+ Case(+ "a dict a handler deletes from",+ "_SAVED_SEARCHES = {}\nasync def drop(i):\n del _SAVED_SEARCHES[i]\n",+ "written-module-global",+ ),+ Case(+ "a defaultdict, which is still one object per process",+ "from collections import defaultdict\n_SEEN = defaultdict(list)\nasync def note(k):\n _SEEN[k].append(1)\n",+ "written-module-global",+ ),+ Case(+ "fabricated records read but never written, with no demo gate",+ "_MOCK_SHIFTS = [{'analyst': 'Dana Reyes', 'alerts_handled': 47, 'ticket': 'INFRA-412'}]\n"+ "async def shifts():\n return _MOCK_SHIFTS\n",+ "ungated-sample-data",+ ),+ # ── and the directions it must not fire in ──────────────────────────+ Case(+ "a frozenset constant, which is not state",+ "ALLOWED = frozenset({'a', 'b'})\nasync def go():\n return 'a' in ALLOWED\n",+ None,+ ),+ Case(+ "a read-only vocabulary map",+ "BACKEND_LABELS = {'qradar': 'IBM QRadar', 'sentinel': 'Microsoft Sentinel'}\nasync def labels():\n return BACKEND_LABELS\n",+ None,+ ),+ Case(+ "sample records behind a demo gate",+ "from app.core.demo import is_demo\n"+ "_MOCK_SHIFTS = [{'analyst': 'Dana Reyes', 'alerts_handled': 47, 'ticket': 'INFRA-412'}]\n"+ "async def shifts():\n return _MOCK_SHIFTS if is_demo() else []\n",+ None,+ ),+ Case(+ "a local dict inside a handler, which is per-request",+ "async def go():\n cache = {}\n cache['k'] = 1\n return cache\n",+ None,+ ),+ Case(+ "a module global read but never written, holding no records",+ "_LIMITS = {'max': 10}\nasync def go():\n return _LIMITS['max']\n",+ None,+ ),+ )+++def _case_results(tmp: pathlib.Path) -> list[tuple[str, bool]]:+ results: list[tuple[str, bool]] = []+ for index, case in enumerate(self_test_cases()):+ tree = tmp / f"case{index}" / "services" / "probe" / "app" / "api"+ tree.mkdir(parents=True)+ (tree / "routes.py").write_text(case.source, encoding="utf-8")+ report = inspect(tmp / f"case{index}")+ kinds = {f.kind for f in report.findings}+ if case.expect is None:+ passed = not report.findings+ detail = f"expected nothing, got {sorted(kinds)}" if not passed else ""+ else:+ passed = case.expect in kinds+ detail = f"expected {case.expect}, got {sorted(kinds)}" if not passed else ""+ results.append((f"{case.description}{f' — {detail}' if detail else ''}", passed))+ return results+++def _corpus_result(root: pathlib.Path) -> tuple[str, bool]:+ report = inspect(root)+ return (+ f"counts what it scanned ({report.globals_examined} globals in {report.files_scanned} route modules)",+ report.files_scanned > 0,+ )+++def self_test() -> int:+ with tempfile.TemporaryDirectory(prefix="aisoc-route-state-") as tmp:+ extra = _case_results(pathlib.Path(tmp))+ extra.append(_corpus_result(repo_root()))+ return self_test_main(pathlib.Path(__file__).name, ["--check"], extra)+++def main() -> int:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--check", action="store_true", help="render a verdict (default)")+ parser.add_argument(SELF_TEST_FLAG, action="store_true", dest="self_test")+ args = parser.parse_args()+ if args.self_test:+ return self_test()+ return _verdict(inspect(repo_root()))+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/scripts/check_route_authz.py b/scripts/check_route_authz.pyindex a2adc72e4..110d832fe 100644--- a/scripts/check_route_authz.py+++ b/scripts/check_route_authz.py@@ -141,7 +141,7 @@ AUTHZ_CALLS = frozenset(#: interchangeable with a tenant role. This gate reads `require_permission`#: only, so it cannot see them; `test_mssp_route_permissions.py` asserts they#: still resolve that scope.-MAX_UNAUTHORIZED = 28+MAX_UNAUTHORIZED = 26def _authorizing_names(tree: ast.Module) -> set[str]:diff --git a/services/api/app/api/v1/endpoints/shifts.py b/services/api/app/api/v1/endpoints/shifts.pydeleted file mode 100644index 07f1c44c3..000000000--- a/services/api/app/api/v1/endpoints/shifts.py+++ /dev/null@@ -1,155 +0,0 @@-"""SOC Shift Management endpoints."""--from __future__ import annotations--import uuid-from datetime import UTC, datetime, timedelta--from fastapi import APIRouter, HTTPException, Query-from pydantic import BaseModel, Field--from app.api.v1.deps import AuthUser--router = APIRouter(prefix="/shifts", tags=["shifts"])---class ShiftAnalyst(BaseModel):- id: str- name: str- role: str-- model_config = {"from_attributes": True}---class ShiftSummary(BaseModel):- id: str- name: str- started_at: str- ended_at: str | None = None- status: str- lead: ShiftAnalyst- analyst_count: int- alerts_handled: int- escalations: int- handoff_notes: str | None = None-- model_config = {"from_attributes": True}---class ShiftCreate(BaseModel):- name: str = Field(..., min_length=1, max_length=120)- analysts: list[str] = Field(default_factory=list, description="Analyst user IDs")- lead_id: str | None = None---class HandoffNotes(BaseModel):- notes: str = Field(..., min_length=1)- pending_items: list[str] = Field(default_factory=list)---_MOCK_ANALYSTS = {- "a1": ShiftAnalyst(id="a1", name="Jordan Lee", role="shift_lead"),- "a2": ShiftAnalyst(id="a2", name="Morgan Chen", role="soc_analyst"),- "a3": ShiftAnalyst(id="a3", name="Taylor Kim", role="soc_analyst"),- "a4": ShiftAnalyst(id="a4", name="Alex Rivera", role="senior_analyst"),-}--_now = datetime.now(UTC)-_MOCK_SHIFTS: list[dict] = [- {- "id": "shift-001",- "name": "Day Shift – 2026-05-07",- "started_at": (_now - timedelta(hours=6)).isoformat(),- "ended_at": None,- "status": "active",- "lead": _MOCK_ANALYSTS["a1"],- "analyst_count": 3,- "alerts_handled": 47,- "escalations": 2,- "handoff_notes": None,- },- {- "id": "shift-002",- "name": "Night Shift – 2026-05-06",- "started_at": (_now - timedelta(hours=18)).isoformat(),- "ended_at": (_now - timedelta(hours=6)).isoformat(),- "status": "completed",- "lead": _MOCK_ANALYSTS["a4"],- "analyst_count": 2,- "alerts_handled": 31,- "escalations": 1,- "handoff_notes": "3 open P2 investigations carried over. SentinelOne connector flapping – ops ticket INFRA-412 filed.",- },- {- "id": "shift-003",- "name": "Day Shift – 2026-05-06",- "started_at": (_now - timedelta(hours=30)).isoformat(),- "ended_at": (_now - timedelta(hours=18)).isoformat(),- "status": "completed",- "lead": _MOCK_ANALYSTS["a1"],- "analyst_count": 3,- "alerts_handled": 62,- "escalations": 4,- "handoff_notes": "Major phishing campaign resolved (INC-1042). New Sigma rule deployed for O365 impossible-travel.",- },-]--[email protected]("", response_model=list[ShiftSummary])-async def list_shifts(- current_user: AuthUser,- status_filter: str | None = Query(None, alias="status", description="active | completed"),- limit: int = Query(20, ge=1, le=100),-):- """Return shift summaries, newest first."""- shifts = _MOCK_SHIFTS- if status_filter:- shifts = [s for s in shifts if s["status"] == status_filter]- return [ShiftSummary(**s) for s in shifts[:limit]]--[email protected]("/current", response_model=ShiftSummary)-async def get_current_shift(current_user: AuthUser):- """Return the currently active shift."""- for s in _MOCK_SHIFTS:- if s["status"] == "active":- return ShiftSummary(**s)- raise HTTPException(status_code=404, detail="No active shift")--[email protected]("", response_model=ShiftSummary, status_code=201)-async def create_shift(- body: ShiftCreate,- current_user: AuthUser,-):- """Start a new shift."""- new_shift = {- "id": f"shift-{uuid.uuid4().hex[:8]}",- "name": body.name,- "started_at": datetime.now(UTC).isoformat(),- "ended_at": None,- "status": "active",- "lead": _MOCK_ANALYSTS.get(body.lead_id or "a1", _MOCK_ANALYSTS["a1"]),- "analyst_count": max(len(body.analysts), 1),- "alerts_handled": 0,- "escalations": 0,- "handoff_notes": None,- }- _MOCK_SHIFTS.insert(0, new_shift)- return ShiftSummary(**new_shift)--[email protected]("/{shift_id}/handoff", response_model=ShiftSummary)-async def add_handoff_notes(- shift_id: str,- body: HandoffNotes,- current_user: AuthUser,-):- """Attach handoff notes to a shift and mark it completed."""- for s in _MOCK_SHIFTS:- if s["id"] == shift_id:- s["handoff_notes"] = body.notes- s["status"] = "completed"- s["ended_at"] = datetime.now(UTC).isoformat()- return ShiftSummary(**s)- raise HTTPException(status_code=404, detail="Shift not found")diff --git a/services/api/app/api/v1/endpoints/stix_taxii.py b/services/api/app/api/v1/endpoints/stix_taxii.pyindex 49fca23a3..cc1ba5c41 100644--- a/services/api/app/api/v1/endpoints/stix_taxii.py+++ b/services/api/app/api/v1/endpoints/stix_taxii.py@@ -271,6 +271,31 @@ DEMO_TAXII_COLLECTIONS: list[TAXIICollection] = [# ── Endpoints ────────────────────────────────────────────────────────────────+def _demo_only() -> None:+ """Refuse outside demo mode.++ Everything these routes serve is invented: `DEMO_INDICATORS`,+ `DEMO_BUNDLES` and `DEMO_TAXII_COLLECTIONS` are hand-written literals,+ the POST routes append to those same module-level lists, and none of it+ is tenant-scoped — so one tenant's POST was readable by every other, and+ a restart lost the lot. It was served with no demo gate at all.++ A 404 rather than a 501, because the honest answer to "show me this+ tenant's STIX indicators" on a deployment that stores none is that there+ is no such collection. The real TAXII 2.1 server backed by the tenant+ IOC store is parity plan 6.10; when it lands, this helper and the+ literals go with it.+ """+ if not settings.AISOC_DEMO_MODE:+ raise HTTPException(+ status_code=status.HTTP_404_NOT_FOUND,+ detail=(+ "STIX and TAXII are not available on this deployment. The data these "+ "routes served was sample content, not this tenant's threat intel."+ ),+ )++@router.get("/indicators", response_model=IndicatorListResponse)async def list_indicators(user: AuthUser,@@ -279,6 +304,7 @@ async def list_indicators(label: str | None = Query(default=None),) -> IndicatorListResponse:"""List STIX 2.1 indicators from the threat intelligence store."""+ _demo_only()items = list(DEMO_INDICATORS)if label:items = [i for i in items if label in i.labels]@@ -384,7 +410,13 @@ async def create_indicator(confidence=body.confidence,labels=body.labels,)- DEMO_INDICATORS.append(indicator)+ # Not stored. The MISP push below is real: it translates the object and+ # sends it to the configured instance. The storage was not — this used+ # to append to a module-level list shared by every tenant and lost on+ # restart, so a POST looked persisted and was neither durable nor+ # private. Pushing without pretending to store is the honest half, and+ # the tenant-scoped store arrives with the real TAXII server (parity+ # plan 6.10).push_result: MispPushResult | None = Noneif _should_push(push_to_misp):@@ -396,6 +428,7 @@ async def create_indicator(@router.get("/bundles", response_model=BundleListResponse)async def list_bundles(user: AuthUser) -> BundleListResponse:"""List STIX 2.1 bundles."""+ _demo_only()return BundleListResponse(items=DEMO_BUNDLES, total=len(DEMO_BUNDLES))@@ -427,7 +460,13 @@ async def create_bundle(created=datetime.now(UTC).isoformat(),objects=body.objects,)- DEMO_BUNDLES.append(bundle)+ # Not stored. The MISP push below is real: it translates the object and+ # sends it to the configured instance. The storage was not — this used+ # to append to a module-level list shared by every tenant and lost on+ # restart, so a POST looked persisted and was neither durable nor+ # private. Pushing without pretending to store is the honest half, and+ # the tenant-scoped store arrives with the real TAXII server (parity+ # plan 6.10).push_result: MispPushResult | None = Noneif _should_push(push_to_misp):@@ -439,6 +478,7 @@ async def create_bundle(@router.get("/taxii/collections", response_model=TAXIICollectionListResponse)async def list_taxii_collections(user: AuthUser) -> TAXIICollectionListResponse:"""List TAXII 2.1 collections for server compatibility."""+ _demo_only()return TAXIICollectionListResponse(items=DEMO_TAXII_COLLECTIONS,total=len(DEMO_TAXII_COLLECTIONS),diff --git a/services/api/app/api/v1/router.py b/services/api/app/api/v1/router.pyindex fd3495b2a..4a6eb7c9a 100644--- a/services/api/app/api/v1/router.py+++ b/services/api/app/api/v1/router.py@@ -78,7 +78,6 @@ from app.api.v1.endpoints import (saved_hunts,saved_views,scim_tokens,- shifts,sla,stix_taxii,tenant_provision,@@ -310,7 +309,6 @@ api_router.include_router(llm_credentials.router)api_router.include_router(stix_taxii.router)# Shift handoff and SOC analyst scheduling-api_router.include_router(shifts.router)# Deployment configuration and air-gap bundle managementapi_router.include_router(deployment.router)diff --git a/services/api/tests/test_no_fabricated_shift_or_taxii_data.py b/services/api/tests/test_no_fabricated_shift_or_taxii_data.pynew file mode 100644index 000000000..6e605dfb1--- /dev/null+++ b/services/api/tests/test_no_fabricated_shift_or_taxii_data.py@@ -0,0 +1,102 @@+"""Neither the shift board nor the STIX routes serve invented data.++Two surfaces served hand-written records from module-level lists with no+tenant filter and no demo gate:++* `shifts.py` returned three invented shifts with named analysts, an+ `alerts_handled` count and a fabricated ticket id. `POST` inserted into+ that same list and `PUT /{id}/handoff` wrote notes into it, so one tenant+ posted a handoff and another read it.+* `stix_taxii.py` returned invented indicators, bundles and TAXII+ collections, and its `POST` routes appended to the same lists.++Neither had a caller. Nothing in `apps/web`, no SDK, and no other service+referenced either surface; the console's shift page is demo-gated and renders+its own sample data client-side. So the shift board is deleted rather than+rebuilt — a route with no caller serving data nobody entered is not a feature+with a bug — and the STIX routes answer 404 outside demo mode until the real+TAXII server backed by the tenant IOC store lands.+"""++from __future__ import annotations++import pathlib++import pytest++SERVICE_ROOT = pathlib.Path(__file__).resolve().parents[1]+REPO_ROOT = SERVICE_ROOT.parents[1]+++class TestTheShiftBoardIsGone:+ def test_the_module_no_longer_exists(self) -> None:+ module = SERVICE_ROOT / "app" / "api" / "v1" / "endpoints" / "shifts.py"+ assert not module.exists(), (+ "shifts.py is back. It served three invented shifts from a module-level list "+ "with no tenant filter, and POST and PUT wrote into that same list"+ )++ def test_nothing_mounts_it(self) -> None:+ router = (SERVICE_ROOT / "app" / "api" / "v1" / "router.py").read_text(encoding="utf-8")+ assert "shifts" not in router, "the shifts router is still mounted"++ def test_the_console_page_is_unaffected(self) -> None:+ """It never called the API: it renders its own demo-gated sample.++ Asserted so that deleting the route is not mistaken for deleting the+ page, and so a future reader does not restore the route believing the+ console needs it.+ """+ view = REPO_ROOT / "apps" / "web" / "src" / "components" / "shifts" / "ShiftsView.tsx"+ if not view.exists():+ pytest.skip("the console shift view is not in this checkout")+ source = view.read_text(encoding="utf-8")+ assert "canUseDemoData" in source, "the console shift view lost its demo gate"+ assert "/api/v1/shifts" not in source, "the console shift view now calls the deleted route"+++class TestTheStixRoutesRefuseOutsideDemoMode:+ def test_every_handler_serving_invented_data_is_gated(self) -> None:+ source = (SERVICE_ROOT / "app" / "api" / "v1" / "endpoints" / "stix_taxii.py").read_text(encoding="utf-8")+ # The three read routes, plus the helper's own definition. The two+ # POST routes are deliberately not gated: what they do is real, they+ # translate the object and push it to the configured MISP instance,+ # and they no longer append to the shared lists — so the cross-tenant+ # write is gone without a working feature going with it.+ assert source.count("_demo_only()") == 4, (+ "expected the three read handlers plus the helper definition; the POST routes push to MISP for real and must stay reachable"+ )+ assert "DEMO_INDICATORS.append" not in source, "a POST is storing into shared state again"+ assert "DEMO_BUNDLES.append" not in source, "a POST is storing into shared state again"++ def test_the_gate_refuses_rather_than_returning_empty(self) -> None:+ """404, not an empty list.++ An empty list says "this tenant has no indicators", which is a claim+ about their data. 404 says the collection does not exist here, which+ is the true statement.+ """+ source = (SERVICE_ROOT / "app" / "api" / "v1" / "endpoints" / "stix_taxii.py").read_text(encoding="utf-8")+ assert "HTTP_404_NOT_FOUND" in source+ assert "AISOC_DEMO_MODE" in source++ def test_the_gate_sits_after_the_docstring(self) -> None:+ """A statement inserted before a docstring demotes it to dead code.++ The first attempt did exactly that, which would have emptied the+ `description` these operations publish in `docs/openapi.yaml` while+ every test still passed.+ """+ import ast++ source = (SERVICE_ROOT / "app" / "api" / "v1" / "endpoints" / "stix_taxii.py").read_text(encoding="utf-8")+ gated = {"list_indicators", "list_bundles", "list_taxii_collections"}+ seen = set()+ for node in ast.walk(ast.parse(source)):+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name in gated:+ seen.add(node.name)+ first = node.body[0]+ assert isinstance(first, ast.Expr) and isinstance(first.value, ast.Constant), (+ f"{node.name} no longer opens with a docstring, so its OpenAPI description is empty"+ )+ assert seen == gated, f"handlers missing from the module: {sorted(gated - seen)}"