Security: fix 6 pkg/dotc1z audit findings; harden SQLite .c1z ingestion #1160
All Vouch review confidence checks passed
Residual risk 0.34 = Change Risk (0.75) × (1 − Review Confidence (0.54)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #1160"
general
weight: 0.35
pquerna
Summary
A security audit of
pkg/dotc1z(the.c1zsync-artifact layer) reported 7 issues. This PR fixes 6 of them, each with aTestSecurity_regression test that fails before the fix and passes after it. The seventh, forged grant digests, is not a vulnerability; the reasoning is below.It also hardens SQLite
.c1zingestion. A v1 catalog that carries file-authored triggers or views now fails to open before any file-authored SQL runs. Nothing is stripped, repaired, or rewritten in the source.No new exported API. The protection is the default behavior of the functions callers already use (
dotc1z.NewStore,NewC1ZFile,NewC1File,AttachFile,CopyIsolateSync); there is nothing to opt into or out of.pkg/sync,pkg/tasks/c1api,pkg/dotc1z/c1zstore, and the Pebble engine's open path are unchanged frommain.Fixes
| # | Finding | Severity | Fix |
|---|---------|----------|-----|
| 1 | Attacker-controlled SQLite index names were interpolated unescaped into
DROP INDEXduring bulk-load open (SQL injection; arbitrary file creation throughATTACHwas demonstrated) | high |c1file.go:quoteIdentifieron index names read from the file's schema || 2 | The compactor interpolated an unvalidated
SyncIDinto the working-artifact filename. That escaped the temp dir, and the fold path then O_TRUNC-wrote the hostile base.c1zto attacker-chosen paths that persisted after cleanup | high |compactor.go: non-empty SyncIDs must match a token charset, so separators are rejected || 3 | The SQLite engine's
ListGrantsForEntitlementspage-token decoder panicked on a uint64 length wrap (decodeBatchCursorlenU+4), crashing an exported Reader RPC | medium |grants_for_entitlements.go: per-term bound check (ports the Pebble twin's fix) || 4 | Indexed-zstd extraction bypassed its budget on entry count:
raw_size==0frames extracted about 1.1M files/dirs at zero budget cost | medium |indexed.go: charge 512 B per entry against the decoded budget (mirrors tar header accounting) || 6 | A hostile sync-run keyspace turned one
ListSyncsRPC into K×O(N) full-keyspace stats scans | medium |adapter_reader.go: stats come only from the canonical fixed key, once per RPC || 7 |
LicenseProfileTrait.license_namepassed through the sanitizer verbatim, breaking the identity-stripping contract | low |handlers.go: HMAC it like every other human-readable field |Finding 5 (forged grant digests): not a vulnerability
The audit reported that a
.c1zcan carry grant-digest state that does not match its grants, and that the engine trusts it as present-means-exact. That is true, and it is not a security issue:.c1z) can write any grants they like. A forged digest gives them nothing beyond lying about the grants directly.GetEntitlementGrantDigest), to skip reconciling an entitlement whose digest matches the last reconciled value. That skip is behind a feature flag and is re-proven against the real grants within a TTL. The worst case for a wrong root is that C1 reflects that entitlement's grants late, which the writer could equally cause by withholding the grants. The digest is not an authorization input.NewStore:| Grants |
mainread-only | validating read-only |mainwritable | validating writable ||---|---|---|---|---|
| 100k | 12 ms | 462 ms | 12 ms | 240 ms |
| 1M | 74 ms | 5.86 s | 72 ms | 2.99 s |
That cost lands on every open, including the platform's read-only reader paths. That revision also had to choose between rejecting the digest states the engine itself writes (invalidated partitions, failed repairs) and loosening the check case by case. It was removed.
SQLite ingestion hardening
A
.c1zis untrusted when it is imported. For SQLite, the danger is executable schema: a file-authored trigger runs the moment the SDK's own migrations touch its table.sqlite_schema_guard.go). Rejects any persistent trigger or view anywhere in the catalog, non-table objects under SDK table names, and hidden/virtual/generated columns or hostile column names on SDK tables. It reads onlysqlite_schemaandPRAGMA table_list/table_xinfoand never executes file-authored SQL. It runs inInitTablesbefore migrations, inCopyIsolateSyncbefore the raw-copy DELETEs, and inAttachFile(ATTACH, validate, and DETACH-on-reject on one leased connection; the host is closed if that DETACH fails). This closes the v1 open-time trigger finding: a read-only open ran a file-definedRAISE(ABORT)trigger during the grant-backfill migration, andtrusted_schema=OFFdoes not disable triggers.sqlite_open.go)._pragma=trusted_schema(OFF)is set on every physical connection through the DSN. This is defense in depth; the schema guard is what blocks triggers. Callers are trusted: atrusted_schemasetting passed throughWithC1FPragmaor the caller's ownfile:URI is applied, not refused.NewC1Filecloses the raw DB on every init failure (a leaked handle per rejected file was a DoS vector). A failing SQLiteOpenStorereturns a nilc1zstore.Storeinterface instead of a typed nil.parseTimeoutSecondsclamps instead of overflowing to a negative duration.The guard reads catalog metadata only: one
sqlite_schemascan, onetable_list, and onetable_xinfoper SDK table present, independent of row count.Compatibility
- a catalog with triggers, views, view or virtual SDK tables, generated columns, or hostile column names fails to open;
-
AttachFilerejects such a catalog.sqlite_stat, ALTER-appended columns, and unrelated ordinary tables (see the legacy acceptance controls). Pebble artifacts open exactly as onmain.pkg/tasks/c1apilike every other bad-input error onmain(ErrEnvelopeTruncated,ErrMaxSizeExceeded, corrupt headers).Limits
Verification
-
TestSecurity_HostileIndexNameExecutesDDLDuringBulkLoadOpen: before the fix, the marker file was created. After it, the marker is absent and the hostile index is still dropped.-
TestSecurityCompactSyncIDFilenameEscapeFold/Overlay+ theNewCompactorrejection matrix-
TestSecurity_DecodeBatchCursorRejectsUint64WrapTokens-
TestSecurity_IndexedExtractionBudgetBoundsEntryCardinality-
TestSecurity_ListSyncsBoundedAgainstHostileSyncRunCardinality-
TestSecurity_SanitizeRewritesLicenseName-
TestSecurity_HostileTriggerRejectedOnEveryRouteandTestSecurity_HostileTriggerMarkerNeverExecutes: every public route rejects, the trigger's marker never executes, and the source envelope is byte-for-byte unchanged.-
TestSecurity_InitTablesReentryRejectsPlantedTrigger,…CopyIsolateSyncRejectsBeforeRawCopyDelete,…AttachFileRejectsHostileAttachment,…ConversionRejectsHostileV1,TestSecurity_SchemaGuardRejectionAndAcceptance. With the guard disabled, the triggers planted in the InitTables and CopyIsolateSync cases fire.-
TestSecurity_LegacyOldSchemaAcceptedAndReadsCorrectlyand…ConvertsAndIsolates: an old schema opens read-only with correct sync metadata and grants and an unchanged envelope, and bothToPebbleandCopyIsolateSyncaccept it.-
TestSecurity_InvalidVerificationClaimReadsUnverified: ingest-invariant markers this SDK can't validate read as unverified on both engines, never as an error, as onmain.-
TestOptionalPreviousSyncC1ZPath_SoftFailsnow includes a spare that the schema guard rejects: the optional path still syncs without replay, and the strict path fails.go test -short -tags=baton_lambda_support ./...andgolangci-lint(CI-pinned v2.13.2) pass locally.Notes for reviewers
needs_validationfindings that depend on deployment facts outside this repo: the v1 zstd FCS fail-fast bypass with its flat 10 GiB budget, the v3 payload budget ×100 scaling, and manifestsync_runsheap amplification.