[Secrets] SqlServer extensions cannot pass contentRootPath — the store-path hole reopens in hub mode #31

Closed
opened 2026-11-09 14:39:18 -05:00 by dohertj2 · 1 comment
Owner

From the scadaproj#15 shared-library review (code-reviews/Secrets/findings.md, Secrets-002), verified at 91fb2b4. Update the finding's Resolution row when fixed.

Severity Medium
Priority P2
Category Security & secret handling
Status Open
Location ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets.Replicator.SqlServer/DependencyInjection/SqlServerSecretsServiceCollectionExtensions.cs:94 (with ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets/DependencyInjection/SecretsServiceCollectionExtensions.cs:76)

Description

Both SQL-Server extensions call the 3-arg AddZbSecrets(config, section), which uses contentRootPath: null. The validator registration is first-wins (SecretsServiceCollectionExtensions.cs:76), so:

  • If the SQL-Server extension runs first, a later 4-arg AddZbSecrets(..., contentRoot) cannot supply the content root.
  • If the 4-arg call runs first, Secrets-001 disables the replicator.

In a pre-host container (no IHostEnvironment), the under-content-root rule is therefore skipped in hub-replication mode, where the local SQLite store is migrated. This is the exact 0.6.0 hole that the 4-arg overload exists to close. The family guidance ("use the 4-arg overload at every pre-host call site") cannot be followed with these extensions, and there is no registration order that gets both behaviours right.

Failure scenario

The probe used hub mode with Secrets:SqlitePath = <contentRoot>/data/s.db. It called AddZbSecretsSqlServerReplication(cfg) and then AddZbSecrets(cfg, "Secrets", contentRoot), then resolved SqliteSecretsStoreMigrator, and no validation error was raised. The pre-host expander migrates an empty store inside the content root. The next deploy renames the directory, and the store is lost (the 2026-08-09 incident shape). Positive control: the same configuration with only the 4-arg AddZbSecrets throws OptionsValidationException.

Recommendation

Add a string? contentRootPath parameter to both SQL-Server extensions and forward it. Also make the validator registration "last explicit content root wins" rather than first-wins, for example by storing the root in an options object that each call may set.

Resolution

Unresolved.

From the scadaproj#15 shared-library review (`code-reviews/Secrets/findings.md`, **Secrets-002**), verified at 91fb2b4. Update the finding's Resolution row when fixed. | | | |--|--| | Severity | Medium | | Priority | P2 | | Category | Security & secret handling | | Status | Open | | Location | `ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets.Replicator.SqlServer/DependencyInjection/SqlServerSecretsServiceCollectionExtensions.cs:94` (with `ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets/DependencyInjection/SecretsServiceCollectionExtensions.cs:76`) | **Description** Both SQL-Server extensions call the 3-arg `AddZbSecrets(config, section)`, which uses `contentRootPath: null`. The validator registration is first-wins (`SecretsServiceCollectionExtensions.cs:76`), so: - If the SQL-Server extension runs first, a later 4-arg `AddZbSecrets(..., contentRoot)` cannot supply the content root. - If the 4-arg call runs first, Secrets-001 disables the replicator. In a pre-host container (no `IHostEnvironment`), the under-content-root rule is therefore skipped in hub-replication mode, where the local SQLite store *is* migrated. This is the exact `0.6.0` hole that the 4-arg overload exists to close. The family guidance ("use the 4-arg overload at every pre-host call site") cannot be followed with these extensions, and there is no registration order that gets both behaviours right. **Failure scenario** The probe used hub mode with `Secrets:SqlitePath = <contentRoot>/data/s.db`. It called `AddZbSecretsSqlServerReplication(cfg)` and then `AddZbSecrets(cfg, "Secrets", contentRoot)`, then resolved `SqliteSecretsStoreMigrator`, and **no validation error** was raised. The pre-host expander migrates an empty store inside the content root. The next deploy renames the directory, and the store is lost (the 2026-08-09 incident shape). Positive control: the same configuration with only the 4-arg `AddZbSecrets` throws `OptionsValidationException`. **Recommendation** Add a `string? contentRootPath` parameter to both SQL-Server extensions and forward it. Also make the validator registration "last explicit content root wins" rather than first-wins, for example by storing the root in an options object that each call may set. **Resolution** _Unresolved._
dohertj2 added the type:review-findingpriority:p2 labels 2026-11-09 14:39:18 -05:00
Author
Owner

Fixed on main 8e2d1e0 (Secrets-002 → Resolved): the three extensions take an optional trailing contentRootPath; the validator uses the last content root explicitly passed to any AddZbSecrets call (a later call without one never clears it). Before: hub-mode extension + 4-arg AddZbSecrets created the store inside the content root silently. Source-compatible; binaries built against 0.6.5 need a rebuild. Evidence: Secrets solution (5 test projects) all pass — Core 246 (1 DPAPI skip), SqlServer 60 (16 live-SQL skips), Akka 44, Grpc 196, Ui 20; each regression test fails with its fix removed. Ships in Secrets 0.6.6 (unpublished).

Fixed on main 8e2d1e0 (Secrets-002 → Resolved): the three extensions take an optional trailing contentRootPath; the validator uses the last content root explicitly passed to any AddZbSecrets call (a later call without one never clears it). Before: hub-mode extension + 4-arg AddZbSecrets created the store inside the content root silently. Source-compatible; binaries built against 0.6.5 need a rebuild. Evidence: Secrets solution (5 test projects) all pass — Core 246 (1 DPAPI skip), SqlServer 60 (16 live-SQL skips), Akka 44, Grpc 196, Ui 20; each regression test fails with its fix removed. Ships in Secrets **0.6.6 (unpublished)**.
Sign in to join this conversation.