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

[ASM] Suspicious attacker blocking #6057

Merged
merged 6 commits into from
Oct 2, 2024

Conversation

NachoEchevarria
Copy link
Contributor

@NachoEchevarria NachoEchevarria commented Sep 19, 2024

Summary of changes

This PR adds the required code to support the suspicious attack functionality.

It has added the required code to read the exclusion data from the RC.

It also has modified the existing code regarding RC actions. Previously, if a configuration was received with an action, the configuration was stored and later sent to the WAF. If new values with an empty action array would come later, the previous action configurations would be deleted, but if a new array would come with a new action different than the previous one, we would report them both to the WAF. This behavior was making the suspicious attacker system tests fail because we would keep RC changes from previous tests. This change seems to be aligned with the behavior of other libraries.

The file AspNetBase.cs has been updated. Now, tests have more control over the used headers by allowing them to remove headers or replace previous values with new ones.

Reason for change

Implementation details

Test coverage

Other details

@andrewlock
Copy link
Member

andrewlock commented Sep 19, 2024

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing the following branches/commits:

Execution-time benchmarks measure the whole time it takes to execute a program. And are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are shown in red. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6057) - mean (72ms)  : 66, 77
     .   : milestone, 72,
    master - mean (70ms)  : 68, 73
     .   : milestone, 70,

    section CallTarget+Inlining+NGEN
    This PR (6057) - mean (1,109ms)  : 1089, 1128
     .   : milestone, 1109,
    master - mean (1,106ms)  : 1084, 1127
     .   : milestone, 1106,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6057) - mean (110ms)  : 107, 112
     .   : milestone, 110,
    master - mean (109ms)  : 105, 113
     .   : milestone, 109,

    section CallTarget+Inlining+NGEN
    This PR (6057) - mean (776ms)  : 759, 793
     .   : milestone, 776,
    master - mean (775ms)  : 754, 796
     .   : milestone, 775,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6057) - mean (93ms)  : 90, 96
     .   : milestone, 93,
    master - mean (93ms)  : 89, 96
     .   : milestone, 93,

    section CallTarget+Inlining+NGEN
    This PR (6057) - mean (730ms)  : 710, 749
     .   : milestone, 730,
    master - mean (728ms)  : 712, 744
     .   : milestone, 728,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6057) - mean (193ms)  : 177, 209
     .   : milestone, 193,
    master - mean (190ms)  : 187, 193
     .   : milestone, 190,

    section CallTarget+Inlining+NGEN
    This PR (6057) - mean (1,201ms)  : 1179, 1222
     .   : milestone, 1201,
    master - mean (1,199ms)  : 1177, 1221
     .   : milestone, 1199,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6057) - mean (276ms)  : 272, 281
     .   : milestone, 276,
    master - mean (276ms)  : 270, 282
     .   : milestone, 276,

    section CallTarget+Inlining+NGEN
    This PR (6057) - mean (942ms)  : 922, 962
     .   : milestone, 942,
    master - mean (944ms)  : 919, 969
     .   : milestone, 944,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6057) - mean (264ms)  : 261, 267
     .   : milestone, 264,
    master - mean (264ms)  : 260, 267
     .   : milestone, 264,

    section CallTarget+Inlining+NGEN
    This PR (6057) - mean (924ms)  : 900, 948
     .   : milestone, 924,
    master - mean (921ms)  : 906, 937
     .   : milestone, 921,

Loading

@andrewlock
Copy link
Member

andrewlock commented Sep 19, 2024

Benchmarks Report for appsec 🐌

Benchmarks for #6057 compared to master:

  • 1 benchmarks are slower, with geometric mean 1.923
  • 2 benchmarks have more allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.Asm.AppSecBodyBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master AllCycleSimpleBody net6.0 73.6μs 62.8ns 243ns 0.0741 0 0 6 KB
