mirror of
https://github.com/beenuar/AiSOC.git
synced 2026-11-24 08:35:46 +08:00
## 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.