-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IAST] Support for specifying aspect min version (#5931)
## Summary of changes Added a mechanism by which an aspect or aspect class can define a minimum native version in order to be applied. ## Reason for change Some aspects defined under new features (like aspects for struct methods, or aspects with generics) can break old native implementations, so, we need a way to avoid those to be sent or applied. ## Implementation details Created `FromVersionAttribute` versions of all Aspect attributes. These inherit from the original attribute adding a **minimum version of the native library** from which the aspect will be applied. This version is then added in the end of the aspect line, in a way that makes old native tracers ignore those lines, as it breaks the old specification. For new tracers who are able to read that version info, a version comparison will determine if that line is accepted or dumped, allowing us to fine tune the aspects set applied. This aspect attribute which states that this aspect will be only applied if a native tracer with version `3.2.0` or bigger is found `[AspectMethodReplaceFromVersion("3.2.0", "System.String::Concat(System.Collections.Generic.IEnumerable)")]` will generate this aspect line `[AspectMethodReplace(\"System.String::Concat(System.Collections.Generic.IEnumerable)\",\"\",[0],[False],[None],Default,[]);V3.2.0] Concat(System.Collections.Generic.IEnumerable)` Notice that the version goes in the end, and that's because old tracers while parsing the line were looking for the text `)] ` This will make old unprepared tracers to automatically ditch the line, whereas the new one implemented from this PR, will be able to retrieve, parse and decide what to do with that version info. ## Test coverage Source generator tests have been written to ensure the correct use and aspect generation of version flavor aspect attributes. ## Other details <!--⚠️ 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. -->
- Loading branch information
1 parent
9f69b4b
commit 6c8db45
Showing
19 changed files
with
293 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tracer/src/Datadog.Trace/Iast/Dataflow/AspectClassFromVersionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// <copyright file="AspectClassFromVersionAttribute.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
#nullable enable | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Datadog.Trace.Iast.Dataflow; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
internal sealed class AspectClassFromVersionAttribute : AspectClassAttribute | ||
{ | ||
private readonly List<object> parameters = new List<object>(); | ||
|
||
public AspectClassFromVersionAttribute(string version) | ||
: base() | ||
{ | ||
} | ||
|
||
public AspectClassFromVersionAttribute(string version, string defaultAssembly) | ||
: base(defaultAssembly) | ||
{ | ||
} | ||
|
||
public AspectClassFromVersionAttribute(string version, string defaultAssembly, AspectType defaultAspectType, params VulnerabilityType[] defaultVulnerabilityTypes) | ||
: base(defaultAssembly, defaultAspectType, defaultVulnerabilityTypes) | ||
{ | ||
} | ||
|
||
public AspectClassFromVersionAttribute(string version, string defaultAssembly, AspectFilter[] filters, AspectType defaultAspectType = AspectType.Propagation, params VulnerabilityType[] defaultVulnerabilityTypes) | ||
: base(defaultAssembly, filters, defaultAspectType, defaultVulnerabilityTypes) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tracer/src/Datadog.Trace/Iast/Dataflow/AspectCtorReplaceFromVersionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// <copyright file="AspectCtorReplaceFromVersionAttribute.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
|
||
#nullable enable | ||
|
||
using Datadog.Trace.AppSec.Waf.ReturnTypes.Managed; | ||
|
||
namespace Datadog.Trace.Iast.Dataflow; | ||
|
||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] | ||
internal class AspectCtorReplaceFromVersionAttribute : AspectCtorReplaceAttribute | ||
{ | ||
public AspectCtorReplaceFromVersionAttribute(string version, string targetMethod) | ||
: base(targetMethod) | ||
{ | ||
} | ||
|
||
public AspectCtorReplaceFromVersionAttribute(string version, string targetMethod, params AspectFilter[] filters) | ||
: base(targetMethod, filters) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.