master AllCycleSimpleBody netcoreapp3.1 62.1μs 67.7ns 253ns 0.0925 0 0 6.95 KB
master AllCycleSimpleBody net472 49.5μs 52.9ns 205ns 1.31 0 0 8.34 KB
master AllCycleMoreComplexBody net6.0 79.7μs 283ns 1.1μs 0.116 0 0 9.51 KB
master AllCycleMoreComplexBody netcoreapp3.1 69.2μs 79.3ns 307ns 0.139 0 0 10.37 KB
master AllCycleMoreComplexBody net472 56.1μs 39.7ns 154ns 1.87 0.0279 0 11.85 KB
master ObjectExtractorSimpleBody net6.0 142ns 0.154ns 0.577ns 0.00396 0 0 280 B
master ObjectExtractorSimpleBody netcoreapp3.1 209ns 0.265ns 0.991ns 0.00365 0 0 272 B
master ObjectExtractorSimpleBody net472 164ns 0.0843ns 0.327ns 0.0446 0 0 281 B
master ObjectExtractorMoreComplexBody net6.0 3.17μs 2.13ns 7.68ns 0.0523 0 0 3.78 KB
master ObjectExtractorMoreComplexBody netcoreapp3.1 3.95μs 2.63ns 10.2ns 0.0497 0 0 3.69 KB
master ObjectExtractorMoreComplexBody net472 3.77μs 3.43ns 13.3ns 0.601 0.00564 0 3.8 KB
#6057 AllCycleSimpleBody net6.0 74.4μs 268ns 1.04μs 0.0723 0 0 6.01 KB
#6057 AllCycleSimpleBody netcoreapp3.1 63μs 89.6ns 347ns 0.0941 0 0 6.95 KB
#6057 AllCycleSimpleBody net472 48.8μs 48.8ns 183ns 1.32 0 0 8.34 KB
#6057 AllCycleMoreComplexBody net6.0 77.5μs 84.5ns 327ns 0.116 0 0 9.51 KB
#6057 AllCycleMoreComplexBody netcoreapp3.1 68.6μs 71.6ns 277ns 0.137 0 0 10.36 KB
#6057 AllCycleMoreComplexBody net472 55.3μs 62.5ns 242ns 1.87 0.0275 0 11.85 KB
#6057 ObjectExtractorSimpleBody net6.0 141ns 0.13ns 0.504ns 0.00391 0 0 280 B
#6057 ObjectExtractorSimpleBody netcoreapp3.1 194ns 0.148ns 0.535ns 0.00363 0 0 272 B
#6057 ObjectExtractorSimpleBody net472 164ns 0.0753ns 0.291ns 0.0446 0 0 281 B
#6057 ObjectExtractorMoreComplexBody net6.0 3.07μs 1.73ns 6.48ns 0.0537 0 0 3.78 KB
#6057 ObjectExtractorMoreComplexBody netcoreapp3.1 3.95μs 1.99ns 7.71ns 0.0495 0 0 3.69 KB
#6057 ObjectExtractorMoreComplexBody net472 3.8μs 2.86ns 10.7ns 0.603 0.00567 0 3.8 KB
Benchmarks.Trace.Asm.AppSecEncoderBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EncodeArgs net6.0 38.2μs 14ns 54.3ns 0.453 0 0 32.4 KB
master EncodeArgs netcoreapp3.1 54.6μs 22.8ns 85.5ns 0.436 0 0 32.4 KB
master EncodeArgs net472 66.2μs 23.9ns 92.5ns 5.15 0.066 0 32.5 KB
master EncodeLegacyArgs net6.0 80.6μs 437ns 2.39μs 0 0 0 2.14 KB
master EncodeLegacyArgs netcoreapp3.1 105μs 119ns 462ns 0 0 0 2.14 KB
master EncodeLegacyArgs net472 149μs 81.5ns 316ns 0.3 0 0 2.15 KB
#6057 EncodeArgs net6.0 37μs 20.3ns 78.8ns 0.461 0 0 32.4 KB
#6057 EncodeArgs netcoreapp3.1 55.1μs 25.1ns 97.2ns 0.438 0 0 32.4 KB
#6057 EncodeArgs net472 66.9μs 29.8ns 116ns 5.13 0.0667 0 32.5 KB
#6057 EncodeLegacyArgs net6.0 73.5μs 20.8ns 80.6ns 0 0 0 2.14 KB
#6057 EncodeLegacyArgs netcoreapp3.1 108μs 67ns 259ns 0 0 0 2.14 KB
#6057 EncodeLegacyArgs net472 150μs 63.2ns 236ns 0.3 0 0 2.15 KB
Benchmarks.Trace.Asm.AppSecWafBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunWafRealisticBenchmark net6.0 186μs 62.3ns 233ns 0 0 0 2.44 KB
master RunWafRealisticBenchmark netcoreapp3.1 198μs 96.8ns 362ns 0 0 0 2.39 KB
master RunWafRealisticBenchmark net472 208μs 161ns 623ns 0.311 0 0 2.46 KB
master RunWafRealisticBenchmarkWithAttack net6.0 123μs 41.9ns 157ns 0 0 0 1.47 KB
master RunWafRealisticBenchmarkWithAttack netcoreapp3.1 131μs 122ns 472ns 0 0 0 1.46 KB
master RunWafRealisticBenchmarkWithAttack net472 140μs 21.1ns 78.9ns 0.21 0 0 1.49 KB
#6057 RunWafRealisticBenchmark net6.0 185μs 130ns 487ns 0 0 0 2.44 KB
#6057 RunWafRealisticBenchmark netcoreapp3.1 195μs 138ns 516ns 0 0 0 2.39 KB
#6057 RunWafRealisticBenchmark net472 210μs 66.9ns 259ns 0.316 0 0 2.46 KB
#6057 RunWafRealisticBenchmarkWithAttack net6.0 123μs 86.9ns 336ns 0 0 0 1.47 KB
#6057 RunWafRealisticBenchmarkWithAttack netcoreapp3.1 131μs 140ns 524ns 0 0 0 1.46 KB
#6057 RunWafRealisticBenchmarkWithAttack net472 140μs 65.1ns 244ns 0.213 0 0 1.49 KB
Benchmarks.Trace.Iast.StringAspectsBenchmark - Slower ⚠️ More allocations ⚠️

