[Secrets] UI reports a saved rotate/delete as failed when the audit write throws (cache not cleared) #34

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

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

Severity Medium
Priority P2
Category Correctness & logic bugs
Status Open
Location ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets.Ui/Components/SecretEditor.razor:138 (also ConfirmDeleteModal.razor:91)

Description

In SecretEditor.SubmitAsync, Store.UpsertAsync (line 138) and the success Audit.WriteAsync (lines 140–151) sit inside the same try. Its catch (Exception) (lines 155–163) treats any throw as a failed mutation:

  • it sets _error = "Unable to add/rotate the secret.";
  • it writes a Failure audit event;
  • it leaves saved == false, so the ISecretCacheInvalidator.Invalidate and OnSaved block (lines 170–178) is skipped.

ConfirmDeleteModal.ConfirmAsync has the identical shape: DeleteAsync at line 91, audit at lines 93–104, catch at lines 108–114, and eviction skipped at lines 121–126. No UI test makes the audit writer throw; CapturingAuditWriter never fails.

Failure scenario

The audit sink (for example a SQL-backed IAuditWriter) is briefly unavailable. An operator rotates db/central to revoke a leaked credential.

  • The new ciphertext is committed and, on a replicated host, already published.
  • The UI says the rotation failed, and the audit trail records secret.rotate / Failure.
  • The local resolver keeps serving the old plaintext for the rest of its cache TTL.

The operator may retry, creating a second revision, or believe the secret is unchanged. A delete behaves the same way: the secret is tombstoned, yet it is reported as not deleted and keeps resolving from cache.

Recommendation

Move the success audit out of the mutation try. Once the store write returns, set saved = true and invalidate the cache. Then write the success audit in its own best-effort try/catch, and log when it fails. Add bUnit tests with a throwing IAuditWriter for both components.

Resolution

Unresolved.

From the scadaproj#15 shared-library review (`code-reviews/Secrets/findings.md`, **Secrets-013**), verified at 91fb2b4. Update the finding's Resolution row when fixed. | | | |--|--| | Severity | Medium | | Priority | P2 | | Category | Correctness & logic bugs | | Status | Open | | Location | `ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets.Ui/Components/SecretEditor.razor:138` (also `ConfirmDeleteModal.razor:91`) | **Description** In `SecretEditor.SubmitAsync`, `Store.UpsertAsync` (line 138) and the success `Audit.WriteAsync` (lines 140–151) sit inside the same `try`. Its `catch (Exception)` (lines 155–163) treats any throw as a failed mutation: - it sets `_error = "Unable to add/rotate the secret."`; - it writes a **Failure** audit event; - it leaves `saved == false`, so the `ISecretCacheInvalidator.Invalidate` and `OnSaved` block (lines 170–178) is skipped. `ConfirmDeleteModal.ConfirmAsync` has the identical shape: `DeleteAsync` at line 91, audit at lines 93–104, catch at lines 108–114, and eviction skipped at lines 121–126. No UI test makes the audit writer throw; `CapturingAuditWriter` never fails. **Failure scenario** The audit sink (for example a SQL-backed `IAuditWriter`) is briefly unavailable. An operator rotates `db/central` to revoke a leaked credential. - The new ciphertext is committed and, on a replicated host, already published. - The UI says the rotation failed, and the audit trail records `secret.rotate` / **Failure**. - The local resolver keeps serving the old plaintext for the rest of its cache TTL. The operator may retry, creating a second revision, or believe the secret is unchanged. A delete behaves the same way: the secret is tombstoned, yet it is reported as not deleted and keeps resolving from cache. **Recommendation** Move the success audit out of the mutation `try`. Once the store write returns, set `saved = true` and invalidate the cache. Then write the success audit in its own best-effort try/catch, and log when it fails. Add bUnit tests with a throwing `IAuditWriter` for both components. **Resolution** _Unresolved._
dohertj2 added the type:review-findingpriority:p2 labels 2026-11-09 14:39:20 -05:00
Author
Owner

Fixed on main 051bdb6 (Secrets-013 → Resolved): SecretEditor and ConfirmDeleteModal run the success audit after the store write, best-effort — an audit failure is a logged warning (never the value), the UI reports the committed change as saved and the cache is evicted. 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 051bdb6 (Secrets-013 → Resolved): SecretEditor and ConfirmDeleteModal run the success audit after the store write, best-effort — an audit failure is a logged warning (never the value), the UI reports the committed change as saved and the cache is evicted. 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.