Activate and expose the WAF's obfuscator#2696
Conversation
| [InlineData(true, "pwd", "select pg_sleep", "select pg_sleep")] | ||
| public void AttacksWithSecrets(bool obfuscate, string key, string fullAttack, string highlight) | ||
| { | ||
| Environment.SetEnvironmentVariable("DD_TRACE_DEBUG", "true"); |
There was a problem hiding this comment.
I don't think we should set this here if possible, as this is changing the global environment variables, and could conflict with other tests? Doesn't look required AFAICT
There was a problem hiding this comment.
To be honest, I just copied and pasted it from another WAF test. I agree, it probably going to slow things and could create issues with other tests, so I the line from both places in 15eff67.
There was a problem hiding this comment.
The debug variable is still being set here. Maybe you committed before saving this file?
There was a problem hiding this comment.
Okay, really fixed in c66cff5. Yes, can't have saved the file.
3d880e9 to
97561d1
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| using var waf = | ||
| obfuscate | ||
| ? Waf.Create(SecuritySettings.ObfuscationParameterKeyRegexDefault, SecuritySettings.ObfuscationParameterValueRegexDefault) | ||
| : Waf.Create(string.Empty, string.Empty); |
There was a problem hiding this comment.
I could see Waf.Create making the obfuscation parameters optional and defaulting to "" if not provided
There was a problem hiding this comment.
I did think about making the new parameters optional, but it seemed to make the meaning of the API clearer to keep them mandatory. I think I'll leave them as they are for now, and come back to this, as I'm planning to start on a refactoring of the Security class soon. Having three string parameters with different meanings isn't great, so maybe I'll wrap them in a class / struct.
Benchmarks Report 🐌Benchmarks for #2696 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 - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ElasticsearchBenchmark - Slower
|
| Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
|---|---|---|---|---|
| Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch‑net472 | 1.307 | 2,506.26 | 3,275.09 |
Raw results
| Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---|---|---|---|---|---|---|---|---|---|
| master | CallElasticsearch |
net472 | 2.51μs | 12.2ns | 48.8ns | 0.127 | 0 | 0 | 803 B |
| master | CallElasticsearch |
netcoreapp3.1 | 1.68μs | 6.15ns | 23ns | 0.0109 | 0 | 0 | 792 B |
| master | CallElasticsearchAsync |
net472 | 2.76μs | 11.8ns | 45.7ns | 0.148 | 0.00135 | 0 | 939 B |
| master | CallElasticsearchAsync |
netcoreapp3.1 | 2.11μs | 10.9ns | 50ns | 0.0124 | 0 | 0 | 912 B |
| #2696 | CallElasticsearch |
net472 | 3.29μs | 13.2ns | 49.4ns | 0.127 | 0 | 0 | 803 B |
| #2696 | CallElasticsearch |
netcoreapp3.1 | 1.73μs | 9.89ns | 70ns | 0.0108 | 0 | 0 | 792 B |
| #2696 | CallElasticsearchAsync |
net472 | 3.01μs | 17.4ns | 132ns | 0.146 | 0 | 0 | 939 B |
| #2696 | CallElasticsearchAsync |
netcoreapp3.1 | 1.92μs | 9.66ns | 52ns | 0.0129 | 0 | 0 | 912 B |
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️
Raw results
| Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---|---|---|---|---|---|---|---|---|---|
| master | ExecuteAsync |
net472 | 3μs | 14.2ns | 60.3ns | 0.168 | 0.00147 | 0 | 1.06 KB |
| master | ExecuteAsync |
netcoreapp3.1 | 2μs | 11.3ns | 75.1ns | 0.0143 | 0 | 0 | 1.03 KB |
| #2696 | ExecuteAsync |
net472 | 3.04μs | 10.1ns | 36.3ns | 0.168 | 0.0015 | 0 | 1.06 KB |
| #2696 | ExecuteAsync |
netcoreapp3.1 | 2.03μs | 9.76ns | 42.5ns | 0.0152 | 0 | 0 | 1.03 KB |
Benchmarks.Trace.HttpClientBenchmark - Slower ⚠️ Same allocations ✔️
Slower ⚠️ in #2696
Benchmark
diff/base
Base Median (ns)
Diff Median (ns)
Modality
Benchmarks.Trace.HttpClientBenchmark.SendAsync‑net472
1.145
6,813.95
7,803.63
| Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
|---|---|---|---|---|
| Benchmarks.Trace.HttpClientBenchmark.SendAsync‑net472 | 1.145 | 6,813.95 | 7,803.63 |
Raw results
| Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---|---|---|---|---|---|---|---|---|---|
| master | SendAsync |
net472 | 6.79μs | 33.6ns | 138ns | 0.361 | 0 | 0 | 2.28 KB |
| master | SendAsync |
netcoreapp3.1 | 4.68μs | 16.8ns | 65.2ns | 0.0301 | 0 | 0 | 2.21 KB |
| #2696 | SendAsync |
net472 | 7.83μs | 40.4ns | 258ns | 0.356 | 0 | 0 | 2.28 KB |
| #2696 | SendAsync |
netcoreapp3.1 | 5.18μs | 27.4ns | 134ns | 0.0303 | 0 | 0 | 2.21 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 |
net472 | 3.59μs | 19.8ns | 121ns | 0.227 | 0 | 0 | 1.45 KB |
| master | EnrichedLog |
netcoreapp3.1 | 3.15μs | 17.4ns | 99.9ns | 0.0213 | 0 | 0 | 1.53 KB |
| #2696 | EnrichedLog |
net472 | 3.38μs | 16.4ns | 71.6ns | 0.228 | 0 | 0 | 1.45 KB |
| #2696 | EnrichedLog |
netcoreapp3.1 | 3.29μs | 18.5ns | 123ns | 0.0215 | 0 | 0 | 1.53 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 |
net472 | 284μs | 1.33μs | 4.97μs | 0.441 | 0.147 | 0 | 4.33 KB |
| master | EnrichedLog |
netcoreapp3.1 | 227μs | 745ns | 2.79μs | 0 | 0 | 0 | 4.21 KB |
| #2696 | EnrichedLog |
net472 | 287μs | 1.44μs | 7.21μs | 0.445 | 0.148 | 0 | 4.33 KB |
| #2696 | EnrichedLog |
netcoreapp3.1 | 235μs | 1.28μs | 7.68μs | 0 | 0 | 0 | 4.21 KB |
Benchmarks.Trace.NLogBenchmark - Slower ⚠️ Same allocations ✔️
Slower ⚠️ in #2696
Benchmark
diff/base
Base Median (ns)
Diff Median (ns)
Modality
Benchmarks.Trace.NLogBenchmark.EnrichedLog‑net472
1.202
7,306.12
8,783.99
| Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
|---|---|---|---|---|
| Benchmarks.Trace.NLogBenchmark.EnrichedLog‑net472 | 1.202 | 7,306.12 | 8,783.99 |
Raw results
| Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---|---|---|---|---|---|---|---|---|---|
| master | EnrichedLog |
net472 | 7.32μs | 30.3ns | 109ns | 0.506 | 0 | 0 | 3.23 KB |
| master | EnrichedLog |
netcoreapp3.1 | 6.4μs | 30.2ns | 117ns | 0.0507 | 0 | 0 | 3.6 KB |
| #2696 | EnrichedLog |
net472 | 8.92μs | 51.9ns | 437ns | 0.502 | 0 | 0 | 3.23 KB |
| #2696 | EnrichedLog |
netcoreapp3.1 | 6.52μs | 17.8ns | 64.2ns | 0.0494 | 0 | 0 | 3.6 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 |
net472 | 2.42μs | 9.33ns | 37.3ns | 0.16 | 0.00118 | 0 | 1.01 KB |
| master | SendReceive |
netcoreapp3.1 | 1.96μs | 6.33ns | 24.5ns | 0.0136 | 0 | 0 | 1.01 KB |
| #2696 | SendReceive |
net472 | 2.41μs | 9.43ns | 35.3ns | 0.161 | 0 | 0 | 1.01 KB |
| #2696 | SendReceive |
netcoreapp3.1 | 2.08μs | 11.2ns | 60.1ns | 0.014 | 0 | 0 | 1.01 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 |
net472 | 6.61μs | 37.2ns | 244ns | 0.292 | 0 | 0 | 1.87 KB |
| master | EnrichedLog |
netcoreapp3.1 | 5.19μs | 22.7ns | 84.8ns | 0.0207 | 0 | 0 | 1.49 KB |
| #2696 | EnrichedLog |
net472 | 6.16μs | 35ns | 245ns | 0.291 | 0 | 0 | 1.87 KB |
| #2696 | EnrichedLog |
netcoreapp3.1 | 5.21μs | 27ns | 133ns | 0.0205 | 0 | 0 | 1.49 KB |
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️
Raw results
| Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---|---|---|---|---|---|---|---|---|---|
| master | StartFinishSpan |
net472 | 924ns | 4.42ns | 18.7ns | 0.0719 | 0 | 0 | 457 B |
| master | StartFinishSpan |
netcoreapp3.1 | 932ns | 5.31ns | 39.1ns | 0.00618 | 0 | 0 | 456 B |
| master | StartFinishScope |
net472 | 1.06μs | 5.42ns | 24.8ns | 0.0845 | 0 | 0 | 538 B |
| master | StartFinishScope |
netcoreapp3.1 | 1.08μs | 6.26ns | 53.5ns | 0.00805 | 0 | 0 | 576 B |
| #2696 | StartFinishSpan |
net472 | 986ns | 4.65ns | 20.8ns | 0.0719 | 0 | 0 | 457 B |
| #2696 | StartFinishSpan |
netcoreapp3.1 | 884ns | 3.05ns | 10.6ns | 0.00603 | 0 | 0 | 456 B |
| #2696 | StartFinishScope |
net472 | 1.18μs | 6.65ns | 52.3ns | 0.0841 | 0 | 0 | 538 B |
| #2696 | StartFinishScope |
netcoreapp3.1 | 1.03μs | 4.96ns | 20.4ns | 0.00768 | 0 | 0 | 576 B |
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️
Raw results
| Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---|---|---|---|---|---|---|---|---|---|
| master | RunOnMethodBegin |
net472 | 1.36μs | 7.31ns | 42ns | 0.0843 | 0 | 0 | 538 B |
| master | RunOnMethodBegin |
netcoreapp3.1 | 1.26μs | 6.62ns | 31.7ns | 0.0075 | 0 | 0 | 576 B |
| #2696 | RunOnMethodBegin |
net472 | 1.27μs | 6.05ns | 30.2ns | 0.084 | 0 | 0 | 538 B |
| #2696 | RunOnMethodBegin |
netcoreapp3.1 | 1.18μs | 5.54ns | 22.9ns | 0.00769 | 0 | 0 | 576 B |
The WAF now comes with a build in obfuscator based on RE2 patterns to scan the output of the WAF for possible sensitive. This PR activates that functionality by setting the patterns to the standard values. It also allows users to control the obfuscation via two environment variables: `DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP` and `DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP` (and by user all the other standard ways of setting config in .NET)
93a3b44 to
5024f6b
Compare
Code Coverage Report 📊
View the full report for further details: Datadog.Trace Breakdown
|
| master | #2696 | Change | |
|---|---|---|---|
| Lines % | 73% |
72% |
-1% |
| Branches % | 70% |
69% |
-1% |
| Complexity | 12416 |
12666 |
250 ⛔ |
The following classes have significant coverage changes.
| File | Line coverage change | Branch coverage change | Complexity change |
|---|---|---|---|
| Datadog.Trace.TracerManager | -30% ⛔ |
-34% ⛔ |
88 ⛔ |
| Datadog.Trace.TracerManagerFactory | -28% ⛔ |
-37% ⛔ |
60 ⛔ |
| Datadog.Trace.AppSec.Waf.Waf | -17% ⛔ |
-12% ⛔ |
9 ⛔ |
| Datadog.Trace.AppSec.SecuritySettings | -16% ⛔ |
-13% ⛔ |
46 ⛔ |
| Datadog.Trace.AppSec.Waf.Initialization.WafConfigurator | -16% ⛔ |
-12% ⛔ |
40 ⛔ |
| Datadog.Trace.SpanExtensions | -5% ⛔ |
-8% ⛔ |
0 ✔️ |
| Datadog.Trace.Ci.GitInfo | 5% ✔️ |
7% ✔️ |
0 ✔️ |
| Datadog.Trace.Ci.CIVisibility | 7% ✔️ |
7% ✔️ |
0 ✔️ |
View the full reports for further details:
Summary of changes
The WAF now comes with a build in obfuscator based on RE2 patterns to
scan the output of the WAF for possible sensitive.
This PR activates that functionality by setting the patterns to the
standard values.
It also allows users to control the obfuscation via two environment
variables:
DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXPandDD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP(and by user all theother standard ways of setting config in .NET)
Test coverage
Includes unit tests, this functionality is also covered by the system-tests.