Slower ⚠️ in #6057

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 1.923 294,950.00 567,150.00 bimodal

More allocations ⚠️ in #6057

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 252.99 KB 316.06 KB 63.07 KB 24.93%
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472 57.26 KB 59.04 KB 1.78 KB 3.12%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StringConcatBenchmark net6.0 59.4μs 793ns 7.89μs 0 0 0 43.44 KB
master StringConcatBenchmark netcoreapp3.1 61.9μs 721ns 7.18μs 0 0 0 42.64 KB
master StringConcatBenchmark net472 38.8μs 194ns 911ns 0 0 0 57.26 KB
master StringConcatAspectBenchmark net6.0 281μs 5.86μs 56.8μs 0 0 0 252.99 KB
master StringConcatAspectBenchmark netcoreapp3.1 341μs 1.79μs 11.7μs 0 0 0 254.22 KB
master StringConcatAspectBenchmark net472 279μs 5.71μs 55.4μs 0 0 0 278.53 KB
#6057 StringConcatBenchmark net6.0 59.3μs 744ns 7.41μs 0 0 0 43.44 KB
#6057 StringConcatBenchmark netcoreapp3.1 60.8μs 782ns 7.74μs 0 0 0 42.64 KB
#6057 StringConcatBenchmark net472 37.6μs 85.8ns 309ns 0 0 0 59.04 KB
#6057 StringConcatAspectBenchmark net6.0 575μs 3.26μs 23μs 0 0 0 316.06 KB
#6057 StringConcatAspectBenchmark netcoreapp3.1 324μs 1.61μs 9.14μs 0 0 0 252.97 KB
#6057 StringConcatAspectBenchmark net472 281μs 6.48μs 62.8μs 0 0 0 278.53 KB

