Skip to content

armgit / AiSOC

Public Imported from GitHub
0

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.

docs: bring the SSRF guard, cases permissions and semgrep-pack procedure current with v20.0.0 (#1431)

Beenu Arora7bbcf6187a23
diff --git a/apps/docs/docs/api/rest.md b/apps/docs/docs/api/rest.md
index 372fc7d4a..477119b19 100644
--- a/apps/docs/docs/api/rest.md
+++ b/apps/docs/docs/api/rest.md
@@ -189,6 +189,24 @@ Re-keying on `(tenant_id, natural_key)` is the proper fix and needs a migration.
| `GET` | `/playbooks/{id}/runs` | Execution history |
| `POST` | `/actions/dry-run` | Simulate an action |
+Every `GET` route in the cases family requires the **`cases:read`**
+permission (v20.0.0, [GHSA-wwq7-2xvh-qgq6](https://github.com/beenuar/AiSOC/security/advisories/GHSA-wwq7-2xvh-qgq6)).
+Role-based users are unaffected — every shipped role that can see the console
+case list already carries it — but an **API key** minted with only
+`alerts:read` can no longer list cases or read their comments, timeline and
+evidence chain. If a narrowly-scoped integration key breaks on a cases `GET`
+after upgrading, add `cases:read` to its scopes.
+
+**Breaking in v20.0.0:** `POST /cases/{id}/comments` no longer accepts
+`is_system` in the request body
+([GHSA-9mc5-hqgh-j6wf](https://github.com/beenuar/AiSOC/security/advisories/GHSA-9mc5-hqgh-j6wf)).
+The field let any `cases:write` holder author a comment the console renders as
+an unattributed "System note", so it could not be preserved — system notes are
+written by the server itself. The server **ignores** the field rather than
+refusing the request, so an existing client that still sends it keeps
+succeeding; only generated SDK request types lose the property. Responses
+still carry `is_system`, now always server-assigned.
+
`PATCH` is **forward-only**. The case state machine
(`new → triaged → investigating → contained → resolved → closed`) has no
backward edge, which is what makes "this case was closed" mean something —
diff --git a/apps/docs/docs/concepts/cases.md b/apps/docs/docs/concepts/cases.md
index 96d0f1534..88b794060 100644
--- a/apps/docs/docs/concepts/cases.md
+++ b/apps/docs/docs/concepts/cases.md
@@ -53,6 +53,14 @@ so the case is not counted as terminal and active at once. Only `closed` can
be reopened; `resolved` still has a forward edge, so the route answers `409`
and tells you to use `PATCH`.
+Reading is permissioned too: every cases `GET` route requires `cases:read`
+(v20.0.0), so an API key scoped to `alerts:read` alone cannot list cases or
+read their comments, timeline and evidence chain. Case comments carry an
+`is_system` flag in responses, but it is server-assigned only — the create
+request stopped accepting it in v20.0.0, because a caller-supplied value let
+any `cases:write` holder author a comment the console renders as an
+unattributed "System note".
+
`reopen_count` exists because `reopened_at` is overwritten each time: a case
reopened four times is a different conversation from one reopened once, and a
single timestamp cannot tell them apart.
diff --git a/apps/docs/docs/deployment/env-vars.md b/apps/docs/docs/deployment/env-vars.md
index a28f91f93..2ec51de2c 100644
--- a/apps/docs/docs/deployment/env-vars.md
+++ b/apps/docs/docs/deployment/env-vars.md
@@ -44,6 +44,9 @@ The API uses bare environment variable names (no prefix). Booleans accept `true`
| `AISOC_APP_DB_PASSWORD` | _empty_ | Postgres **runtime** role (`aisoc_app`), DML only so the row-level-security policies apply to it. `make env` generates one. |
| `REDIS_PASSWORD` | _empty_ | Redis AUTH password. `REDIS_URL` references it rather than repeating it, so rotating one rotates both. `make env` generates one. |
| `CLICKHOUSE_PASSWORD` | _empty_ | ClickHouse event-lake password, referenced the same way by `CLICKHOUSE_URL`. `make env` generates one. |
+| `AISOC_SSRF_ALLOW_PRIVATE` | `false` | The API validates connector `base_url`s at create/update and webhook destinations at create, update and delivery through the SSRF guard. `true` re-admits RFC1918 / link-local destinations (never loopback, never cloud metadata) for on-prem systems. One `.env` value reaches `api`, `connectors` and `agents` in compose. |
+| `AISOC_SSRF_ALLOW_HOSTS` | — | Comma-separated **exact** hostnames the guard admits (no wildcards, no CIDR). Use it to permit one named internal SIEM or webhook without opening every private range. The cloud-metadata block list cannot be overridden by it. |
+| `AISOC_SSRF_EXTRA_BLOCKED_HOSTS` | — | Comma-separated extra hosts or IPs to deny on top of the built-in cloud-metadata block list. |
:::info A published default cannot satisfy a production guard
@@ -299,7 +302,8 @@ Source: [`services/agents/app/`](https://github.com/beenuar/AiSOC/tree/main/serv
| `OTEL_EXPORTER_OTLP_ENDPOINT` | — | OTLP collector endpoint |
| `OTEL_EXPORTER` | `otlp` | One of `otlp`, `jaeger`, `console` |
| `AISOC_SSRF_ALLOWED_SCHEMES` | `http,https` | Comma-separated list of URL schemes allowed for outbound `http_request` and `notify` playbook steps. Anything else is rejected. |
-| `AISOC_SSRF_ALLOW_PRIVATE` | `false` | When `true`, lets playbook steps reach loopback / RFC1918 / link-local destinations. Leave off in production; enable only for self-hosted webhooks on a private network. |
+| `AISOC_SSRF_ALLOW_PRIVATE` | `false` | When `true`, lets playbook steps reach RFC1918 / link-local destinations (never loopback, never cloud metadata). Leave off in production; enable only for self-hosted webhooks on a private network. Compose passes one `.env` value to every service that runs the guard — this one, `api` and `connectors` — so the three processes cannot disagree. |
+| `AISOC_SSRF_ALLOW_HOSTS` | — | Comma-separated **exact** hostnames to admit (no wildcards, no CIDR ranges). A named host skips the IP-range checks, so a single internal webhook or SIEM can be admitted without opening every private range. The cloud-metadata block list still applies — nothing can admit `169.254.169.254` or its siblings. |
| `AISOC_SSRF_EXTRA_BLOCKED_HOSTS` | — | Comma-separated extra hosts or IPs to deny in addition to the built-in cloud-metadata block list (`169.254.169.254`, `metadata.google.internal`, …). |
| `AISOC_SIEM_WRITEBACK_ENABLED` | `1` | Whether the triage worker asks the API to project a verdict onto the finding that raised the alert. Off means nothing is attempted. |
| `AISOC_AGENTS_SERVICE_TOKEN` | — | Shared secret for the API's writeback route. **Unset disables the service path**, so the worker logs a warning and posts nothing rather than failing silently. |
@@ -307,6 +311,30 @@ Source: [`services/agents/app/`](https://github.com/beenuar/AiSOC/tree/main/serv
---
+## Connectors service (`services/connectors`)
+
+Source: [`services/connectors/app/`](https://github.com/beenuar/AiSOC/tree/main/services/connectors/app)
+
+Every connector egress path — the stateless "Test connection" route, resource
+reads and scheduled polls — goes through the SSRF guard in this process
+(GHSA-cq4g-g6wp-4m2w), so a tenant-controlled `base_url` cannot reach cloud
+metadata, loopback or internal services. The guard reads the same variables
+in every service that runs it, and compose delivers them to `api`,
+`connectors` and `agents` from one `.env` value:
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `AISOC_SSRF_ALLOW_PRIVATE` | `false` | `true` re-admits connectors on RFC1918 / link-local ranges — the on-prem SIEM case. Never admits loopback or cloud metadata. |
+| `AISOC_SSRF_ALLOW_HOSTS` | — | Comma-separated **exact** hostnames to admit (no wildcards, no CIDR). A named host skips the IP-range checks; the cloud-metadata block list still applies and cannot be overridden. |
+| `AISOC_SSRF_EXTRA_BLOCKED_HOSTS` | — | Comma-separated extra hosts or IPs to deny on top of the built-in block list. |
+
+The service's port, auth and Kafka variables are set by compose and documented
+inline in `docker-compose.yml`; the connector-specific credentials (Splunk,
+CrowdStrike, …) are entered per connector instance in the console and stored
+vault-encrypted, not read from the environment.
+
+---
+
## Realtime service (`services/realtime`)
Source: [`services/realtime/src/index.ts`](https://github.com/beenuar/AiSOC/blob/main/services/realtime/src/index.ts)
diff --git a/apps/docs/docs/operations/security.md b/apps/docs/docs/operations/security.md
index ea2aea204..ac9871e8a 100644
--- a/apps/docs/docs/operations/security.md
+++ b/apps/docs/docs/operations/security.md
@@ -579,19 +579,35 @@ The important security properties:
- **Per-service credential posture.** The `api`, `agents`, `connectors`, and `realtime` services run with credentials enabled because the browser console sends a session cookie. The `ueba`, `honeytokens`, and `purple-team` services run with `allow_credentials=false` and are safe with wildcard origins even in production. The Go services (`ingest`, `enrichment`) are token-authenticated per request and also run without credentials.
- **No per-service drift.** Adding a new console subdomain means setting `AISOC_CORS_ORIGINS` once at the deployment layer — no code change in any service.
-## Playbook outbound traffic — SSRF guard
+## Outbound traffic — SSRF guard
-Playbook `http_request` and `notify` steps run inside the agents service and can reach arbitrary URLs supplied by playbook authors. To keep this from being abused as a metadata-service or internal-network pivot, every outbound URL is validated by the SSRF guard before any socket is opened:
+Three services open sockets to URLs that a tenant, a playbook author or a
+webhook configuration supplies, and all three validate every such URL through
+the same SSRF guard before any socket is opened:
+
+- **Agents** — playbook `http_request` and `notify` steps (`services/agents/app/playbook/ssrf_guard.py`; both `_handle_http` and `_handle_notify` call it first).
+- **Connectors** — every connector egress path: the stateless "Test connection" route, resource reads and scheduled polls (GHSA-cq4g-g6wp-4m2w). A tenant-controlled `base_url` cannot reach cloud metadata, loopback or internal services.
+- **API** — connector `base_url`s at create/update, before they are encrypted and stored, and outbound webhook destinations at create, update and delivery time (GHSA-898c-wxrw-hx6c).
+
+What the guard enforces:
- Only `http://` and `https://` are allowed by default (override with `AISOC_SSRF_ALLOWED_SCHEMES` if you genuinely need `https` only or an additional scheme).
- URLs that embed credentials (`https://user:pass@host`) are rejected outright.
- The hostname is resolved through `socket.getaddrinfo`; every resolved IP must be a global-unicast address. Loopback (`127.0.0.0/8`, `::1`), RFC1918 ranges, link-local, multicast, and the IETF reserved blocks are blocked.
-- Cloud metadata endpoints — `169.254.169.254`, `fd00:ec2::254`, `metadata.google.internal`, `metadata.azure.com`, `metadata`, `metadata.aws` — are blocked even if `AISOC_SSRF_ALLOW_PRIVATE=true`.
+- Cloud metadata endpoints — `169.254.169.254`, `fd00:ec2::254`, `metadata.google.internal`, `metadata.azure.com`, `metadata`, `metadata.aws` — are blocked **unconditionally**: no relax knob admits them.
- Operators can extend the deny list with `AISOC_SSRF_EXTRA_BLOCKED_HOSTS=internal-only.example.com,10.0.0.5`.
-If a playbook needs to reach a private webhook (Slack on a private network, an internal Jira, etc.), set `AISOC_SSRF_ALLOW_PRIVATE=true` **only** on the agents service and keep network-level egress controls in place. The metadata block list always applies.
+Two relax knobs exist for legitimate private infrastructure, and compose
+delivers both to all three guard-running services from one `.env` value so
+the processes cannot disagree about what an operator admitted:
-The guard is a single chokepoint at `services/agents/app/playbook/ssrf_guard.py`; both `_handle_http` and `_handle_notify` call it before the HTTP client makes any request. New action handlers that perform outbound HTTP should call `validate_outbound_url` first.
+- `AISOC_SSRF_ALLOW_PRIVATE=true` re-admits RFC1918 / link-local destinations — the on-prem SIEM or private-webhook case. It never admits loopback and never admits cloud metadata.
+- `AISOC_SSRF_ALLOW_HOSTS=splunk.corp.internal,jira.corp.internal` admits **exact** hostnames (no wildcards, no CIDR ranges). A named host skips the IP-range checks, so one internal system can be permitted without opening every private range. The metadata block list still applies.
+
+Keep network-level egress controls in place regardless; the guard is
+defence-in-depth, not a replacement for them. New action handlers or service
+code that performs outbound HTTP to configurable destinations should call
+`validate_outbound_url` first.
## Hardening checklist
@@ -682,6 +698,47 @@ Two patterns are worth documenting because they came up repeatedly during the sw
The remaining alert categories (`py/uninitialized-local-variable`, `py/side-effect-in-assert`, `py/incomplete-url-substring-sanitization`, `py/ineffectual-statement`, `py/unnecessary-lambda`, `py/mixed-returns`, `py/unused-global-variable`, `py/unused-import`) are all standard Python correctness items and the fixes were uncontroversial — see the `[Unreleased]` section of the [CHANGELOG](https://github.com/beenuar/AiSOC/blob/main/CHANGELOG.md) for the per-PR breakdown.
+## Static analysis (semgrep) — vendored rule packs
+
+Semgrep runs in `security.yml` as a **ratcheted, deliberately non-required**
+job: measured across identical trees it splits ±1 finding for reasons no
+author can act on, and a ratchet over a non-deterministic scanner fails open —
+a randomly lost finding sitting exactly at the ceiling is silent in the
+direction nobody checks. The measurements behind that decision, and the
+conditions under which requiring it would become reasonable, are recorded
+beside the ceilings in `.security/allowlist.yml`.
+
+What makes the measurement reproducible at all is that the scan does not fetch
+rules from the registry at run time. The five registry packs it uses —
+`p/security-audit`, `p/owasp-top-ten`, `p/python`, `p/typescript`, `p/react` —
+are **vendored** under `.security/semgrep/`, the scan reads the committed
+files, and the ratchet binds its ceiling to the combined digest of those packs
+(`rules_sha256` in the allowlist, printed by `vendor_semgrep_packs.py
+--digest`) — so a registry pack changing upstream cannot silently re-grade the
+tree. A ceiling whose digest cannot be established is a failure, not a skip.
+The pinned binary and the pinned rules together are the whole measurement; a
+pinned binary against unpinned rules is half a pin, and it was measured rather
+than suspected — two consecutive runs on one branch moved 103/39 → 104/40
+while the commits between them changed zero scanned files.
+
+To refresh the packs (an explicit re-measure, exactly like bumping the pinned
+scanner binary):
+
+1. `python3 scripts/vendor_semgrep_packs.py` — re-fetches the current registry
+ packs into `.security/semgrep/` and rewrites `MANIFEST.sha256`.
+2. Re-run the scan locally and re-measure the finding counts.
+3. Update the ceilings *and* the recorded `rules_sha256` in
+ `.security/allowlist.yml` in the same commit, with the measurement stated
+ in the commit message.
+
+`scripts/vendor_semgrep_packs.py --check` verifies the committed packs against
+the manifest without network access — deliberately, because a check that
+compared against the live registry would fail whenever upstream moves, which
+is exactly when the pin is doing its job. CI runs `--check` in `security.yml`,
+so a hand-edited pack fails before it can re-grade anything. Never raise a
+ceiling to make a scan pass — when a change adds findings, fix the findings or
+record why they are false positives.
+
## Reporting a vulnerability
Security issues should be reported privately via [GitHub Security Advisories](https://github.com/beenuar/AiSOC/security/advisories/new), not as public issues. We aim to acknowledge reports within 2 business days and ship a coordinated disclosure with the reporter. The [Contributing guidelines](../contributing/guidelines) cover the full process.