Skip to content

Commit 20998ed

Browse files
committed
Fixed an issue where the duplicate checker plugin could dos itself.
1 parent b5dac85 commit 20998ed

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

src/Exceptionless/ExceptionlessClient.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,8 @@ public void SubmitEvent(Event ev, ContextData pluginContextData = null) {
185185

186186
var context = new EventPluginContext(this, ev, pluginContextData);
187187
EventPluginManager.Run(context);
188-
if (context.Cancel) {
189-
_log.Value.FormattedInfo(typeof(ExceptionlessClient), "Event submission cancelled by a plugin: id={0} type={1}", ev.ReferenceId, ev.Type);
188+
if (context.Cancel)
190189
return;
191-
}
192190

193191
// ensure all required data
194192
if (String.IsNullOrEmpty(ev.Type))
@@ -197,7 +195,7 @@ public void SubmitEvent(Event ev, ContextData pluginContextData = null) {
197195
ev.Date = DateTimeOffset.Now;
198196

199197
if (!OnSubmittingEvent(ev, pluginContextData)) {
200-
_log.Value.FormattedInfo(typeof(ExceptionlessClient), "Event submission cancelled by event handler: id={0} type={1}", ev.ReferenceId, ev.Type);
198+
_log.Value.FormattedInfo(typeof(ExceptionlessClient), "Event submission cancelled by event handler: refid={0} type={1} message={2}", ev.ReferenceId, ev.Type, ev.Message);
201199
return;
202200
}
203201

src/Exceptionless/Plugins/ContextData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public bool IsUnhandledError {
3838

3939
if (!(this[KnownKeys.IsUnhandledError] is bool))
4040
return false;
41-
41+
4242
return (bool)this[KnownKeys.IsUnhandledError];
4343
}
4444
}

src/Exceptionless/Plugins/Default/1010_DuplicateCheckerPlugin.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
namespace Exceptionless.Plugins.Default {
1010
[Priority(1010)]
1111
public class DuplicateCheckerPlugin : IEventPlugin, IDisposable {
12+
private const string LOG_SOURCE = nameof(DuplicateCheckerPlugin);
13+
private static readonly Type _logSourceType = typeof(DuplicateCheckerPlugin);
1214
private readonly Queue<Tuple<int, DateTimeOffset>> _processed = new Queue<Tuple<int, DateTimeOffset>>();
1315
private readonly Queue<MergedEvent> _mergedEvents = new Queue<MergedEvent>();
1416
private readonly object _lock = new object();
@@ -30,33 +32,36 @@ public DuplicateCheckerPlugin(TimeSpan? interval) {
3032
}
3133

3234
public void Run(EventPluginContext context) {
35+
if (LOG_SOURCE == context.Event.Source)
36+
return;
37+
3338
int hashCode = context.Event.GetHashCode();
3439
int count = context.Event.Count ?? 1;
35-
context.Log.FormattedTrace(typeof(DuplicateCheckerPlugin), "Checking event: {0} with hash: {1}", context.Event.Message, hashCode);
40+
context.Log.FormattedTrace(_logSourceType, "Checking event: {0} with hash: {1}", context.Event.Message, hashCode);
3641

3742
lock (_lock) {
3843
// Increment the occurrence count if the event is already queued for submission.
3944
var merged = _mergedEvents.FirstOrDefault(s => s.HashCode == hashCode);
4045
if (merged != null) {
4146
merged.IncrementCount(count);
4247
merged.UpdateDate(context.Event.Date);
43-
context.Log.FormattedInfo(typeof(DuplicateCheckerPlugin), "Ignoring duplicate event with hash: {0}", hashCode);
48+
context.Log.FormattedInfo(_logSourceType, "Ignoring duplicate event: {0} with hash: {1}", context.Event.Message, hashCode);
4449
context.Cancel = true;
4550
return;
4651
}
4752

4853
DateTimeOffset repeatWindow = DateTimeOffset.UtcNow.Subtract(_interval);
4954
if (_processed.Any(s => s.Item1 == hashCode && s.Item2 >= repeatWindow)) {
50-
context.Log.FormattedTrace(typeof(DuplicateCheckerPlugin), "Adding event with hash: {0} to cache.", hashCode);
55+
context.Log.FormattedTrace(_logSourceType, "Adding duplicate event: {0} with hash: {1} to cache for later submission.", context.Event.Message, hashCode);
5156
// This event is a duplicate for the first time, lets save it so we can delay it while keeping count
5257
_mergedEvents.Enqueue(new MergedEvent(hashCode, context, count));
5358
context.Cancel = true;
5459
return;
5560
}
5661

57-
context.Log.FormattedTrace(typeof(DuplicateCheckerPlugin), "Enqueueing event with hash: {0} to cache.", hashCode);
62+
context.Log.FormattedTrace(_logSourceType, "Enqueueing event with hash: {0} to cache.", hashCode);
5863
_processed.Enqueue(Tuple.Create(hashCode, DateTimeOffset.UtcNow));
59-
64+
6065
while (_processed.Count > 50)
6166
_processed.Dequeue();
6267
}
@@ -108,15 +113,15 @@ public void Resubmit() {
108113
_context.Event.Date = DateTimeOffset.Now;
109114

110115
if (!_context.Client.OnSubmittingEvent(_context.Event, _context.ContextData)) {
111-
_context.Log.FormattedInfo(typeof(DuplicateCheckerPlugin), "Event submission cancelled by event handler: id={0} type={1}", _context.Event.ReferenceId, _context.Event.Type);
116+
_context.Log.FormattedInfo(_logSourceType, "Event submission cancelled by event handler: id={0} type={1}", _context.Event.ReferenceId, _context.Event.Type);
112117
return;
113118
}
114119

115-
_context.Log.FormattedTrace(typeof(DuplicateCheckerPlugin), "Submitting event: type={0}{1}", _context.Event.Type, !String.IsNullOrEmpty(_context.Event.ReferenceId) ? " refid=" + _context.Event.ReferenceId : String.Empty);
120+
_context.Log.FormattedTrace(_logSourceType, "Submitting event: type={0}{1}", _context.Event.Type, !String.IsNullOrEmpty(_context.Event.ReferenceId) ? " refid=" + _context.Event.ReferenceId : String.Empty);
116121
_context.Resolver.GetEventQueue().Enqueue(_context.Event);
117122

118123
if (!String.IsNullOrEmpty(_context.Event.ReferenceId)) {
119-
_context.Log.FormattedTrace(typeof(DuplicateCheckerPlugin), "Setting last reference id: {0}", _context.Event.ReferenceId);
124+
_context.Log.FormattedTrace(_logSourceType, "Setting last reference id: {0}", _context.Event.ReferenceId);
120125
_context.Resolver.GetLastReferenceIdManager().SetLast(_context.Event.ReferenceId);
121126
}
122127

src/Exceptionless/Plugins/EventPluginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static void Run(EventPluginContext context) {
1414
try {
1515
plugin.Run(context);
1616
if (context.Cancel) {
17-
context.Log.FormattedInfo(plugin.GetType(), "Event submission cancelled by plugin: id={0} type={1}", context.Event.ReferenceId, context.Event.Type);
17+
context.Log.FormattedInfo(plugin.GetType(), "Event submission cancelled by plugin: refid={0} type={1} message={2}", context.Event.ReferenceId, context.Event.Type, context.Event.Message);
1818
return;
1919
}
2020
} catch (Exception ex) {

src/Platforms/Exceptionless.Web/RequestInfoCollector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public static RequestInfo Collect(HttpContextBase context, ExceptionlessConfigur
4343

4444
if (context.Request.Url != null)
4545
info.Port = context.Request.Url.Port;
46-
46+
4747
var exclusionList = config.DataExclusions as string[] ?? config.DataExclusions.ToArray();
4848
info.Cookies = context.Request.Cookies.ToDictionary(exclusionList);
49-
49+
5050
if (context.Request.Form.Count > 0) {
5151
info.PostData = context.Request.Form.ToDictionary(exclusionList);
5252
} else if (context.Request.ContentLength > 0) {

0 commit comments

Comments
 (0)