Commit Graph
3 Commits
Author SHA1 Message Date
Beenu Arora 3a853d16b0 fix(enrichment): authenticate /enrich callers and key the limiter on the credential (GHSA-qf6m-hgwv-65f9) (#1844)
## Summary

Fixes **GHSA-qf6m-hgwv-65f9** (medium): the Go enrichment service's
`POST /enrich` and `/enrich/bulk` authenticated nobody, and two console
Next rewrites (`/api/v1/enrichment/lookup`, `/api/v1/enrichment/bulk`)
made them same-origin reachable from any browser that could reach the
console. An unauthenticated client could run enrichment lookups, receive
threat-intel results, and spend the deployment's provider quota
(VirusTotal, AbuseIPDB, GreyNoise, …) — and because the rate limiter was
keyed on the request body's `tenant_id`, rotating that string minted a
fresh token bucket per request, so the limiter limited nothing.

## Changes

**Service-side (the boundary fix):**
- New `services/enrichment/internal/tenantauth` — a behaviour-identical
Go port of the contract the Python services vendor in
`app/security/tenant_scope.py`:
- console HS256 access tokens (alg pinned to HS256, `type == "access"`,
expiry with 30s skew, `tenant_id` claim required; placeholder secrets
from `INSECURE_SECRET_KEY_DEFAULTS` count as unset),
- or the service token (`AISOC_ENRICHMENT_SERVICE_TOKEN`, then
`AISOC_SERVICE_TOKEN`; constant-time compare) with the acting tenant
declared on `X-AiSOC-Tenant-ID` — an absent tenant is an empty scope,
never every scope,
- fail-closed 503 when neither is configured, with the same
three-condition dev bypass as the Python module (`AISOC_DEV_MODE` +
`AISOC_DEV_AUTH_BYPASS` + loopback-only `AISOC_PUBLISHED_BIND_ADDRS`).
- `/enrich` and `/enrich/bulk` sit behind the middleware (`/health`
stays open for the compose healthcheck). The rate limiter and cache are
keyed on the **authenticated** tenant; a body naming any other tenant —
or an arbitrary bucket-minting string like `"probe-a"` — is refused (403
on the single route, a named per-item error in bulk).

**Console-side (closing the public door):**
- The two rewrites are removed. Nothing in the console calls them —
`threatIntelApi.lookup` reads the tenant's own threat-intel store — and
`ENRICHMENT_URL` leaves `resolve-runtime-routes.mjs`'s operator-intent
list so setting it is not treated as something the resolver can satisfy.

**Callers (the paths that must keep working):**
- Fusion's fuse-time `AlertEnricher`, the investigator's `enrich_ioc`,
the playbook `enrich` step, and the context bundle's threat-intel fetch
now present the service token and declare the run's/alert's own tenant
on the platform header.
- Compose wires `SECRET_KEY`, `AISOC_DEV_MODE` and
`AISOC_PUBLISHED_BIND_ADDRS` into the enrichment service (it already had
`AISOC_SERVICE_TOKEN`), and the dev overlay grants it the same
deliberate bypass as the Python services.

## Tests

- `internal/tenantauth/tenantauth_test.go`: fail-closed with nothing
configured; all three dev-bypass conditions individually; valid console
token resolves tenant+role; expired / refresh-type / no-tenant /
wrong-signature / alg-none tokens refused; placeholder secret counts as
unset; service token without header 403, non-UUID header 400, declared
tenant resolves delegated; per-service override wins; `Covers` is
intersection-only.
- `internal/handler/handler_auth_test.go` + updated
`handler_ratelimit_test.go`: handlers refuse with no principal; body
cannot name another tenant; bulk items scoped individually with a named
per-item refusal; **rotating the body tenant does not mint buckets**
(the advisory's limiter PoC, inverted); per-tenant budgets still
per-tenant; nil limiter still grants.
- Python callers: fusion `test_alert_enricher.py` asserts the service
call carries the token and the alert's tenant header; agents
`test_playbook_enrich_target.py` asserts the same for the playbook step.
- Full suites: enrichment `go test ./...` ok, `go vet` + `gofmt` clean;
fusion **1229 passed**; agents **2599 passed, 219 subtests**; ruff
clean.

## Disclosure

Reported by **@naroSEC** via a repository security advisory with a
reproduction against the `full` profile. The advisory will be published
with credit once this lands in a release.
2026-11-12 11:22:12 -08:00
Beenu AroraandBeenu Arora b2cca25e2e fix(deploy): make the console's endpoints runtime-configurable and a single host reachable (#888)
* fix(deploy): make the console's endpoints runtime-configurable and reachable

A self-hoster deploying with Compose on a single host reported that setting
the documented variables changed nothing. It could not have: `next build`
freezes both halves of the console's routing. Anything prefixed
`NEXT_PUBLIC_` is inlined into the JavaScript bundle, and the destinations
returned by `rewrites()` are compiled into `.next/routes-manifest.json`.
`next start` loads the config again and logs that it did, which makes this
look configurable, but production routing is served from the manifest — so
`API_URL` was inert too. The stack worked on the bundled Compose network only
because the baked `http://api:8000` happens to be that service's DNS name
there; any other topology resolved a hostname that does not exist.

`apps/web/docker-entrypoint.sh` re-evaluates `rewrites()` against the
container's environment and rewrites the manifest before the server starts.
`next.config.js` stays the single definition of the routing table, so the
resolver duplicates no route. An address that is set and cannot be applied
stops the container and names itself rather than starting on the built-in
defaults.

Every host port also published to a literal 127.0.0.1, so the stack came up
healthy and unreachable from the browser it was meant to be used from.
`AISOC_CONSOLE_BIND_ADDR` publishes the console alone — one port is enough,
because the browser only ever talks to the console's own origin — keeping
Postgres, Redis, Kafka and Neo4j and their development passwords on loopback.

The Helm chart had the same defect and worse: it set no upstream addresses at
all, while its Services are `<release>-api`, so every console request in a
cluster resolved nowhere.

Demo mode had two flags that could disagree with nothing to consult but the
rendered page. `AISOC_DEMO_MODE` now answers for both services, a Server
Component resolves it once and hands it down so the two paints cannot differ,
and `GET /api/runtime-config` reports the answer with its source.

Verified on a live stack reached over the LAN: sign-in, a real ingested alert
rendered in the console, and no cross-origin request from the browser.

* fix(tests): keep the node path off Optional in the console gate

`shutil.which` is typed `str | None`, and narrowing it through `pytest.fail`
relies on that being inferred NoReturn, which the type-check baseline does
not do — so the subprocess argv read as `list[str | None]`. Defaulting to ""
and testing falsiness keeps the honest failure message and the narrowing
without a suppression.

---------

Co-authored-by: Beenu Arora <beenu@MacBook-Pro-3.local>
2026-09-25 17:25:13 -07:00
Beenu AroraandBeenu Arora 91472d241e feat(discoverability): machine-readable index, working MCP install, honest social cards (#880)
* feat(discoverability): machine-readable index, working MCP install, honest social cards

Make AiSOC legible to automated readers and fix the adoption path that did
not work. No README body changes — that surface is being rewritten separately.

Machine readers
- Add llms.txt and llms-full.txt at the documentation root, generated by
  scripts/generate_llms_txt.py from the artefacts that own each figure (the
  connector registry and the detection truth table) rather than hand-typed.
  --check is a CI gate; the generator self-tests that it refuses an empty tree.
- Add schema.org SoftwareApplication + WebSite JSON-LD to the docs site,
  asserting only independently checkable facts. No aggregateRating or review,
  because no such data exists.
- Add services/mcp/server.json, validated against the published MCP registry
  2025-12-11 schema. It declares no `packages` entry on purpose: that field is
  optional, and omitting it sends a directory visitor to the source instead of
  an install command that would 404.

MCP server: the installer wrote a config nothing could start
- `install` hardcoded `npx -y @aisoc/mcp serve` from every source build.
  @aisoc/mcp is not on npm, so the output parsed, wrote cleanly, reported
  success and could never launch. The test asserted the defect verbatim.
  It now resolves a launcher (`node <abs path>` from a build, `npx` from an
  installed package) with `--launcher` to force either; verified by launching
  the generated config and completing an MCP handshake against it.
- `install --verbose` wrote AISOC_VERBOSE while the server reads
  AISOC_MCP_VERBOSE, so verbose was dead in every installed config. The test
  now round-trips the written environment through resolveConfig.

Social + search surface
- apps/docs/static/img/aisoc-social-card.png held 277 bytes of SVG, so every
  crawler got image/png with SVG bytes and rendered nothing. favicon.ico had
  the same defect. Both are now real PNGs rendered from committed SVG sources
  by apps/web/scripts/render-og-images.mjs.
- The marketing OG card read "Built by Cyble", "Free forever" and a stale
  "v3 milestone" pill on the open-source project's card. Rewritten without
  them, and the metadata now points at a PNG because no major platform renders
  an SVG og:image. The landing page's OG description also pointed readers at a
  commercial hostname; removed.
- The docs keywords meta carried the commercial brand as an SEO term; removed.
- The marketing JSON-LD hardcoded "26 security sources"; now reads the
  generated CONNECTOR_COUNT.

Accuracy
- The MCP README and docs page promised npm publication "in v8.0" three major
  versions after v8.0 shipped, claimed 50 tests against a real 124, and
  asserted an audit trail that src/telemetry.ts already documents as untrue.
  Corrected, along with a competitor-framed "moat" line.
- SUPPORT.md, examples/README.md and the sandbox README told readers to
  `pip install aisoc-sandbox`, which 404s. They now give the from-source path
  and say why the registry one does not resolve.

* fix(gate): drop the now-stale hosted-hostname exemption for the landing page

`apps/web/src/app/page.tsx` was allow-listed for one occurrence: the landing
page's Open Graph description ended "join the managed waitlist at
tryaisoc.com". Removing it left the exemption covering nothing, and the gate
fails closed on a stale entry — correctly, since an exemption that covers
nothing is a standing licence for the next occurrence to slip in unreviewed.

---------

Co-authored-by: Beenu Arora <beenu@MacBook-Pro-3.local>
2026-09-25 12:39:36 -07:00