@datadog-ddstaging
Copy link

datadog-ddstaging bot commented Sep 19, 2024

Datadog Report

Branch report: nacho/SuspiciousAttackerBlocking
Commit report: 7d2290e
Test service: dd-trace-dotnet

✅ 0 Failed, 363585 Passed, 2048 Skipped, 16h 1m 9.45s Total Time
⌛ 1 Performance Regression

⌛ Performance Regressions vs Default Branch (1)

  • StringConcatAspectBenchmark - Benchmarks.Trace.Iast.StringAspectsBenchmark 575.06µs (+270.91µs, +89%) - Details

@andrewlock
Copy link
Member

andrewlock commented Sep 19, 2024

Benchmarks Report for tracer 🐌

Benchmarks for #6057 compared to master:

  • 1 benchmarks are faster, with geometric mean 1.158
  • 2 benchmarks are slower, with geometric mean 1.159
  • All benchmarks have the same allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.ActivityBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 7.74μs 38.7ns 212ns 0.0152 0.00758 0 5.43 KB
master StartStopWithChild netcoreapp3.1 9.93μs 55.2ns 340ns 0.0146 0.00488 0 5.62 KB
master StartStopWithChild net472 16μs 25.3ns 98.1ns 1.03 0.316 0.0947 6.07 KB
#6057 StartStopWithChild net6.0 7.81μs 40.3ns 245ns 0.0195 0.00778 0 5.42 KB
#6057 StartStopWithChild netcoreapp3.1 10μs 54.3ns 307ns 0.0198 0.00495 0 5.62 KB
#6057 StartStopWithChild net472 16.2μs 55ns 213ns 1.02 0.32 0.096 6.07 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 468μs 333ns 1.2μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 633μs 191ns 715ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 832μs 374ns 1.4μs 0.414 0 0 3.3 KB
#6057 WriteAndFlushEnrichedTraces net6.0 466μs 179ns 645ns 0 0 0 2.7 KB
#6057 WriteAndFlushEnrichedTraces netcoreapp3.1 655μs 322ns 1.25μs 0 0 0 2.7 KB
#6057 WriteAndFlushEnrichedTraces net472 830μs 632ns 2.45μs 0.414 0 0 3.3 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 209μs 2.04μs 20.1μs 0.19 0 0 18.45 KB
master SendRequest netcoreapp3.1 222μs 1.24μs 8.41μs 0.215 0 0 20.61 KB
master SendRequest net472 0.00212ns 0.000846ns 0.00328ns 0 0 0 0 b
#6057 SendRequest net6.0 196μs 1.12μs 9.27μs 0.186 0 0 18.45 KB
#6057 SendRequest netcoreapp3.1 214μs 1.13μs 5.97μs 0.224 0 0 20.61 KB
#6057 SendRequest net472 0ns 0ns 0ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 555μs 1.13μs 4.09μs 0.543 0 0 41.59 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 688μs 3.16μs 12.2μs 0.332 0 0 41.91 KB
master WriteAndFlushEnrichedTraces net472 872μs 2.44μs 8.78μs 8.13 2.57 0.428 53.26 KB
#6057 WriteAndFlushEnrichedTraces net6.0 555μs 2.55μs 9.54μs 0.548 0 0 41.66 KB
#6057 WriteAndFlushEnrichedTraces netcoreapp3.1 679μs 3.16μs 12.6μs 0.363 0 0 41.96 KB
#6057 WriteAndFlushEnrichedTraces net472 864μs 3.21μs 12μs 8.39 2.52 0.419 53.28 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.21μs 0.746ns 2.69ns 0.0145 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.79μs 1.94ns 7.51ns 0.0133 0 0 1.02 KB
master ExecuteNonQuery net472 2.1μs 0.854ns 3.19ns 0.156 0 0 987 B
#6057 ExecuteNonQuery net6.0 1.25μs 0.822ns 2.96ns 0.0143 0 0 1.02 KB
#6057 ExecuteNonQuery netcoreapp3.1 1.8μs 1.77ns 6.64ns 0.0134 0 0 1.02 KB
#6057 ExecuteNonQuery net472 2.09μs 2.45ns 9.5ns 0.157 0 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.15μs 0.659ns 2.38ns 0.0134 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.54μs 0.869ns 3.25ns 0.0132 0 0 976 B
master CallElasticsearch net472 2.51μs 1.23ns 4.77ns 0.158 0 0 995 B
master CallElasticsearchAsync net6.0 1.3μs 0.37ns 1.43ns 0.013 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.6μs 0.55ns 1.91ns 0.0137 0 0 1.02 KB
master CallElasticsearchAsync net472 2.48μs 1.03ns 4ns 0.167 0 0 1.05 KB
#6057 CallElasticsearch net6.0 1.11μs 0.897ns 3.47ns 0.0139 0 0 976 B
#6057 CallElasticsearch netcoreapp3.1 1.43μs 0.729ns 2.63ns 0.0131 0 0 976 B
#6057 CallElasticsearch net472 2.48μs 1.09ns 4.08ns 0.157 0 0 995 B
#6057 CallElasticsearchAsync net6.0 1.29μs 0.414ns 1.6ns 0.0129 0 0 952 B
#6057 CallElasticsearchAsync netcoreapp3.1 1.59μs 1.86ns 7.19ns 0.0135 0 0 1.02 KB
#6057 CallElasticsearchAsync net472 2.49μs 1.19ns 4.6ns 0.166 0 0 1.05 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.36μs 1.53ns 5.92ns 0.0131 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.62μs 2.52ns 9.75ns 0.0122 0 0 952 B
master ExecuteAsync net472 1.75μs 0.853ns 3.3ns 0.145 0 0 915 B
#6057 ExecuteAsync net6.0 1.23μs 0.71ns 2.75ns 0.0135 0 0 952 B
#6057 ExecuteAsync netcoreapp3.1 1.6μs 0.623ns 2.25ns 0.0127 0 0 952 B
#6057 ExecuteAsync net472 1.72μs 0.65ns 2.34ns 0.145 0 0 915 B
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net6.0 4.08μs 3.38ns 12.6ns 0.0307 0 0 2.22 KB
master SendAsync netcoreapp3.1 5.19μs 4.72ns 18.3ns 0.036 0 0 2.76 KB
master SendAsync net472 7.9μs 10.5ns 40.8ns 0.497 0 0 3.15 KB
#6057 SendAsync net6.0 4.09μs 1.19ns 4.47ns 0.0305 0 0 2.22 KB
#6057 SendAsync netcoreapp3.1 5.17μs 2.75ns 10.3ns 0.0359 0 0 2.76 KB
#6057 SendAsync net472 7.73μs 1.77ns 6.85ns 0.498 0 0 3.15 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 1.53μs 1.48ns 5.71ns 0.0231 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.1μs 1.11ns 4.3ns 0.0221 0 0 1.64 KB
master EnrichedLog net472 2.56μs 1.39ns 5.01ns 0.25 0 0 1.57 KB
#6057 EnrichedLog net6.0 1.48μs 0.523ns 1.89ns 0.0227 0 0 1.64 KB
#6057 EnrichedLog netcoreapp3.1 2.17μs 1.5ns 5.6ns 0.0219 0 0 1.64 KB
#6057 EnrichedLog net472 2.63μs 0.868ns 3.25ns 0.249 0 0 1.57 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 115μs 141ns 545ns 0.0571 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 123μs 500ns 1.94μs 0 0 0 4.28 KB
master EnrichedLog net472 149μs 305ns 1.18μs 0.673 0.224 0 4.46 KB
#6057 EnrichedLog net6.0 115μs 87ns 301ns 0.0571 0 0 4.28 KB
#6057 EnrichedLog netcoreapp3.1 119μs 209ns 808ns 0 0 0 4.28 KB
#6057 EnrichedLog net472 147μs 231ns 832ns 0.657 0.219 0 4.46 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.96μs 3.35ns 13ns 0.0311 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.19μs 3.22ns 12.5ns 0.0289 0 0 2.2 KB
master EnrichedLog net472 4.89μs 4.18ns 16.2ns 0.319 0 0 2.02 KB
#6057 EnrichedLog net6.0 3.07μs 1.15ns 4.15ns 0.0306 0 0 2.2 KB
#6057 EnrichedLog netcoreapp3.1 4.19μs 0.939ns 3.64ns 0.0296 0 0 2.2 KB
#6057 EnrichedLog net472 4.71μs 1.24ns 4.8ns 0.319 0 0 2.02 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 1.31μs 0.963ns 3.73ns 0.0158 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.71μs 0.713ns 2.67ns 0.0153 0 0 1.14 KB
master SendReceive net472 2.1μs 0.584ns 2.26ns 0.183 0.00104 0 1.16 KB
#6057 SendReceive net6.0 1.39μs 0.727ns 2.82ns 0.0161 0 0 1.14 KB
#6057 SendReceive netcoreapp3.1 1.72μs 1.61ns 6.25ns 0.0154 0 0 1.14 KB
#6057 SendReceive net472 2.04μs 0.894ns 3.46ns 0.183 0.00101 0 1.16 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.75μs 0.762ns 2.95ns 0.0226 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.89μs 2.16ns 8.36ns 0.0215 0 0 1.65 KB
master EnrichedLog net472 4.43μs 1.83ns 7.08ns 0.323 0 0 2.04 KB
#6057 EnrichedLog net6.0 2.73μs 0.822ns 3.08ns 0.022 0 0 1.6 KB
#6057 EnrichedLog netcoreapp3.1 3.89μs 1.56ns 5.61ns 0.0214 0 0 1.65 KB
#6057 EnrichedLog net472 4.45μs 1.81ns 7.01ns 0.324 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6057

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net6.0 1.125 394.19 443.44

