Skip to content

Commit

Permalink
Session property can throw on netcore app 3.1 and lower
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-git committed Feb 13, 2025
1 parent ae840d3 commit a5b6a37
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#if !NETFRAMEWORK
using System;
using System.Collections.Generic;
using Datadog.Trace.AppSec.Waf;
using Datadog.Trace.Logging;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;

Expand Down Expand Up @@ -78,7 +80,17 @@ internal static void CheckPathParamsAndSessionId(this Security security, HttpCon
{
var securityCoordinator = SecurityCoordinator.Get(security, span, transport);
var args = new Dictionary<string, object> { { AddressesConstants.RequestPathParams, pathParams } };
var result = securityCoordinator.RunWaf(args, sessionId: context.Session.Id);
IResult? result;
// we need these tests for netcoreapp3.1 and lower, as otherwise it throws
if (context.Features.Get<ISessionFeature>() is not null && (context.Session?.IsAvailable ?? false))
{
result = securityCoordinator.RunWaf(args, sessionId: context.Session.Id);
}
else
{
result = securityCoordinator.RunWaf(args);
}

securityCoordinator.BlockAndReport(result);
}
}
Expand Down

0 comments on commit a5b6a37

Please sign in to comment.