-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASM] Introduce SecurityReporter for all reporting functions of Secur…
…ityCoordinator (#6481) ## Summary of changes This PR is just moving code around, to allow reporting security infos on spans without needing a security coordinator. Basically we are extracting from `SecurityCoordinator` the reporting functions to the already existing underused `SecurityReporter`, we are nesting core/framework classes inside of `SecurityCoordinator` and `SecurityReporter`. `SecurityReporter` can function without the `Security` instance, it just needs the span and transport to add info. This allows for better separation of concerns and prepares things for ATO as some contexts just need to report additional headers without running the waf necessarily, or already, within the catch (BlockException) inside the `BlockingMiddleware` where we just want to report the result within the exception and don't need any security features ## 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. -->
- Loading branch information
Showing
16 changed files
with
286 additions
and
222 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
47 changes: 47 additions & 0 deletions
47
tracer/src/Datadog.Trace/AppSec/Coordinator/SecurityReporter.Core.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,47 @@ | ||
// <copyright file="SecurityReporter.Core.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 | ||
#if !NETFRAMEWORK | ||
using System.Runtime.CompilerServices; | ||
using Datadog.Trace.Headers; | ||
|
||
namespace Datadog.Trace.AppSec.Coordinator; | ||
|
||
internal partial class SecurityReporter | ||
{ | ||
private bool CanAccessHeaders => true; | ||
|
||
/// <summary> | ||
/// Outside of a web context this can't work and there are no web assemblies to load so without the no inlining, this would cause a load assembly exception | ||
/// </summary> | ||
/// <param name="span">the span to report on</param> | ||
/// <param name="searchRootSpan">should we fetch the root span for you</param> | ||
internal static void SafeCollectHeaders(Span span, bool searchRootSpan = true) | ||
{ | ||
if (AspNetCoreAvailabilityChecker.IsAspNetCoreAvailable()) | ||
{ | ||
CollectHeadersSafe(searchRootSpan); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
void CollectHeadersSafe(bool searchRootSpanImpl) | ||
{ | ||
var context = CoreHttpContextStore.Instance.Get(); | ||
if (context is not null) | ||
{ | ||
var securityReporter = new SecurityReporter(span, new SecurityCoordinator.HttpTransport(context), !searchRootSpanImpl); | ||
securityReporter.CollectHeaders(); | ||
} | ||
} | ||
} | ||
|
||
internal void CollectHeaders() | ||
{ | ||
var headers = new HeadersCollectionAdapter(_httpTransport.Context.Request.Headers); | ||
AddRequestHeaders(headers); | ||
} | ||
} | ||
#endif |
Oops, something went wrong.