Faster 🎉 in #6057

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net6.0 1.158 562.50 485.81

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 394ns 0.307ns 1.19ns 0.00809 0 0 576 B
master StartFinishSpan netcoreapp3.1 586ns 0.486ns 1.82ns 0.00781 0 0 576 B
master StartFinishSpan net472 691ns 0.492ns 1.84ns 0.0918 0 0 578 B
master StartFinishScope net6.0 562ns 0.32ns 1.24ns 0.00992 0 0 696 B
master StartFinishScope netcoreapp3.1 711ns 0.979ns 3.79ns 0.00953 0 0 696 B
master StartFinishScope net472 887ns 0.782ns 3.03ns 0.104 0 0 658 B
#6057 StartFinishSpan net6.0 444ns 0.207ns 0.747ns 0.00804 0 0 576 B
#6057 StartFinishSpan netcoreapp3.1 558ns 0.456ns 1.77ns 0.00779 0 0 576 B
#6057 StartFinishSpan net472 651ns 0.626ns 2.42ns 0.0918 0 0 578 B
#6057 StartFinishScope net6.0 486ns 0.255ns 0.986ns 0.00981 0 0 696 B
#6057 StartFinishScope netcoreapp3.1 761ns 0.673ns 2.6ns 0.00938 0 0 696 B
#6057 StartFinishScope net472 883ns 0.806ns 3.12ns 0.104 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6057

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin‑net6.0 1.193 603.30 719.90

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 603ns 0.259ns 1ns 0.00982 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 996ns 2.82ns 10.6ns 0.00945 0 0 696 B
master RunOnMethodBegin net472 1.14μs 1.24ns 4.8ns 0.105 0 0 658 B
#6057 RunOnMethodBegin net6.0 720ns 0.331ns 1.28ns 0.00969 0 0 696 B
#6057 RunOnMethodBegin netcoreapp3.1 917ns 0.708ns 2.74ns 0.00927 0 0 696 B
#6057 RunOnMethodBegin net472 1.14μs 0.325ns 1.26ns 0.104 0 0 658 B

