fix(secrets-ui): Add refuses an existing name; restoring a tombstone needs a second submit (scadaproj#45)
Secrets-014: SecretEditor in add mode reads the name first. A live row is refused ("already
exists. Use Rotate") with no write and no audit, so a pasted name can no longer replace a live
credential and reset its description/content type under a "secret.add" audit. A tombstoned name is
restored only when the operator submits the same name a second time after the warning.
Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -129,6 +129,22 @@
|
||||
|
||||
try
|
||||
{
|
||||
if (!IsRotate)
|
||||
{
|
||||
// Add must never silently overwrite (Secrets-014): the store's upsert replaces the
|
||||
// value, clears a tombstone and resets description/content type, and it would be
|
||||
// audited as "add". A live row is refused; a tombstone needs a second, deliberate
|
||||
// submit of the same name. (Check-then-write is not atomic; a concurrent add of the
|
||||
// same name in another session can still race — the window is the round trip.)
|
||||
StoredSecret? existing = await Store.GetAsync(name, _cts.Token);
|
||||
string? refusal = AddRefusal(name, existing);
|
||||
if (refusal is not null)
|
||||
{
|
||||
_error = refusal;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
StoredSecret row = Cipher.Encrypt(name, _value, _contentType);
|
||||
row = row with
|
||||
{
|
||||
@@ -177,6 +193,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
// The name whose tombstone the operator has been warned about; a second submit of the SAME
|
||||
// name restores it. Any other name starts over.
|
||||
private string? _restoreConfirmedFor;
|
||||
|
||||
private string? AddRefusal(SecretName name, StoredSecret? existing)
|
||||
{
|
||||
if (existing is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!existing.IsDeleted)
|
||||
{
|
||||
return $"A secret named '{name.Value}' already exists. Use Rotate to change its value.";
|
||||
}
|
||||
|
||||
if (string.Equals(_restoreConfirmedFor, name.Value, StringComparison.Ordinal))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_restoreConfirmedFor = name.Value;
|
||||
return $"A deleted secret named '{name.Value}' exists. Select Add again to restore it with this value.";
|
||||
}
|
||||
|
||||
private async Task WriteSuccessAuditAsync(string actor, string action, string target)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user