Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2849 ApplyEventException can leak event data to logs #2854

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/CoreTests/Exceptions/ApplyEventExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Marten.Events;
using Marten.Exceptions;
using Shouldly;
using Xunit;

namespace CoreTests.Exceptions;

public class ApplyEventExceptionTests
{
public class FakeEventThatContainsSecretInformation
{
public string Secret { get; set; }
}

[Fact]
public void should_only_include_sequence_and_id_no_data()
{
var @event = new Event<FakeEventThatContainsSecretInformation>(new()
{
Secret = "very secret!!!"
});
var exception = new ApplyEventException(@event, new("inner"));

exception.Message.ShouldBe($"Failure to apply event #{@event.Sequence} Id({@event.Id})");
}
}
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/ApplyEventException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Marten.Exceptions;
public class ApplyEventException: MartenException
{
public ApplyEventException(IEvent @event, Exception innerException): base(
$"Failure to apply event #{@event.Sequence} ({@event.Data}.)", innerException)
$"Failure to apply event #{@event.Sequence} Id({@event.Id})", innerException)
Copy link
Member

@mysticmind mysticmind Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see it, depending on usage, @event.Id may or may not get set by the code using Marten lib. So in some cases, Id as a value in the exception log may not be relatable since it might have been generated internally within Marten for event persistence if it was not set.

So data leakage looks be a bit of a tricky issue to deal with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you're right, but I think its better to not have the best log message thinkable, then to have GPDR requirements broken. So maybe this logging can be improved in a future fix?

I could add the EventTypeName and StreamKey ?? StreamId

Copy link
Member

@mysticmind mysticmind Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we don't know what is GDPR related data or some sensitive data which shouldn't be logged. May be once there is support for GDPR in Marten, there could be an attribute or something which can be applied on a property or field and which can be used to redact the text while logging as well. Until then we can't have a clear cut fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we could not include Data and include other descriptive properties untill then? That will prevent sensitive data to be unintentially written, especially using records. Which is becoming the default for events as of there ease of use for the case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will see what could be a short term solution, will discuss with @jeremydmiller and @oskardudycz on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That event.Id is Marten assigned and I don't think would refer directly to any kind of PII

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That event.Id is Marten assigned and I don't think would refer directly to any kind of PII

Just having event.Id wouldn't give much details about the exception for troubleshooting purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree @mysticmind , maybe we can add the event type and event stream id in another PR

{
Event = @event;
}
Expand Down
Loading