Enterprise Workflow, Proxy/Session & Database Support Inventory
Verified inventory of workflow/approval enforcement, reverse-proxy and session behaviour, and per-engine database support on `next` (post-PR #566). Every row carries path:line; unlocated capabilities are recorded as 'not found' with the search that proves it.
On this page
Status: current audit of
next. The baseline snapshot wasefa57c55eon the (now deleted)fix/enterprise-readiness-20261110branch; PR #566 is merged and every row below was re-verified against the current tree, so a reference that moved cites the symbol. Per-finding status is listed below — entries marked fixed are no longer current defects and must not be read as open risks. Rows without a reachable call site keep theirnot foundresult and the search behind it. Re-verified 2026-11-11 on the current tree: the status and evidence of every row this pass touched were checked against the code again; references that moved cite the symbol.
| Finding | Status | Evidence |
|---|---|---|
TRUSTED_PROXIES matched only exact strings — documented CIDR blocks never matched |
Fixed in PR #566 (commits 0040f073d, f2281aeaf) |
isTrustedProxyIp() in hook-utils.ts; tests/unit/security/trusted-proxy-cidr.test.ts |
Workflow publish gate unreachable for normal collections (plan.hasWorkflows never set) |
Corrected; dispatch/worker fixed; schema writer still missing (commit 5dafc3a5d; worker gate 2026-11-11) |
hasWorkflows is derived in execution-plan.ts:80-83 from workflow/reviewWorkflow/hasWorkflow/plugins, so the single-update gate is reachable; the bulk path calls assertPublishAllowed (tests/unit/services/bulk-publish-workflow-gate.test.ts). Content-package import is gated in applyImport (content-package-service.ts:1014-1067, gate :1056), again in the worker before any write (jobs/import-jobs.ts:292-334 → assertJobPublishAllowed, called at :486 for the content-package lane and :687 for the direct lane), and in the synchronous namespace lane before its write (assertCollectionImportPublishAllowed, import-jobs.ts:347-366, called from misc-namespaces.ts:308). Replace mode’s deleteMany runs after the gate. The worker fails closed with PERMANENT_FAILURE when the actor is missing (import-jobs.ts:306-310) or unresolvable (:315-319). Still open: nothing in src/ writes the workflow/hasWorkflow schema flag the gate reads (§1.3). |
Bulk write paths bypassed assertPublishAllowed |
Fixed (bulk update/batch status) | collectBulkRejections gates every publishing row on bulk update; workflow-less collections stay off the lazy import and the query; system writes and non-publish updates untouched. Bulk create still initialises the workflow after insert and has no gate (see §1.3). |
| Tenant/global session revocation had no distributed marker path; now read, not published | Partially fixed — read path is distributed; no production publisher for tenant/global | Readers now compare a session’s issued-at against user/tenant/global markers through getDistributedRevocationEpoch() (revocation-publish.server.ts:149-179, 5 s memo :34): warm LRU and the shared gate in handle-authentication.ts:305-321 / :340-348 (warm call :613), the session:<tenant>:<id> snapshot branch :709-726 (gate :715), and the store layer session-manager.ts:53-64 (:94-97, :117-120, :283-289, :321-327). publishUserRevocation() is called from auth-service.ts:1198, handlers/auth.ts:827 and auth-namespace.ts:416; publishTenantRevocation()/publishGlobalRevocation() (:100-116, :77-94) have no production caller. Remaining limits: the store branches check tenant/global but not the distributed user marker, and the memo admits up to 5 s of staleness. Tests: tests/unit/auth/revocation-read-path.test.ts (8), tests/unit/auth/revocation-distributed.test.ts (6). |
No versioned DB migrations; MongoDB has no transactions; README claims MySQL without DB_TYPE=mysql |
Still open (re-verified 2026-11-11) | find src scripts tests -name "*.sql" → 0 files; the only migrations dirs are src/plugins/{smart-importer,unified-data-hub}/migrations. Mongo declares supportsTransactions: false (mongodb/adapter-core.ts:76) and returns TRANSACTIONS_DISABLED (mongo-db-adapter.ts:225-234). README advertises “MariaDB/MySQL” (README.md:42, :63); createAdapterInstance() accepts only sqlite \| postgresql \| mariadb \| mongodb (db-init.ts:101-116). The MariaDB DDL uses CREATE INDEX IF NOT EXISTS (mariadb/adapter-core.ts:728, :2272; mariadb/schema-sync.ts:201-249) and JSON_UNQUOTE(JSON_EXTRACT(...)) expression indexes (:2248-2272), which MySQL 8 rejects. |
This page records what the source actually enforces on branch next (baseline snapshot efa57c55e). It is an inventory, not a design document: each row points at the line that does the work, and each gap points at the line where a caller can step around it.
Evidence rule. Every statement carries
path:line. A capability that could not be located is written as not found, together with the search that was run. A doc sentence, a config key or a unit test with a hand-built fixture is not evidence of enforcement — only a line on the request/write execution path counts. Method (2026-11-10). Read-only audit of the worktree. No source file was changed, nothing was committed, and no suite was executed (the host was running a performance benchmark). Test coverage below is read from the test files and frompackage.json/.github/workflows/ci.yml, not from a run.
1. Workflow and approval enforcement
1.1 What the model actually is
There are two independent status systems, and they are not synchronised:
| System | Values / shape | Where |
|---|---|---|
Entry status |
archive, draft, publish, unpublish, schedule, clone, delete — no review value |
src/content/status.ts:14-22 |
| Workflow instance | Free-form FSM states (states[], transitions[], gatePublication) owned by workflow_definitions / workflow_instances |
src/types/workflow-types.ts:6-59 |
A review workflow therefore lives only in the workflow tables. No code maps a workflow state onto entry.status: transition() writes the instance and the audit log (src/services/background/workflow-service.ts:371-419) and never touches the content row. Publishing is a separate write that is (conditionally) checked against the instance.
1.2 The single gate function and its call sites
assertPublishAllowed() (src/services/background/workflow-service.ts:503-549) is the whole approval mechanism:
- admins/super-admins short-circuit (
:509); - no definition, or
gatePublication !== true→ allow (:512); - create-path call without
entryId→ always reject (:514-520); - otherwise the instance must exist and sit in a state with
isFinal(:522-548); a missing instance is lazily enrolled and the write rejected (:526-539).
Call sites (seven):
| Caller | Line |
|---|---|
SDK collections.create |
src/services/sdk/namespaces/collections-namespace.ts:963 |
SDK collections.update |
src/services/sdk/namespaces/collections-namespace.ts:1214 |
| SDK bulk update / batch status | src/services/sdk/namespaces/collections/bulk-operations.ts:188 |
| Scheduler status transition | src/services/scheduler.ts:328 |
| Scheduled-publish sweep | src/services/background/jobs/scheduled-jobs.ts:155 |
| Content-package planning | src/services/core/content-package-service.ts:1056 |
| Background import worker | src/services/background/jobs/import-jobs.ts:277 |
1.3 Capability matrix — workflow / approval
| Capability | Status | Implementation (file:line) | Existing tests | Gap |
|---|---|---|---|---|
| Workflow definition CRUD | complete | src/services/background/workflow-service.ts:70-131 (save), :136-147 (delete), topology validation :638-653 |
tests/unit/services/workflow-service-completion.test.ts:205-300; tests/e2e/routes/config/workflows.spec.ts:59-104 |
saveWorkflow only writes workflow_definitions; it never sets the collection flag the gate reads (see next row). |
| Publish gate reachable for a normal collection | missing | Gate is consulted only when plan.hasWorkflows is true (collections-namespace.ts:957, :1207); that flag is derived solely from schema.workflow \| reviewWorkflow \| hasWorkflow \| plugins.includes("workflow") (src/services/sdk/namespaces/collections/execution-plan.ts:79-84) |
tests/unit/services/execution-plan.test.ts:122-135 — uses a literal { workflow: true } cast to Schema |
grep -rn "hasWorkflow\|reviewWorkflow" src tests → only execution-plan.ts:79-84 (readers) and collections-namespace.ts:957,1207 (use). No writer exists: nothing in src/ or src/routes/(app)/config/collectionbuilder sets those fields, and workflow is not a member of Schema (grep -n "workflow" src/content/types.ts → 0 hits). A definition in workflow_definitions alone therefore never gates publishing. Admin-only saveWorkflow (workflow-service.ts:78-80) cannot fix this. |
| Gates skipped by presence cache | partial | src/services/background/workflow-presence.ts:14-24 (60 s note), consumed at collections-namespace.ts:960, :1211 via !workflowKnownAbsent(...) |
tests/unit/services/workflow-presence.test.ts |
Cache is per process with a 60 s TTL (workflow-presence.ts:17, :47); a peer instance keeps publishing for up to 60 s after a definition is created. |
| FSM transition validity | complete | src/services/background/workflow-service.ts:300-310; no instance → 404 :288-293 |
tests/unit/sdk/workflow-namespace.test.ts:156-165 |
Instance must pre-exist; only post-write.ts:280-307 creates one, and only on create (see initialisation row). |
Transition RBAC (workflow:transition, transition.requiredRole) |
complete (service) / unreachable (REST) | Service check workflow-service.ts:314-338; permission registered :26-32; catalogue bit src/databases/auth/permission-catalog.ts:382 |
tests/unit/services/workflow-service-completion.test.ts:213-300 |
PATCH /api/workflows — the only transition route (src/routes/api/[...path]/+server.ts:118) — requires admin for every non-GET method (src/routes/api/[...path]/handlers/system/system-workflows.ts:33-34). A non-admin reviewer can never transition, so requiredRole and the base permission are dead paths over REST. |
Assignee lock (requiresAssignee) |
complete (service) | workflow-service.ts:343-369; handoff :431-488 |
tests/unit/services/workflow-service-completion.test.ts:213-300 |
Same REST/admin obstacle as above; the SDK path (src/services/sdk/namespaces/workflow-namespace.ts:60-80) bypasses the HTTP guard for in-process callers. |
| Publish-on-create (REST) | partial | src/services/sdk/namespaces/collections-namespace.ts:946-990 (isPublishing → assertPublishAllowed) |
tests/unit/services/workflow-service-completion.test.ts:175-182 |
Whole block is inside if (plan.hasWorkflows) (:957), and system: true bypasses it (:952-953). Handler never passes system (handlers/collections.ts:664-676). |
| Publish-on-update (REST/GraphQL/SDK) | partial | collections-namespace.ts:1196-1261 |
tests/unit/services/workflow-service-completion.test.ts:138-203 |
Gate runs only for an explicit status: "publish"\|"published" payload (:1199-1200, :1207). A PATCH without status on an already-published entry never consults the workflow (:1206), so content can be edited after approval without re-review. |
| Bulk create (publish) | missing | src/services/sdk/namespaces/collections/bulk-operations.ts:207-313 (executeBulkCreate) — no assertPublishAllowed call in the create path; the workflow is only initialised after insert (:305-320). The only gate call in this file is the bulk-update collector (:188). |
tests/integration/databases/bulk-operations-contract.test.ts (CRUD only); no workflow case |
POST /api/collections/:id/bulk and array-bodied POST /api/collections/:id insert status: "publish" rows with no gate and no required-field-for-publish check. Search: grep -n "assertPublishAllowed" src/services/sdk/namespaces/collections/bulk-operations.ts → 1 hit, the bulk-update collector (no create call). |
| Bulk update / batch status | fixed (bulk update/batch status) | bulk-operations.ts:136-201 — collectBulkRejections calls assertPublishAllowed per publishing row; required-fields-for-publish checked first (:177-184) |
tests/unit/services/bulk-publish-workflow-gate.test.ts |
Reached from PATCH /api/collections/:id/bulk, POST /api/collections/:id/batch {action:"status"} and PATCH /api/collections/:id/:entryId/status with {entries:[…]}. Workflow-less collections stay off the lazy import (workflowKnownAbsent). |
Scheduled publish job (publish-scheduled handler) |
partial | src/services/background/jobs/scheduled-jobs.ts:135-209; gate at :153-168; actor must exist :138-152 |
none found (grep -rn "scheduledPublishHandler" tests → 0) |
Publishes with db.content.nodes.update(node.path, …) (:182-187), i.e. outside the SDK write lane: schema validation, required fields, hooks, revisions and the widget pipeline never run. Cache invalidation is manual and best-effort (:199-202). |
| Scheduler status transition | partial | src/services/scheduler.ts:289-347; gate for publish only :325-329 |
tests/unit/services/scheduler-job.test.ts:10-54 (payload acceptance only; no execution test) |
When the job carries entryPath, the status is written directly (:330-334) — unpublish/draft/delete bypass validation/hooks/revisions entirely, and even the publish path never re-validates required fields. Actor is pinned server-side (:42-68, :302-305), which prevents impersonation but not the bypass. |
| Content-package import | fixed at planning/dispatch and in the worker | src/services/core/content-package-service.ts:1014-1067 (assertImportPublishAllowed), gate :1056; the content-package job payload is { planId, tenantId, userId, operations } and carries no duplicateStrategy (:885-894), because the plan already resolved create/update/skip/conflict. The worker re-gates both lanes before any write — content-package import-jobs.ts:396, direct :507-512 — including before replace mode’s deleteMany (:97-104), and fails closed with PERMANENT_FAILURE when payload.userId is absent (:258-262) or unresolvable (:267-271). Actors: content sync passes the operator id persisted in the job payload (never the "system" sentinel) and turns a gate block into an explicit job error naming the channel (src/services/core/content-sync-service.ts:692-751); the SDK resolves params.userId → options.userId → options.user._id (src/services/sdk/namespaces/data-operations.ts:76-85). |
tests/unit/services/content-package-workflow-gate.test.ts (9 cases: non-admin rejected, admin allowed, ungated collection unaffected, update→publish gated, background dispatch blocked, draft unaffected, unresolved/no actor fail closed); tests/unit/services/import-worker-workflow-gate.test.ts (9 cases: non-admin, replace-wipe ordering, admin, workflow-absent, missing actor, unresolvable actor, content-package round trip, pre-write gate, update upsert/skip tally); tests/unit/services/import-actor-resolution.test.ts (9 cases) |
Imported status: "publish" rows are now checked against the same gate as a normal write in both lanes, and a gate rejection writes nothing. All three former gaps are closed: ImporterNamespace.importData() resolves the actor from options.userId → options.user._id (src/services/sdk/namespaces/misc-namespaces.ts:248-260, dispatch :281-282); the backup create/restore payloads are typed (import-jobs.ts:88-116) and the restore branch re-gates before the write (import-jobs.ts:562-608); a plan conflict now fails the job permanently (import-jobs.ts:404-409) instead of counting as a skip. The synchronous namespace lane is gated too (assertCollectionImportPublishAllowed, import-jobs.ts:347-366, called misc-namespaces.ts:308; tests tests/unit/services/import-lane-gaps.test.ts). Import still bypasses hooks/enrolment/revision. |
| Smart Importer (bulk import) | missing | src/plugins/smart-importer/index.server.ts:405-414 (crud.updateOne / crud.insert), :520-522 → src/plugins/smart-importer/performance.ts:314-336 (insertMany) |
tests/unit/plugins/smart-importer/* (parser/mapping only) |
Same bypass, plus insertMany skips per-row validation. Remote import is a first-class admin feature, so the practical effect is “import anything, including published rows”. |
| Draft → publish promotion | complete | src/services/sdk/namespaces/drafts-namespace.ts:380-394 delegates to collections.create/update, so the update/create gate applies |
tests/unit/sdk/drafts-promotion-atomicity-sqlite.test.ts; tests/unit/databases/mongo-drafts-parity.test.ts |
On MongoDB promotion is not atomic (drafts-namespace.ts:251-258, :396-412) — see §3. |
| Workflow enrolment of new entries | partial | src/services/sdk/namespaces/collections/post-write.ts:280-307; needs workflowApplies(...) (a prior lookup) and !skipReturning |
tests/unit/sdk/collections-post-write.test.ts |
Entries created by the import paths above, by system: true callers (forms.ts:423) or with skipSideEffects never get an instance, so a later gate check has to lazily enrol them (workflow-service.ts:526-539) — the first publish attempt after enabling a workflow always fails once. |
| Workflow reset when approved content changes | missing | — | none found | grep -rn "resetWorkflow\|revertToDraft\|invalidateWorkflow\|demote" src → only cache invalidation (workflow-service.ts:61-65). Editing an entry whose instance sits in a final state leaves it publishable with no re-review. |
| Admin override of gate/assignee | complete (by design) | workflow-service.ts:37-39, :509, :314-315, :345 |
tests/unit/services/workflow-service-completion.test.ts:196-203 |
Documented escape hatch; not signalled in the audit record when used. |
| Transition audit trail | complete | workflow-service.ts:390-409, assign :469-485 |
tests/unit/services/workflow-service-completion.test.ts (mock asserts call) |
Audit is written after the instance update; a failure between :382-387 and :390 leaves an unaudited transition. No test for that ordering. |
| FS, state and gate unit coverage on a real engine | missing | — | all gate tests use a fake adapter: tests/unit/services/workflow-service-completion.test.ts:5,29-40 |
grep -rln "gatePublication\|assertPublishAllowed" tests/integration → 0 files. Nothing proves the gate against SQL JSON round-trips, tenant scoping or Mongo behaviour. |
2. Reverse proxy and session behaviour
2.1 Request-trust chain as implemented
getClientIp()reads the transport peer (event.getClientAddress(),src/utils/hook-utils.ts:286-295), then — only if that peer is inTRUSTED_PROXIES— reads forwarded headers in the ordercf-connecting-ip→x-real-ip→ first hop ofx-forwarded-for(:301-315). Result is memoised onlocals.__clientIp(:282-284,:317).TRUSTED_PROXIESis parsed insrc/databases/config-state.ts:439-460("all"/"*"sentinel, comma string or array, cached against a config stamp).- The peer match is
isTrustedProxyIp()(src/utils/hook-utils.ts:395-434): exact addresses and IPv4/IPv6 CIDR, IPv4-mapped IPv6 normalised (::ffff:a.b.c.d), malformed entries degrade to a harmless exact string (fail closed), and the compiled rules are cached against the parsed allowlist. - CSRF compares
Origin(orReferer) against theHostheader (src/utils/security/csrf-utils.ts:126-167), else requires theX-CSRF-Tokencookie/header pair. - With
MULTI_TENANT, the tenant id is derived from the request hostname (src/utils/tenant.ts:35-48, called fromsrc/hooks/handle-security.ts:220).
2.2 Capability matrix — proxy, sessions, multi-instance behaviour
| Capability | Status | Implementation (file:line) | Existing tests | Gap |
|---|---|---|---|---|
| Trusted-proxy allowlist | complete (except all) |
src/databases/config-state.ts:439-463; src/databases/private-config-schema.ts:71-75; matcher src/utils/hook-utils.ts:395-441 |
tests/unit/security/trusted-proxy-cidr.test.ts; tests/unit/databases/config-state-trusted-proxies.test.ts:28-58 (cache invalidation) |
Entries are exact addresses or CIDR (10.0.0.0/8, 2001:db8::/32), IPv4-mapped IPv6 normalised, malformed entries fail closed and are cached. TRUSTED_PROXIES=all/* still trusts forwarded headers from any peer, which re-opens client-IP spoofing — keep it to development. |
| Forwarded-IP spoofing resistance (HTTP) | complete | src/utils/hook-utils.ts:299-315 (headers ignored unless peer trusted); fallback 0.0.0.0 not loopback (:286-295) |
tests/unit/hooks/rate-limit.test.ts:183 (“XFF does not split a real client”); tests/unit/hooks/adversarial.test.ts |
When TRUSTED_PROXIES="all" (or a shared LB IP), the client-supplied X-Forwarded-For first hop is taken verbatim — spoofing returns for rate-limit bucketing. No test asserts behaviour for "all". |
| Forwarded-IP resistance (WebSocket) | complete | src/hooks.ws.ts:100-115 transport only; asserted in :265-291 |
tests/unit/hooks/ws-ratelimit.test.ts:42-74 |
normalizeUrl() still trusts x-forwarded-proto unconditionally (hooks.ws.ts:145-147) when rebuilding the upgrade URL; used for scheme, not for the origin comparison (:163-173), so impact is limited to isSecureCookieContext inputs at :213. |
| Host / origin validation | partial | WS: src/hooks.ws.ts:163-173 (origin host must equal request host; empty origin allowed :164); HTTP: src/utils/security/csrf-utils.ts:126-167; framework-level ORIGIN patched in vite.config.ts:1270-1285 |
tests/unit/services/scheduler-job.test.ts:56-70 (websocketOriginAllowed); tests/unit/hooks/adversarial.test.ts |
No allowlist of legal Host values anywhere (grep -rni "allowedHosts\|trustedHosts\|x-forwarded-host" src → 0 hits). The Host header is simultaneously the CSRF reference and the tenant selector (handle-security.ts:220 → tenant.ts:44-46), so a spoofed Host: acme.example.com picks the acme tenant scope for the request. |
| Session cookie flags | complete | src/routes/api/[...path]/handlers/auth.ts:250-267 (httpOnly:true, sameSite: strict\|lax, secure, 24 h); __Host- naming src/databases/auth/constants.ts:78-79; secure decision constants.ts:43-62 |
tests/unit/auth/sessions/session-cookies.test.ts:40-155 (incl. subdomain cookie-tossing :139) |
Non-secure context downgrades to SameSite=Lax and drops the __Host- prefix (auth.ts:264, constants.ts:79) — a proxy that terminates TLS without url.protocol=https (missing PROTOCOL_HEADER) yields a lax, non-Secure cookie. isSecureCookieContext mitigates in production for non-loopback hosts (constants.ts:59-62), but there is no test for “proxy + http protocol + production host”. |
| CSRF enforcement on mutating APIs | complete | REST dispatcher src/routes/api/[...path]/+server.ts:549-569; GraphQL src/routes/api/graphql/+server.ts:859-877; migration import src/routes/api/migration/import/+server.ts:43-45; preview …/preview/authorize/+server.ts:19-21 |
tests/integration/api/security-negative.test.ts; tests/unit/api/* |
Same-origin fast path accepts origin === //host (csrf-utils.ts:129) and treats loopback origin+host pairs as same-origin (:136-140); acceptable, but it means the check is a Host-header comparison, not a configured-origin comparison. |
| Session store / multi-instance sharing | partial | Default is in-memory (src/databases/auth/session-manager.ts:505-513); the Redis-backed store is only chosen when a Redis client is passed (:262-298, :300-340, :505-513) |
tests/unit/auth/session-rotation.test.ts; tests/unit/databases/relational-auth-session-mutations.test.ts |
getDefaultSessionManager() calls createSessionManager() with no argument (session-manager.ts:520-528), so the default process always gets the in-memory store even when Redis is configured; cross-instance invalidation then relies on DB session rows and the revocation markers below. |
| User-level session revocation (multi-instance) | complete | src/databases/auth/revocation-publish.server.ts:20-29 (marker prefixes, 30 d TTL) and :53-71 (publishUserRevocation); read on the warm LRU via getDistributedRevocationEpoch() (handle-authentication.ts:305-321, call :586-592) and in the session stores (session-manager.ts:94-97, :117-120, :283-289, :321-327) |
tests/unit/auth/session-rotation.test.ts; tests/unit/auth/revocation-read-path.test.ts; tests/unit/auth/revocation-distributed.test.ts |
Fail-open: a marker write failure only logs (revocation-publish.server.ts:65-69), and workers that never saw the marker still honour the DB row delete. |
| Tenant-wide / global session revocation (multi-instance) | read path shipped; publish unwired | Publishers exist (revocation-publish.server.ts:77-94 global, :100-116 tenant) but grep -rn "publishGlobalRevocation\|publishTenantRevocation" src returns only their definitions and the doc comments in revocation-epoch.ts. Readers are wired: handle-authentication.ts:305-321 (:586-592), session-manager.ts:53-64. |
tests/unit/auth/revocation-read-path.test.ts (8); tests/unit/auth/revocation-distributed.test.ts (6) |
A tenant lockout or “log out everywhere” still only reaches other nodes once a caller publishes the marker — none does today. The hook’s session:<tenant>:<id> snapshot branch (:652-671) has no revocation check at all; the store layer checks tenant/global but not the distributed user marker; the read memo admits up to 5 s of staleness (revocation-publish.server.ts:34). |
| Rate limiting (HTTP) | complete (single instance) / partial (cluster) | src/services/security/response-service.ts:537-604: Redis primary :578-587, memory fallback :586,589, key :571 |
tests/unit/hooks/rate-limit.test.ts:150-183; tests/unit/security/* |
Fallback is fail-open (:582-586 logs and continues on memory), so a Redis outage multiplies the effective limit by the instance count. The skip list excludes /login (:551-560), leaving password brute-force to the per-account lockout (src/databases/auth/auth-service.ts:932-949) rather than the WAF. |
| Rate-limit storage inspection | complete | src/services/security/state-store.ts:35-160 (svelty:sec: keys, L1 + L2 read) |
tests/unit/security/* |
Incidents are truncated to the last 100 per tenant (state-store.ts:132) — telemetry loss under attack, not an enforcement gap. |
| WebSocket connection limit across instances | partial | src/hooks.ws.ts:266-291: per-process activeConnections set (:44-52) |
tests/unit/hooks/ws-ratelimit.test.ts:76-90 |
RATE_LIMITER_WEBSOCKETS_REDIS_PREFIX is read (:268-270) but only used in a log message (:286); there is no Redis counter, so N instances allow N × maxConnsPerIp. |
| Cache invalidation across instances | complete (with Redis) / partial (without) | src/databases/cache/cache-service.ts:357-365 (subscribe), :428-436 and :988-999 (publish, guarded by isL2Ready()), node self-filter :365-366 |
tests/unit/databases/cache-service-l2-contract.test.ts:91-233 (explicit two-instance pub/sub test :196) |
Without L2 the publish branch only purges the CDN (:433-435), so a peer’s L1 keeps stale entries until its own TTL (content 120 s, entry 60 s, collection 300 s — cache-service.ts:43-57). |
| Background-job coordination | partial | Atomic claim by filtered update src/services/scheduler.ts:217-228; reaper for orphaned running rows src/services/background/jobs/job-queue-service.ts:310-348 (15 min lease); single-writer gate src/hooks.server.ts:371-393 (SVELTY_BACKGROUND_MODE=disabled\|child) |
tests/unit/services/scheduler-job.test.ts:10-54; no reaper test |
No leader election: every instance polls and relies on the claim. The scheduler’s own claim has no lease/heartbeat (scheduler.ts:217-226) — a crash leaves the row running until the job-queue reaper happens to run, and grep -rn "reapStaleRunningJobs" src shows the only caller is the queue’s own interval (job-queue-service.ts:391). |
| Schema-migration coordination | complete | src/databases/migration-lock.ts:23-59 (PG advisory lock, MariaDB GET_LOCK, SQLite file lock, Mongo lock doc); used at src/databases/postgresql/postgres-adapter.ts:105, src/databases/mariadb/mariadb-adapter.ts:111, src/databases/sqlite/adapter-core.ts:1418, and for content migrations src/services/core/migration-engine.ts:555 |
tests/unit/databases/in-memory-provision-lock.test.ts; tests/unit/databases/adapter-wrap-hot-path.test.ts |
Unknown adapter types run migrations without a lock (migration-lock.ts:51-56) — irrelevant today because only four types exist, but it is a silent degrade. |
| Fast-lane request identity | partial | vite.config.ts:1344 builds the lane request with clientAddress: a.socket?.remoteAddress \|\| "127.0.0.1" |
tests/integration/api/lane-transport-identity.test.ts |
The "127.0.0.1" fallback is a loopback address, which handle-security.ts:182-191 treats as local; combined with IS_TEST_MODE it short-circuits the WAF. In production the socket address is the proxy IP, so IP bucketing collapses to one bucket unless TRUSTED_PROXIES is set. |
3. Database support: claim versus reality
3.1 Engine matrix
| Engine | Status | Adapter (file:line) | DDL / migrations | Existing tests |
|---|---|---|---|---|
| SQLite | complete | SQLiteAdapter selected at src/databases/db-init.ts:102-104; implementation src/databases/sqlite/sqlite-adapter.ts, core …/sqlite/adapter-core.ts |
No versioned migrations. bootstrapSystemSchema("sqlite", …) guarded by withMigrationLock (sqlite/adapter-core.ts:1404-1418); per-collection DDL in …/sqlite/schema-sync.ts:93-192 |
tests/integration/databases/sqlite-adapter.test.ts; contract.test.ts; adapter-parity.test.ts; differential-parity.test.ts; transaction-contract.test.ts; tests/unit/databases/sqlite-schema-bootstrap-exec.test.ts; sqlite-statement-cache-lru.test.ts |
| PostgreSQL | complete | PostgreSQLAdapter at src/databases/db-init.ts:105-107; src/databases/postgresql/postgres-adapter.ts |
Same bootstrap path: postgres-adapter.ts:105; DDL spec src/databases/system-schema-spec.ts:37-147; column/index sync …/postgresql/schema-sync.ts; PG-only GIN indexes system-schema-spec.ts:1225-1231 |
tests/integration/databases/postgresql-adapter.test.ts; contract.test.ts; differential-parity.test.ts; tests/unit/databases/postgresql-adapter-lifecycle.test.ts; postgresql-index-usage.test.ts; postgresql-fts-adapter.test.ts; postgresql-wire-etag.test.ts |
| MariaDB | complete | MariaDBAdapter at src/databases/db-init.ts:108-110; …/mariadb/mariadb-adapter.ts (mysql2 driver :88) |
bootstrapSystemSchema("mariadb", …) under lock (mariadb-adapter.ts:107-113); …/mariadb/schema-sync.ts:93-249 |
tests/integration/databases/mariadb-adapter.test.ts; contract.test.ts; tests/unit/databases/mariadb-insert-coalescer.test.ts; mariadb-wire-etag.test.ts |
| MongoDB | complete (documents) / partial (relational features) | MongoDBAdapter at src/databases/db-init.ts:111-113; …/mongodb/mongo-db-adapter.ts |
No DDL at all: models registered on connect (…/mongodb/model-registration.ts:25-40), indexes created lazily per collection (…/mongodb/collection-module.ts:355-440) |
tests/integration/databases/mongodb-adapter.test.ts; contract.test.ts; tests/unit/databases/mongo-drafts-parity.test.ts; mongo-facet-list.test.ts; mongo-map-query.test.ts; mongo-unordered-bulk.test.ts; mongo-upsert-one-rt.test.ts |
| “MySQL” | not-found | createAdapterInstance() accepts exactly sqlite \| postgresql \| mariadb \| mongodb, everything else throws Unsupported database type (src/databases/db-init.ts:101-116) |
— | no MySQL-specific suite; grep -rn "mysql" src/databases/mariadb/*.ts returns mysql2 driver/dialect usage only (e.g. adapter-core.ts:48-51, mariadb-adapter.ts:88,97) — no MySQL adapter or DB_TYPE=mysql |
Claim under test. README.md:42 and :63 advertise ”MariaDB/MySQL”. Reality: there is no DB_TYPE=mysql, and the MariaDB path emits syntax MySQL 8 rejects — CREATE INDEX IF NOT EXISTS (src/databases/mariadb/adapter-core.ts:728, :2272; …/mariadb/schema-sync.ts:201-249) and JSON_UNQUOTE(JSON_EXTRACT(...)) expression indexes (adapter-core.ts:2248-2272). MySQL compatibility is therefore unverified and likely broken at first index creation; nothing in tests/ runs against a MySQL server (tests/docker-compose.yml profiles are mongodb, mariadb, postgresql and redis — SQLite runs in-process — and the four-entry matrix is generated in .github/workflows/db-matrix.ts:36-69).
3.2 Capability differences per engine (declared)
| Capability | PostgreSQL | MariaDB | SQLite | MongoDB | Evidence |
|---|---|---|---|---|---|
| Multi-document transactions | yes | yes | yes | no (replica set required) | postgresql/adapter-core.ts:87; mariadb/adapter-core.ts:72; sqlite/adapter-core.ts:1824; mongodb/adapter-core.ts:76 + mongo-db-adapter.ts:221-234 (TRANSACTIONS_DISABLED) |
RETURNING writes |
yes | no | yes | n/a (driver returns doc) | postgresql:96, mariadb:81, sqlite:1833, mongodb:84 |
| Native JSON column + queries | JSONB | JSON | TEXT + json_extract |
BSON | system-schema-spec.ts:145-147; sqlite/adapter-core.ts:901,1975-2032; mariadb/adapter-core.ts:184-196,330-350; supportsNativeJson flags above |
| JSON-path secondary indexes | GIN (PG only) | expression indexes (MariaDB 10.6+) | none | wildcard/compound | system-schema-spec.ts:1225-1231; mariadb/adapter-core.ts:2248-2272; sqlite has none (grep -rn "create.*Index.*json" src/databases/sqlite → 0) |
| Aggregation pipeline | subset | subset | subset | native | supportsAggregation: true for all four; unsupported stages fail closed at src/databases/core/aggregation-translator.ts (comment postgresql/adapter-core.ts:90-92) |
| Streaming / wire streaming | yes | yes | no (supportsStreaming:false) |
yes / no wire | postgresql:93,99; mariadb:78,84; sqlite:1830,1836; mongodb:82,87 |
| Full-text search | yes | yes | no (supportsFullTextSearch:false although src/databases/sqlite/fts-adapter.ts exists) |
yes | postgresql:89; mariadb:74; sqlite:1826; mongodb:79 |
| Max batch size | 1000 | 1000 | 100 | 1000 | postgresql:101; mariadb:86; sqlite:1838; mongodb:75 |
| Row-level security | opt-in, unwired; fails closed | none | none | none | postgresql/adapter-core.ts:2231-2298 implements enforceTenantPolicy, which now re-reads relrowsecurity/relforcerowsecurity/ownership and refuses to report success when the policy cannot filter; no production caller wires it. Tenant isolation is application-level (src/databases/crud-tenant-guard.ts). See the tenancy inventory §3. |
| Atomic draft promotion | yes | yes | yes | no — create-then-delete fallback | src/services/sdk/namespaces/drafts-namespace.ts:251-258, :396-412 |
| Read replicas | adapter-agnostic | adapter-agnostic | adapter-agnostic | adapter-agnostic | src/databases/db-init.ts:137-171 (DB_READ_REPLICAS, ReplicaRouterAdapter) |
3.3 How the matrix is actually exercised
| Concern | Where | Notes |
|---|---|---|
| CI matrix | .github/workflows/ci.yml:457-553; generator .github/workflows/db-matrix.ts:36-80 |
4 jobs (sqlite, postgresql, mariadb, mongodb), each runs the whole tests/integration/ tree (ci.yml:531-535) with DB_TYPE set. |
| Local parity runner | scripts/runs/run-local-db-matrix.ts:41-50 (5 suites), :67-72 (targets), :221-231 (env); package.json:162 |
Skips offline engines unless --require-all (:288-295); the header notes the pre-push hook only proves SQLite (:8-9). The hinted scripts/runs/run-all-db-matrix.ts does not exist (ls scripts/runs → run-local-db-matrix.ts only). |
| Per-suite engine gating | tests/integration/databases/adapter-test-env.ts:39-60 |
Suite runs only when DB_TYPE matches and the Docker container is up (or CI=true). |
| Transaction contract gating | tests/integration/databases/transaction-contract.test.ts:71 |
Title says “All Adapters” but there is no DB_TYPE guard and the assertions require a working commit/rollback (:77-129). On the MongoDB job the adapter returns TRANSACTIONS_DISABLED (mongo-db-adapter.ts:225-234), so either the suite fails or it silently never exercises the engine — no in-repo exclusion exists (grep -rn "transaction-contract" scripts .github → only the smart-test list in scripts/test/test-smart.ts:336). |
| Versioned DB migrations | not found | re-verified 2026-11-11: find src scripts tests -name "*.sql" → 0 files; find . -type d -name migrations → only src/plugins/*/migrations (plugin data migrations). Core schema is create-if-missing + column sync (system-schema-spec.ts, */schema-sync.ts), and MigrationEngine (src/services/core/migration-engine.ts:363) migrates content schemas, not the database. |
4. The five most important missing tests for data safety
Each case is written to fail on today’s code. Expected failure modes are the ones implied by the cited lines, not guesses.
T1 — Bulk publish bypasses the publication gate
- Target file:
tests/integration/api/workflow-bulk-gate.test.ts(new) - Precondition: collection
postswith a workflow definition wheregatePublication: trueand the entry’s instance sits in a non-final state (draft). Editor user withcollections:update, no admin.plan.hasWorkflowsmust be true (set the schema flag the gate reads, perexecution-plan.ts:79-84). - Action:
PATCH /api/collections/posts/bulkwith[{ id, data: { status: "publish" } }]; repeat withPOST /api/collections/posts/batch { action: "status", entryIds: [id], status: "publish" }; repeat withPOST /api/collections/posts/bulkcarryingstatus: "publish"rows. - Expected behaviour (now implemented for bulk update):
PATCH /api/collections/posts/bulkandPOST /api/collections/posts/batch {action:"status"}now callassertPublishAllowedper publishing row (bulk-operations.ts:186-200) and return403 WORKFLOW_PUBLISH_GATE. Bulk create (POST /api/collections/posts/bulkwithstatus: "publish"rows) still inserts without the gate — that half of the test remains open.
T2 — A workflow definition alone does not gate publishing
- Target file:
tests/integration/api/workflow-gate-reachability.test.ts(new) - Precondition: fresh database; a collection created through the normal collection-builder payload (no
workflow,hasWorkflow,reviewWorkfloworplugins: ["workflow"]fields);POST /api/workflowswithgatePublication: trueand a non-final initial state. - Action: as a non-admin editor,
POST /api/collections/postswithstatus: "publish", thenPATCH /api/collections/posts/:id { status: "publish" }. - Expected failure mode: both writes succeed and the row is published. The gate is guarded by
plan.hasWorkflows(collections-namespace.ts:957,:1207), which isfalsebecause nothing writes the flag (execution-plan.ts:79-84; no writer found bygrep -rn "hasWorkflow\|reviewWorkflow" src). The test should demand403 WORKFLOW_PUBLISH_GATEafter saving a workflow — i.e. it encodes the invariant “a saved definition is enforced, orsaveWorkflowrefuses to save”.
T3 — Editing approved content republishes without re-review
- Target file:
tests/integration/api/workflow-stale-approval.test.ts(new) - Precondition:
gatePublication: true; entry published through the workflow (instance in a final state); non-admin editor withcollections:update. - Action:
PATCH /api/collections/posts/:idwith a body that changestitle/body copy and omitsstatus; thenGETthe entry as an anonymous reader. - Expected failure mode: the public read returns the edited copy while the workflow instance is still in the final state — no transition, no re-review, no audit entry. Cause: gating only runs for an explicit publish (
collections-namespace.ts:1199-1207), andtransition()/update()never reset or re-open the instance (workflow-service.ts:371-419;post-write.ts:280-307initialises on create only). The test should require either a state reset or a rejection until the instance returns to a final state.
T4 — Scheduled transition and import paths write around the write lane
- Target file:
tests/integration/api/workflow-out-of-band-writes.test.ts(new) - Precondition: collection with a
required: truefield, a JSON field andrevision: true; astatus-transitionjob whose payload containsentryPath(scheduler.ts:35accepts it), scheduled by a real user id (:302-305). - Action: let the scheduler claim and execute the job (
scheduler.ts:212-272), then separately import a content package with apublishrow (content-package-service.ts:885-894dispatch; adapter writes at:925-950) and a Smart Importer batch (smart-importer/index.server.ts:405-414). - Expected failure mode: all three persist an entry that violates the required field / skips the revision snapshot / skips hooks and widget processing, because they call
db.content.nodes.updateorcrud.insertdirectly instead of the collections namespace (scheduler.ts:330-334;scheduled-jobs.ts:182-187;content-package-service.ts:925-950). The content-package import is now gated at planning (content-package-service.ts:1014-1067) and again in the worker before any write (import-jobs.ts:244-286, called:396/:507-512), but scheduled transitions/imports still bypass the write lane. The namespace now dispatches the actor id (misc-namespaces.ts:248-260), a planconflictfails the job permanently (import-jobs.ts:404-409), and the synchronous lane is gated too (tests/unit/services/import-lane-gaps.test.ts). Assert (a) no revision row, (b) the invalid required-field row is readable, (c) noworkflow_instancesrow was created for the imported entries.
T5 — MongoDB loses atomicity on draft promotion and bulk writes
- Target file:
tests/integration/databases/mongo-draft-promotion-atomicity.test.ts(new) - Precondition:
DB_TYPE=mongodb, collection with a unique index on a business key, an existing draft whose promotion target already exists; also a 20-rowbulkCreatewhere row 11 violates a NOT NULL-equivalent schema rule. - Action: call
drafts.promoteDraft(...)for the conflicting draft; thencollections.bulkCreatewith the mixed batch. - Expected failure mode: on Mongo the promotion runs the non-transactional path (
drafts-namespace.ts:251-258,:396-412): the live write lands first, the draft delete fails, and the caller receives “promoted but could not remove it” (:402-412) — a duplicated live row plus a stale draft.bulkCreateinserts throughbatch.bulkInsertwith no transaction (bulk-operations.ts:260-276), so a partial failure leaves the earlier rows committed while the caller sees an error. Correct behaviour: document/enforce all-or-nothing (or exposesupportsTransactions:falseto the caller and require idempotency keys). Notetransaction-contract.test.ts:71currently claims “All Adapters” while this engine returnsTRANSACTIONS_DISABLED(mongo-db-adapter.ts:225-234).
Appendix A — searches behind the “not found” rows
| Claim | Search | |
|---|---|---|
No writer for schema.workflow / hasWorkflow / reviewWorkflow |
grep -rn "hasWorkflow\|reviewWorkflow" src tests; grep -n "workflow" src/content/types.ts; grep -rn "workflow" src/routes/(app)/config/collectionbuilder |
|
| No workflow reset on content edit | grep -rn "resetWorkflow\|revertToDraft\|demote\|invalidateWorkflow\|currentState =" src |
|
| No gate in bulk paths | grep -n "assertPublishAllowed" src/services/sdk/namespaces/collections/bulk-operations.ts src/services/sdk/namespaces/collections/bulk-validation.ts |
|
| No integration test for the gate | grep -rln "gatePublication\|assertPublishAllowed" tests/integration |
|
| No CIDR proxy matching | grep -n "isProxyTrusted" -A8 src/utils/hook-utils.ts; grep -rn "10.0.0.0/8" tests/unit/databases/config-state-trusted-proxies.test.ts |
|
| No host allowlist | grep -rniE "allowedHosts\|trustedHosts\|x-forwarded-host" src |
|
| No distributed tenant/global revocation | grep -rn "revokeAllSessions\|revokeTenantSessions" src tests |
|
| No MySQL adapter | sed -n "101,116p" src/databases/db-init.ts; grep -rn "mysql" src/databases/db-init.ts |
|
| No versioned DB migrations | find src scripts tests -name "*.sql"; find . -path ./node_modules -prune -o -type d -name migrations -print |
|
| RLS never applied | grep -rn "enforceTenantPolicy" src; `grep -rniE “row.level security |
CREATE POLICY” src` |
| Runner name in the brief | ls scripts/runs → no run-all-db-matrix.ts (only run-local-db-matrix.ts) |