Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -42,7 +42,7 @@ A full review is mandatory before every major-release tag.
Explicitly **out of scope** for this document (covered by vendor agreements / operator runbooks):
- Third-party provider compromise (Stripe, Mailjet, OpenAI, Bunny CDN, S3 host)
- Third-party provider compromise (Legacy-Provider, Mailjet, OpenAI, Bunny CDN, S3 host)
- Client-device theft or physical-access attacks
- DNS hijack / registrar compromise
- Operator-laptop compromise (covered by IT-security policy, not this repository)
@@ -70,24 +70,24 @@ flowchart LR
Trust boundary: browser → web (CSRF token, origin allow-list, TLS). Boundary: web → API (signed JWT or shared session secret). Boundary: web → mail (provider API key, no PII beyond email + token).
### Stripe webhook flow
### Legacy-Provider webhook flow
```mermaid
flowchart LR
Stripe["Stripe (provider)"]
API["API /v1/webhooks/stripe"]
Legacy-Provider["Legacy-Provider (provider)"]
API["API /v1/webhooks/legacyProvider"]
Outbox[("OutboxEvent")]
Worker["Worker<br/>dispatcher"]
DB[("Postgres")]
Stripe -- "POST + Stripe-Signature header" --> API
API -- "verify signature with STRIPE_WEBHOOK_SIGNING_SECRET" --> API
Legacy-Provider -- "POST + Legacy-Provider-Signature header" --> API
API -- "verify signature with MOLLIE_API_KEY" --> API
API -- "publishOutboxEvent (FOR UPDATE SKIP LOCKED)" --> Outbox
Outbox -.-> Worker
Worker -- "apply subscription change" --> DB
Worker -- "publish cache-invalidation" -.-> DB
```
Trust boundary: Stripe → API (HMAC signature, replay window from `Stripe-Timestamp`, idempotency key recorded). Boundary: API → outbox (transactional write — no side-effects before commit). Boundary: worker → DB (per-row tenant scope).
Trust boundary: Legacy-Provider → API (HMAC signature, replay window from `Legacy-Provider-Timestamp`, idempotency key recorded). Boundary: API → outbox (transactional write — no side-effects before commit). Boundary: worker → DB (per-row tenant scope).
### AI request flow (with cost tracking + quota)
@@ -95,7 +95,7 @@ Trust boundary: Stripe → API (HMAC signature, replay window from `Stripe-Times
flowchart LR
User["User UI"]
Web["Web action / loader"]
AICost["@toolctrl/ai/cost<br/>executeLLMCall"]
AICost["@hivegrid/ai/cost<br/>executeLLMCall"]
Quota["assertTenantAICreditAccess<br/>(spend-cache, 60s TTL)"]
Provider["LLM provider<br/>(OpenAI / Scaleway / Anthropic)"]
Outbox[("outbox.ai-cost")]
@@ -112,7 +112,7 @@ flowchart LR
Worker --> DB
```
Trust boundary: user → web (auth + tenant). Boundary: web → provider (API key from `@toolctrl/config`, never read from UI code). Boundary: cost-publish → outbox (idempotency via requestId; payload sanitized — no prompt text persisted by default).
Trust boundary: user → web (auth + tenant). Boundary: web → provider (API key from `@hivegrid/config`, never read from UI code). Boundary: cost-publish → outbox (idempotency via requestId; payload sanitized — no prompt text persisted by default).
### Plugin execution flow (foundation shipped; production sign-off pending)
@@ -161,10 +161,10 @@ Each table follows the same shape: **Threat** (the STRIDE category and concrete
| --- | --- | --- | --- |
| **S** — Forged session cookie | Signed cookie via `SESSION_SECRET`, `Secure` + `HttpOnly`, SameSite resolved by runtime | `packages/config/src/session-cookie.test.ts`, `apps/web/app/utils/session.server.test.ts` | Stolen device → session theft. Mitigated operationally by short session TTL + IdP-side revoke (planned with Authentik). |
| **S** — Magic-link replay | Single-use `MagicLinkToken` with `consumedAt` and TTL; rate-limited issuance | `packages/db/prisma/schema.prisma` (`MagicLinkToken`), `apps/web/app/utils/services/magic-link.server.test.ts` | TTL window allows one-time interception via mail-provider compromise. Accepted; mitigated by Mailjet SPF/DKIM. |
| **T** — XSS via user content | React escaping by default, CSP planned (see B-005), no `dangerouslySetInnerHTML` in mutating routes | `apps/web/app/utils/csp.test.ts`, ESLint `react/no-danger` rule | CSP not yet enforced in production headers (tracked in `docs/improvement-plan` 10-compliance-polish). |
| **T** — XSS via user content | React escaping by default, CSP planned (see B-005), no `dangerouslySetInnerHTML` in mutating routes | `apps/web/app/utils/csp.test.ts`, ESLint `react/no-danger` rule | CSP not yet enforced in production headers; track via HiveGrid security ticket. |
| **T** — CSRF on browser mutation | Per-session CSRF token required on POST/PUT/PATCH/DELETE; verified header-first | `apps/web/app/utils/session-csrf-sweep.test.ts`, `docs/security/csrf-inventory.md` | None known; new mutating routes must register an inventory entry (verified by test). |
| **R** — Privileged action without audit | Mutating admin routes emit `AuditEvent` with hash-chain | `apps/web/app/routes/admin/audit-trails.test.tsx`, `verify:permission-matrix` | Full hash-chain verifier is gated by compliance-audit-export task; chain validation runs nightly. |
| **I** — Tenant-isolation leak via crafted ID | Loaders resolve tenant from session, not URL; static inventory snapshot | `verify:tenant-isolation-report`, `docs/security/tenant-isolation-report.md` | C3 runtime cross-tenant test still pending (tracked in `docs/improvement-plan`). |
| **I** — Tenant-isolation leak via crafted ID | Loaders resolve tenant from session, not URL; static inventory snapshot | `verify:tenant-isolation-report`, `docs/security/tenant-isolation-report.md` | C3 runtime cross-tenant test still pending; track via HiveGrid security ticket. |
| **I** — Secret in HTML / log | `process.env` access banned in UI routes; pino redact rules | `packages/config/src/env-access-enforcement.test.ts` | Operator must verify Sentry PII scrubbers — see `docs/security/incident-response.md`. |
| **D** — Login brute force | Sliding-window rate-limit on `/login`, structured 429 | `apps/web/app/utils/services/auth.server.test.ts` | Distributed credential stuffing still possible. Mitigated by password policy + TOTP. |
| **E** — Permission bypass | Role/permission matrix from `permissions-seed.server.ts`; role-matrix tests enforce coverage | `packages/db/src/permissions-seed.server.test.ts`, `verify:permission-matrix` | None known. |
@@ -176,7 +176,7 @@ Each table follows the same shape: **Threat** (the STRIDE category and concrete
| **S** — Forged JWT | HS256 verification with `JWT_SECRET`; refresh-path requires server-side state | `apps/api/src/auth/*.test.ts`, `verify:openapi-security` | Secret rotation runbook (see [incident-response.md](./incident-response.md)). |
| **S** — Stolen API key | Hashed lookup; `API_KEY_LEGACY_PLAINTEXT_FALLBACK=false` in production; per-tenant scope at handler | `apps/api/src/route-access-inventory.test.ts`, `docs/security/route-access-inventory.md` | Key leaked in dependency repo → mitigated by hash-only storage. |
| **T** — Idempotency replay | Idempotency keys recorded per tenant; idempotency table planned in compliance-audit-export | `apps/api/src/middleware/idempotency.test.ts` | Window between key issuance and recording. Accepted (millisecond order). |
| **T** — Inbound webhook replay | Signature verification with provider secret + timestamp window; outbox prevents double-side-effect | `apps/api/src/routes/webhooks/stripe.test.ts` | Window of `STRIPE_WEBHOOK_TOLERANCE_SECONDS` (default 300s). |
| **T** — Inbound webhook replay | Signature verification/refetch with provider secret + replay controls; outbox prevents double-side-effect | billing webhook tests | Provider-specific replay window or refetch policy. |
| **T** — SSRF via outbound webhook URL | Outbound delivery rejects RFC1918, link-local, loopback, metadata IPs | `apps/worker/src/jobs/webhook-delivery.test.ts` (block-list) | DNS rebind possible during request; mitigated by per-attempt IP resolution. |
| **R** — Repudiated admin API call | Every `/v1/admin/*` request emits AuditEvent with request-id linkage | `apps/api/src/openapi.test.ts`, `verify:permission-matrix` | None known. |
| **I** — OpenAPI exposes admin route | OpenAPI guard rejects routes without explicit auth class | `apps/api/src/openapi.test.ts`, `verify:openapi-security` | None known. |
@@ -193,7 +193,7 @@ Each table follows the same shape: **Threat** (the STRIDE category and concrete
| **T** — Queue poisoning | Each producer goes through typed `enqueueJob` with descriptor validation | `apps/worker/src/handlers.test.ts`, `apps/worker/src/enqueue.test.ts` | None known. |
| **T** — Outbox replay | `OutboxEvent.processedAt`/dispatched flag + `FOR UPDATE SKIP LOCKED` claim | `apps/worker/src/jobs/outbox-claim.test.ts` | Two workers in race window: covered by integration test. |
| **R** — Side-effect replay without audit | Outbox is the only path to external side-effects in critical flows; receivers wrap with `withOutboxIdempotency` | `apps/worker/src/jobs/outbox-dispatcher.test.ts` | Legacy direct producers still exist; migration tracked in #42 follow-ups. |
| **I** — Job payload leak | PII-redaction at enqueue (`@toolctrl/logger` redact rules); SBOM excludes payload | `packages/logger/src/redact.test.ts` | Operator must verify Sentry breadcrumb scrubbers. |
| **I** — Job payload leak | PII-redaction at enqueue (`@hivegrid/logger` redact rules); SBOM excludes payload | `packages/logger/src/redact.test.ts` | Operator must verify Sentry breadcrumb scrubbers. |
| **D** — Queue starvation | Per-group queue separation (`general`, `mail`, `import`, `webhook`) + concurrency caps + job-priority | `apps/worker/src/queues.test.ts`, `docs/architecture/job-priority.md` | Operator must size per group; see runbook. |
| **E** — Worker → DB privilege escalation | Worker connects with role limited to required tables; no admin DDL grants | `infra/postgres/init.sql` + Coolify role provisioning | Mis-grant by operator → audited via [`docs/operations/database-rollback.md`](../operations/database-rollback.md). |
@@ -234,7 +234,7 @@ Each table follows the same shape: **Threat** (the STRIDE category and concrete
| Threat | Mitigation | Evidence / Gate | Residual risk |
| --- | --- | --- | --- |
| **S** — Spoofed presigned URL | Server-side signing with provider IAM credentials; client never holds long-lived keys | `packages/storage/src/s3.test.ts` | None known. |
| **T** — Upload of malicious file | AV scanner layer 1 (magic-bytes) + layer 2 (ClamAV planned) | `packages/storage/src/av-scan.test.ts`, `docs/improvement-plan/01-tech-debt-foundation/av-scanner-layer-*.md` | Layer 2 (ClamAV) container provisioning is operator step. |
| **T** — Upload of malicious file | AV scanner layer 1 (magic-bytes) + layer 2 (ClamAV planned) | `packages/storage/src/av-scan.test.ts`, `docs/ops/asset-cdn.md` | Layer 2 (ClamAV) container provisioning is operator step. |
| **I** — Public bucket exposure | Buckets default to private; ACL test enforces | `packages/storage/src/bucket-policy.test.ts` (operator-run) | Operator must verify per environment. |
| **D** — Egress cost burn | Per-tenant rate-limit on signed-URL issuance | `packages/storage/src/rate-limit.test.ts` | Operator-side WAF + Bunny CDN absorb large bursts. |
| **E** — Cross-tenant object read | Object key prefixed with `tenant:{tenantId}/...`; loader verifies prefix matches actor's tenant | `packages/storage/src/key-scope.test.ts` | None known. |
@@ -380,17 +380,17 @@ Each table follows the same shape: **Threat** (the STRIDE category and concrete
## Cross-cutting controls
- **Secret handling** — secrets never read from UI code; `@toolctrl/config` exposes typed loaders. `.env.test` allow-listed; `.env` git-ignored. See `docs/env-access-inventory.md`.
- **Secret handling** — secrets never read from UI code; `@hivegrid/config` exposes typed loaders. `.env.test` allow-listed; `.env` git-ignored. See `docs/env-access-inventory.md`.
- **Branding / infra parametrization** — `BRAND_*` env vars and `scripts/infra-config.mjs` give forks override knobs without removing the verify-gate contract — see `docs/deployment-porting.md`.
- **Migrations** — structural Prisma diff verified via `verify:db-migrate-status`; rollback procedure documented in `docs/operations/database-rollback.md`.
- **Audit chain** — every privileged mutation emits an AuditEvent; hash-chain verifier planned in [`compliance-audit-export`](../improvement-plan/10-compliance-polish/compliance-audit-export.md) is the canonical forensics source referenced by [`incident-response.md`](./incident-response.md).
- **Audit chain** — every privileged mutation emits an AuditEvent; the planned HiveGrid hash-chain verifier is the canonical forensics source referenced by [`incident-response.md`](./incident-response.md) once it lands.
- **SBOM** — generated per build; see [`sbom.md`](./sbom.md).
## Gaps tracked in the roadmap
The following items are knowingly incomplete and tracked under the improvement plan:
The following items are knowingly incomplete and should be tracked through HiveGrid tickets:
- **B4** — Mail templates currently hardcode English subjects/bodies (`docs/improvement-plan` 04-i18n).
- **B4** — Mail templates currently hardcode English subjects/bodies.
- **B5** — `Response.json("Unauthorized", …)` style stringly errors still exist in some loaders.
- **C1 / C2** — Handler coverage below target (API < 70 %, worker < 50 %).
- **C3** — Cross-tenant runtime integration test pending.