Skip to content

Commit

Permalink
Use new capabilities helper
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoEchevarria committed Sep 12, 2024
1 parent 3afbc29 commit 3532ae2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Datadog.Trace.AppSec.AttackerFingerprint;

internal static class AttackerFingerprintHelper
{
public const string MinimumWAFVersion = "1.19.0";
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(AttackerFingerprintHelper));
private static readonly Dictionary<string, object> _fingerprintRequest = new() { { AddressesConstants.WafContextProcessor, new Dictionary<string, object> { { "fingerprint", true } } } };

Expand Down
26 changes: 4 additions & 22 deletions tracer/src/Datadog.Trace/AppSec/Security.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,10 @@ private void SetRemoteConfigCapabilites()
rcm.SetCapability(RcmCapabilitiesIndices.AsmRaspShi, _settings.RaspEnabled && _noLocalRules && WafSupportsCapability(RcmCapabilitiesIndices.AsmRaspShi));
rcm.SetCapability(RcmCapabilitiesIndices.AsmRaspSqli, _settings.RaspEnabled && _noLocalRules && WafSupportsCapability(RcmCapabilitiesIndices.AsmRaspSqli));
rcm.SetCapability(RcmCapabilitiesIndices.AsmExclusionData, _noLocalRules && WafSupportsCapability(RcmCapabilitiesIndices.AsmExclusionData));
var fingerPrintSupported = WafVersionEqualOrAbove(AttackerFingerprintHelper.MinimumWAFVersion);
rcm.SetCapability(RcmCapabilitiesIndices.AsmEnpointFingerprint, _noLocalRules && fingerPrintSupported);
rcm.SetCapability(RcmCapabilitiesIndices.AsmHeaderFingerprint, _noLocalRules && fingerPrintSupported);
rcm.SetCapability(RcmCapabilitiesIndices.AsmNetworkFingerprint, _noLocalRules && fingerPrintSupported);
rcm.SetCapability(RcmCapabilitiesIndices.AsmSessionFingerprint, _noLocalRules && fingerPrintSupported);
rcm.SetCapability(RcmCapabilitiesIndices.AsmEnpointFingerprint, _noLocalRules && WafSupportsCapability(RcmCapabilitiesIndices.AsmEnpointFingerprint));
rcm.SetCapability(RcmCapabilitiesIndices.AsmHeaderFingerprint, _noLocalRules && WafSupportsCapability(RcmCapabilitiesIndices.AsmHeaderFingerprint));
rcm.SetCapability(RcmCapabilitiesIndices.AsmNetworkFingerprint, _noLocalRules && WafSupportsCapability(RcmCapabilitiesIndices.AsmNetworkFingerprint));
rcm.SetCapability(RcmCapabilitiesIndices.AsmSessionFingerprint, _noLocalRules && WafSupportsCapability(RcmCapabilitiesIndices.AsmSessionFingerprint));
// follows a different pattern to rest of ASM remote config, if available it's the RC value
// that takes precedence. This follows what other products do.
rcm.SetCapability(RcmCapabilitiesIndices.AsmAutoUserInstrumentationMode, true);
Expand All @@ -519,23 +518,6 @@ private bool WafSupportsCapability(BigInteger capability)
return RCMCapabilitiesHelper.WafSupportsCapability(capability, _waf?.Version);
}

private bool WafVersionEqualOrAbove(string version)
{
if (string.IsNullOrWhiteSpace(version))
{
return false;
}

var currentVersion = _waf?.Version;

if (string.IsNullOrWhiteSpace(currentVersion))
{
return false;
}

return Version.Parse(currentVersion) >= Version.Parse(version);
}

private void InitWafAndInstrumentations(bool configurationFromRcm = false)
{
// initialization of WafLibraryInvoker
Expand Down
4 changes: 4 additions & 0 deletions tracer/src/Datadog.Trace/AppSec/Waf/RCMCapabilitiesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ internal static class RCMCapabilitiesHelper
{ RcmCapabilitiesIndices.AsmRaspSsrf, new Version(2, 51) },
{ RcmCapabilitiesIndices.AsmRaspShi, new Version(3, 2) },
{ RcmCapabilitiesIndices.AsmExclusionData, new Version(3, 2) },
{ RcmCapabilitiesIndices.AsmEnpointFingerprint, new Version(1, 19) },
{ RcmCapabilitiesIndices.AsmHeaderFingerprint, new Version(1, 19) },
{ RcmCapabilitiesIndices.AsmNetworkFingerprint, new Version(1, 19) },
{ RcmCapabilitiesIndices.AsmSessionFingerprint, new Version(1, 19) },
};

internal static bool WafSupportsCapability(BigInteger capability, string? wafVersion)
Expand Down

0 comments on commit 3532ae2

Please sign in to comment.