@andrewlock
Copy link
Member

andrewlock commented Sep 19, 2024

Throughput/Crank Report ⚡

Throughput results for AspNetCoreSimpleController comparing the following branches/commits:

Cases where throughput results for the PR are worse than latest master (5% drop or greater), results are shown in red.

Note that these results are based on a single point-in-time result for each branch. For full results, see one of the many, many dashboards!

gantt
    title Throughput Linux x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6057) (11.083M)   : 0, 11082519
    master (11.173M)   : 0, 11173302
    benchmarks/2.9.0 (11.081M)   : 0, 11080577

    section Automatic
    This PR (6057) (7.329M)   : 0, 7328882
    master (7.279M)   : 0, 7278664
    benchmarks/2.9.0 (7.732M)   : 0, 7732233

    section Trace stats
    master (7.532M)   : 0, 7531539

    section Manual
    master (11.083M)   : 0, 11082902

    section Manual + Automatic
    This PR (6057) (6.708M)   : 0, 6708136
    master (6.710M)   : 0, 6709924

    section DD_TRACE_ENABLED=0
    master (10.153M)   : 0, 10153208

Loading
gantt
    title Throughput Linux arm64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6057) (9.609M)   : 0, 9609368
    master (9.398M)   : 0, 9398448
    benchmarks/2.9.0 (9.798M)   : 0, 9798067

    section Automatic
    This PR (6057) (6.475M)   : 0, 6474701
    master (6.529M)   : 0, 6529082

    section Trace stats
    master (6.958M)   : 0, 6957848

    section Manual
    master (9.566M)   : 0, 9566040

    section Manual + Automatic
    This PR (6057) (6.156M)   : 0, 6155926
    master (6.221M)   : 0, 6221012

    section DD_TRACE_ENABLED=0
    master (8.922M)   : 0, 8921736

