Skip to content

Commit

Permalink
Update redactions to use prefix instead of matching on exact ID
Browse files Browse the repository at this point in the history
  • Loading branch information
mhelleborg committed Oct 21, 2024
1 parent 6152a0d commit c56b7a3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Source/Events/Store/Redactions/Redaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace Dolittle.Runtime.Events.Store.Redactions;
/// </summary>
public class Redaction
{
public const string MagicRedactionId = "de1e7e17-bad5-da7a-fad4-fbc6ec3c0ea5";
public static readonly Guid MagicRedactionGuid = Guid.Parse(MagicRedactionId);
public const string RedactedPrefix = "de1e7e17-bad5-da7a";

public EventSourceId EventSourceId { get; }
public Event Details { get; }
public EventLogSequenceNumber EventLogSequenceNumber { get; }
public Guid TypeId { get; }

public Redaction(EventSourceId eventSourceId, Event @event, EventLogSequenceNumber eventLogSequenceNumber, Guid typeId)
public Redaction(EventSourceId eventSourceId, Event @event, EventLogSequenceNumber eventLogSequenceNumber,
Guid typeId)
{
EventSourceId = eventSourceId;
Details = @event;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class Event
public static bool TryGet(CommittedEvent evt, [NotNullWhen(true)] out Redaction? redaction)
{
redaction = default;
if (evt.Type.Id.Value != MagicRedactionGuid)
if (!IsRedactionId(evt.Type.Id))
{
return false;
}
Expand All @@ -67,17 +67,28 @@ public static bool TryGet(CommittedEvent evt, [NotNullWhen(true)] out Redaction?
return false;
}

if (!Guid.TryParse(payload.EventId, out var typeId))
if (!Guid.TryParse(payload.EventId, out var redactedTypeId))
{
return false;
}

redaction = new Redaction(evt.EventSource, payload, evt.EventLogSequenceNumber, typeId);
if (IsRedactionId(redactedTypeId))
{
// Cannot redact a redaction. This is to prevent removing logs of what has been redacted
// As redactions themselves should not contain PII, this should not be a problem
return false;
}


redaction = new Redaction(evt.EventSource, payload, evt.EventLogSequenceNumber, redactedTypeId);
return true;
}
catch // Bad payload, ignore
{
return false;
}
}

static bool IsRedactionId(Guid id) =>
id.ToString().StartsWith(RedactedPrefix, StringComparison.InvariantCultureIgnoreCase);
}

0 comments on commit c56b7a3

Please sign in to comment.