[ASM] Deduplication of vulnerabilities#3371
Conversation
andrewlock
left a comment
There was a problem hiding this comment.
LGTM, with minor comments 👍
| bool newVulnerability; | ||
| lock (vulnerabilityHashes) | ||
| { | ||
| newVulnerability = vulnerabilityHashes.Add(hashCode); |
There was a problem hiding this comment.
Just to point out, even if you don't want the extra memory of a queue, you could use a ConcurrentDictionary<int, bool> instead of a HashSet<int> to avoid all the extra locks etc.
| [Trait("RunOnWindows", "True")] | ||
| [InlineData(false)] | ||
| [InlineData(true)] | ||
| public async Task SubmitsTraces(bool deduplicationEnabled) |
There was a problem hiding this comment.
nit: I would personally prefer to re-use the existing weak cipher etc tests for this, rather than adding an extra sample. Every extra sample we add slows down the build stage, which slows down every other stage in CI. Not required, but would be preferable IMO 🙂
There was a problem hiding this comment.
Yes, I thought about it. The problem is that for deduplication, some .net versions are better than others when providing the file and line in the stack, and some provide the method name instead the file (as expected, the newest are better). This means that the behaviour of the deduplication in the already existing tests varies slightly depending on the framework because the information that it receives is slightly different. Reusing the already existing tests would require to cover a few different cases that would increase the complexity, so, finally, I decided to go for a new, very simple, test app.
| [Trait("RunOnWindows", "True")] | ||
| public async Task SubmitsTraces() | ||
| { | ||
| SetEnvironmentVariable("DD_IAST_DEDUPLICATION_ENABLED", "false"); |
There was a problem hiding this comment.
As noted above, I think it would be preferable to make these theory :)
| public class HashBasedDeduplicationTests | ||
| { | ||
| [Fact] | ||
| public void GivenTheSameVulnerabilityInstance_WhenAddedToDeduplication_OnlyOneIsStored() |
There was a problem hiding this comment.
This is not a correct usage of CollectionDefinition 🙂 But you can just delete it anyway, as this is the only type that uses it - tests within a single class are always run in serial. You only need to disable parallelization when you have multiple test classes using the same shared objects. Which you avoid wherever possible 😄
Couldn't we switch to a singleton with an internal .ctor to ease testing
+1 on this 🙂
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Andrew Lock <[email protected]>
This comment has been minimized.
This comment has been minimized.
…ithub.com/DataDog/dd-trace-dotnet into nacho/HashBasedVulnerabilityDeduplication
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Snapshots difference summaryThe following differences have been observed in committed snapshots. It is meant to help the reviewer. 62 occurrences of : + _dd.origin: iast,
|
Benchmarks Report 🐌Benchmarks for #3371 compared to master:
The following thresholds were used for comparing the benchmark speeds:
Allocation changes below 0.5% are ignored. Benchmark detailsBenchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AppSecBodyBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AspNetCoreBenchmark - Unknown 🤷 Same allocations ✔️Raw results
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️Raw results
|
Code Coverage Report 📊✔️ Merging #3371 into master will not change line coverage
View the full report for further details: Datadog.Trace Breakdown ✔️
The following classes have significant coverage changes.
The following classes were added in #3371:
View the full reports for further details: |
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return IastUtils.GetHashCode(new object?[] { Path, Line }); |
There was a problem hiding this comment.
Maybe having a two params version to skip the new object[]?
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return IastUtils.GetHashCode(new object[] { Origin, Name, Value }); |
Summary of changes
Implementation of an option, DD_IAST_DEDUPLICATION_ENABLED, enabled by default, that avoids reporting a vulnerability if it has already been reported during the execution of an App.
Reason for change
It is a requirement for all the IAST implementations across teams.
Implementation details
Test coverage
Other details