Loading
gantt
    title Throughput Windows x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6057) (10.251M)   : 0, 10251443
    master (10.147M)   : 0, 10147192
    benchmarks/2.9.0 (10.067M)   : 0, 10067315

    section Automatic
    This PR (6057) (6.765M)   : 0, 6765236
    master (6.895M)   : 0, 6894968
    benchmarks/2.9.0 (7.552M)   : 0, 7552193

    section Trace stats
    master (7.434M)   : 0, 7433935

    section Manual
    master (10.142M)   : 0, 10142136

    section Manual + Automatic
    This PR (6057) (6.349M)   : 0, 6348925
    master (6.402M)   : 0, 6401740

    section DD_TRACE_ENABLED=0
    master (9.547M)   : 0, 9547292

Loading

@@ -333,7 +333,15 @@ protected async Task TestRateLimiter(bool enableSecurity, string url, MockTracer
{
foreach (var header in headers)
{
_httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
Copy link
Contributor Author

@NachoEchevarria NachoEchevarria Sep 20, 2024

Choose a reason for hiding this comment

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

This is useful to have more control over the headers in tests. We can remove default headers by setting them to null or add any desired custom value without the need of adding them to the existing ones.

Copy link
Member

Choose a reason for hiding this comment

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

Agree, please log this as a potential improvement.

@NachoEchevarria NachoEchevarria changed the title Nacho/suspicious attacker blocking [ASM] Suspicious attacker blocking Sep 20, 2024
@@ -24,20 +24,34 @@ public void ProcessUpdates(ConfigurationStatus configurationStatus, List<RemoteC
configurationStatus.RulesDataByFile[rawFile.Path.Path] = rulesData;
configurationStatus.IncomingUpdateState.WafKeysToApply.Add(ConfigurationStatus.WafRulesDataKey);
}

var exclusionsData = asmDataConfig.TypedFile!.ExclusionsData;
Copy link
Member

Choose a reason for hiding this comment

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

Minor: I know it's what the above code does, but are we sure TypedFile can never be null? It feels like ? would be safer, especially as we check if exclusionsData is null anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I have changed both statements. Thanks!

@NachoEchevarria NachoEchevarria marked this pull request as ready for review September 20, 2024 13:57
@NachoEchevarria NachoEchevarria requested a review from a team as a code owner September 20, 2024 13:57
@NachoEchevarria NachoEchevarria marked this pull request as draft October 1, 2024 15:54
Copy link
Contributor

@anna-git anna-git left a comment

Choose a reason for hiding this comment

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

left a few comments but LGTM

@@ -46,6 +48,12 @@ public void ProcessUpdates(ConfigurationStatus configurationStatus, List<RemoteC

if (asmConfig.Actions != null)
{
if (!actionsCleared)
Copy link
Contributor

Choose a reason for hiding this comment

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

this and the following could now use a rebase, actions should clear automatically with removed files or empty arrays in fles like other objects

public AspNetCore5AsmAttackerBlocking(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper)
: base(fixture, outputHelper, enableSecurity: true, testName: nameof(AspNetCore5AsmAttackerBlocking))
{
SetEnvironmentVariable(ConfigurationKeys.DebugEnabled, "1");
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want debug enabled on master though ?

Copy link
Member

Choose a reason for hiding this comment

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

We should not enable debug by default, as that's a different scenario to our customers, and it can hide issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will remove that. I was merging the conflicting files before testing and setting the PR as ready to review, but I promise to remove the debug flag :)

new KeyValuePair<string, string>("User-Agent", "dd-test-scanner-log-block"),
};

SetEnvironmentVariable(ConfigurationKeys.DebugEnabled, "1");
Copy link
Contributor

Choose a reason for hiding this comment

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

is this meant to stay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that was only for testing. I have deleted it.

result = SubmitRequest(url + "?a=5", null, null, headers: headersAttackerArachni);
result.Result.StatusCode.Should().Be(HttpStatusCode.MethodNotAllowed);
result = SubmitRequest(url + "?a=6", null, null, headers: headersRegularArachni);
result.Result.StatusCode.Should().Be(HttpStatusCode.OK);
Copy link
Contributor

Choose a reason for hiding this comment

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

no snapshot verify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this feature, I though that it would be enough to replicate what the system tests check and was failing regarding status in order to make a more simple test and avoid unnecessary snapshots usage.

@NachoEchevarria NachoEchevarria marked this pull request as ready for review October 2, 2024 11:20
@NachoEchevarria NachoEchevarria merged commit f93ed0a into master Oct 2, 2024
75 checks passed
@NachoEchevarria NachoEchevarria deleted the nacho/SuspiciousAttackerBlocking branch October 2, 2024 13:42
@github-actions github-actions bot added this to the vNext-v3 milestone Oct 2, 2024
agocs pushed a commit that referenced this pull request Oct 8, 2024
## Summary of changes

This PR adds the required code to support the suspicious attack
functionality.

It has added the required code to read the exclusion data from the RC.

It also has modified the existing code regarding RC actions. Previously,
if a configuration was received with an action, the configuration was
stored and later sent to the WAF. If new values with an empty action
array would come later, the previous action configurations would be
deleted, but if a new array would come with a new action different than
the previous one, we would report them both to the WAF. This behavior
was making the suspicious attacker system tests fail because we would
keep RC changes from previous tests. This change seems to be aligned
with the behavior of other libraries.

The file
[AspNetBase.cs](https://github.com/DataDog/dd-trace-dotnet/pull/6057/files#diff-0faff2451113067d7669566ba9199908b720a3764914b00d6f33d4b376098d74)
has been updated. Now, tests have more control over the used headers by
allowing them to remove headers or replace previous values with new
ones.

## Reason for change

## Implementation details

## Test coverage

## Other details
<!-- Fixes #{issue} -->

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants