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(docs): one more dead self-link, and a gate so they cannot come back (#719)
Beenu Arorab4a596ce2936
diff --git a/.github/workflows/link-check.yml b/.github/workflows/link-check.ymlindex 1918e571b..44c028de4 100644--- a/.github/workflows/link-check.yml+++ b/.github/workflows/link-check.yml@@ -21,6 +21,7 @@ on:- '**/*.mdx'- '.github/workflows/link-check.yml'- '.lycheeignore'+ - 'scripts/check_repo_self_links.py'push:branches: [main]paths:@@ -28,6 +29,7 @@ on:- '**/*.mdx'- '.github/workflows/link-check.yml'- '.lycheeignore'+ - 'scripts/check_repo_self_links.py'# External links rot without anyone touching this repo, which is how the# docs URL went stale in the first place.schedule:@@ -84,3 +86,23 @@ jobs:--accept 200,206,301,302,307,308,403,429'docs/**/*.md' 'apps/docs/docs/**/*.md' 'apps/docs/docs/**/*.mdx'fail: false++ # Hard gate, and deliberately offline. The observe tier above cannot catch+ # self-links into our own tree: it accepts 403/429, so GitHub rate-limiting+ # a request is indistinguishable from the page existing. A QA pass found+ # seven links to three orgs that do not exist plus one to a path that moved,+ # all 404s, none reported. Resolving against the checkout instead of the+ # network makes this deterministic and unrateable, so it can fail closed.+ self-links:+ name: Self-links · repo paths must exist+ runs-on: ubuntu-latest+ timeout-minutes: 5+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7++ - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0+ with:+ python-version: '3.11'++ - name: Every github.com/beenuar/AiSOC link resolves to a real path+ run: python3 scripts/check_repo_self_links.pydiff --git a/apps/docs/docs/operations/security.md b/apps/docs/docs/operations/security.mdindex f4224ea83..8c96029bc 100644--- a/apps/docs/docs/operations/security.md+++ b/apps/docs/docs/operations/security.md@@ -112,7 +112,7 @@ The model:3. RLS policies on every tenant-scoped table (`cases`, `alerts`, `connectors`, `detection_rules`, `api_keys`, `playbooks`, `audit_log`, …) enforce `tenant_id = current_tenant_id()`.4. The `FORCE ROW LEVEL SECURITY` flag ensures even the table owner is subject to the policy — there is no superuser escape hatch via the application's DB role.-If `app.current_tenant_id` is not set (e.g. an internal job that needs to operate cross-tenant), the policy permits the query. This is intentional for system-level workers but means **the application-level ORM session must always set the tenant** before serving user requests. The middleware that does this is wired in [`services/api/app/api/deps.py`](https://github.com/beenuar/AiSOC/blob/main/services/api/app/api/deps.py).+If `app.current_tenant_id` is not set (e.g. an internal job that needs to operate cross-tenant), the policy permits the query. This is intentional for system-level workers but means **the application-level ORM session must always set the tenant** before serving user requests. The middleware that does this is wired in [`services/api/app/api/v1/deps.py`](https://github.com/beenuar/AiSOC/blob/main/services/api/app/api/v1/deps.py).The `users` table is excluded from RLS deliberately — it would create a chicken-and-egg problem during authentication. Tenant filtering on `users` is enforced at the application layer through `get_current_user()`.diff --git a/scripts/check_repo_self_links.py b/scripts/check_repo_self_links.pynew file mode 100644index 000000000..5b1cb40a3--- /dev/null+++ b/scripts/check_repo_self_links.py@@ -0,0 +1,138 @@+#!/usr/bin/env python3+"""Assert every self-referential GitHub link in the docs points at a real path.++Why this exists as a separate gate from `link-check.yml`:++The lychee job already crawls the docs tree, but it cannot catch this class of+rot. It runs in observe mode (`fail: false`), and it passes+`--accept 200,206,301,302,307,308,403,429` — so a GitHub rate-limit response is+indistinguishable from a healthy page. A QA pass found seven links pointing at+three orgs that do not exist (`AiSOC-community/AiSOC`, `aisoc-community/aisoc`,+`aisoc-platform/aisoc`) plus one link to `services/api/app/api/deps.py`, a path+that moved under `v1/`. All eight were 404s that lychee never reported.++This gate is deliberately offline and deterministic: it resolves each path+against the checkout on disk instead of the network, so it cannot be rate+limited, cannot flake, and runs in well under a second.++Two properties are enforced:++1. A link into this project's own source must use the canonical `beenuar/AiSOC`+ coordinates. Any other org is a typo or a leftover from a rename.+2. The path after `blob/main/` or `tree/main/` must exist in the working tree.++Links pinned to a non-`main` ref are skipped: they may legitimately point at a+branch or tag that is not checked out.+"""++from __future__ import annotations++import re+import sys+from pathlib import Path++REPO_ROOT = Path(__file__).resolve().parent.parent++CANONICAL_OWNER = "beenuar"+CANONICAL_REPO = "AiSOC"++# `plans/cyble-aisoc/` is an archived prototype subtree kept for history; its+# links describe a repo that no longer exists and are not actionable. CodeQL+# excludes it for the same reason.+EXCLUDED_DIRS = {".git", "node_modules", "plans/cyble-aisoc"}++SEARCH_ROOTS = ("docs", "apps/docs/docs", ".")++# Matches https://github.com/<owner>/<repo>/(blob|tree)/<ref>/<path>+LINK_RE = re.compile(+ r"https://github\.com/"+ r"(?P<owner>[A-Za-z0-9_.-]+)/"+ r"(?P<repo>[A-Za-z0-9_.-]+)/"+ r"(?P<kind>blob|tree)/"+ r"(?P<ref>[A-Za-z0-9_.\-/]+?)/"+ r"(?P<path>[A-Za-z0-9_.\-/]+)"+)++# Any casing of the project name is "ours" for the purposes of the owner check;+# a link to an unrelated third-party repo is legitimate and must not be flagged.+KNOWN_STALE_OWNERS = {"aisoc-community", "aisoc-platform", "aisoc"}+++def _excluded(path: Path) -> bool:+ rel = path.relative_to(REPO_ROOT).as_posix()+ return any(rel == d or rel.startswith(f"{d}/") for d in EXCLUDED_DIRS)+++def _markdown_files() -> list[Path]:+ seen: set[Path] = set()+ for root in SEARCH_ROOTS:+ base = REPO_ROOT / root+ if not base.is_dir():+ continue+ pattern = "*.md*" if root == "." else "**/*.md*"+ for path in base.glob(pattern):+ if path.suffix in (".md", ".mdx") and not _excluded(path):+ seen.add(path)+ return sorted(seen)+++def _is_ours(owner: str, repo: str) -> bool:+ """True when the link is meant to point at this project."""+ if owner == CANONICAL_OWNER and repo == CANONICAL_REPO:+ return True+ return owner.lower() in KNOWN_STALE_OWNERS or repo.lower() == CANONICAL_REPO.lower()+++def main() -> int:+ wrong_owner: list[tuple[Path, int, str]] = []+ missing_path: list[tuple[Path, int, str]] = []++ for md in _markdown_files():+ try:+ lines = md.read_text(encoding="utf-8").splitlines()+ except UnicodeDecodeError:+ continue+ for lineno, line in enumerate(lines, start=1):+ for m in LINK_RE.finditer(line):+ owner, repo = m.group("owner"), m.group("repo")+ if not _is_ours(owner, repo):+ continue++ rel = md.relative_to(REPO_ROOT)+ if (owner, repo) != (CANONICAL_OWNER, CANONICAL_REPO):+ wrong_owner.append((rel, lineno, f"{owner}/{repo}"))+ continue++ # Only `main` can be resolved against the checkout.+ if m.group("ref") != "main":+ continue++ target = m.group("path").split("#", 1)[0].rstrip("/.,);:")+ if not target:+ continue+ if not (REPO_ROOT / target).exists():+ missing_path.append((rel, lineno, target))++ if not wrong_owner and not missing_path:+ print("check_repo_self_links: OK — every self-link resolves to a real path")+ return 0++ if wrong_owner:+ print(+ f"\n{len(wrong_owner)} link(s) use a non-canonical owner "+ f"(expected {CANONICAL_OWNER}/{CANONICAL_REPO}):"+ )+ for path, lineno, found in wrong_owner:+ print(f" {path}:{lineno} -> {found}")++ if missing_path:+ print(f"\n{len(missing_path)} link(s) point at a path that does not exist:")+ for path, lineno, target in missing_path:+ print(f" {path}:{lineno} -> {target}")++ print("\nThese render as 404s for every reader. Fix the link or the path.")+ return 1+++if __name__ == "__main__":+ sys.exit(main())