Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/WebJobs.Script.WebHost/AntiSSRF/AntiSSRFConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Microsoft.Azure.WebJobs.Script.WebHost
{
public static class AntiSSRFConstants
{
public static readonly string AntiSSRFHttpClientName = "AntiSSRFClient";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Internal.AntiSSRF;

namespace Microsoft.Azure.WebJobs.Script.WebHost
{
public static class AntiSSRFServiceCollectionExtensions
{
public static IServiceCollection AddAntiSSRFHttpClient(this IServiceCollection services)
{
// create and add SSRF HTTP client
var policy = new AntiSSRFPolicy();
policy.SetDefaults();
var handler = policy.GetHandler();
services.AddHttpClient(AntiSSRFConstants.AntiSSRFHttpClientName)
.ConfigurePrimaryHttpMessageHandler(() => handler);

return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -39,7 +39,7 @@ public AtlasInstanceManager(IOptionsFactory<ScriptApplicationHostOptions> option
IPackageDownloadHandler packageDownloadHandler) : base(httpClientFactory, webHostEnvironment,
environment, logger, metricsLogger, meshServiceClient)
{
_client = httpClientFactory?.CreateClient() ?? throw new ArgumentNullException(nameof(httpClientFactory));
_client = httpClientFactory?.CreateClient(AntiSSRFConstants.AntiSSRFHttpClientName) ?? throw new ArgumentNullException(nameof(httpClientFactory));
_webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_metricsLogger = metricsLogger;
Expand Down Expand Up @@ -182,6 +182,7 @@ protected override async Task<string> DownloadWarmupAsync(RunFromPackageContext
string error = null;
HttpResponseMessage response = null;
long? contentLength = null;

try
{
if (!string.IsNullOrEmpty(blobUri))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -34,7 +34,7 @@ public PackageDownloadHandler(IHttpClientFactory httpClientFactory, IManagedIden
IBashCommandHandler bashCommandHandler, IEnvironment environment, IFileSystem fileSystem, ILogger<PackageDownloadHandler> logger,
IMetricsLogger metricsLogger)
{
_httpClient = httpClientFactory?.CreateClient() ?? throw new ArgumentNullException(nameof(httpClientFactory));
_httpClient = httpClientFactory?.CreateClient(AntiSSRFConstants.AntiSSRFHttpClientName) ?? throw new ArgumentNullException(nameof(httpClientFactory));
_managedIdentityTokenProvider = managedIdentityTokenProvider ?? throw new ArgumentNullException(nameof(managedIdentityTokenProvider));
_bashCommandHandler = bashCommandHandler ?? throw new ArgumentNullException(nameof(bashCommandHandler));
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
services.AddSingleton<IFunctionMetadataManager, FunctionMetadataManager>();
services.AddSingleton<IWebFunctionsManager, WebFunctionsManager>();
services.AddHttpClient();
services.AddAntiSSRFHttpClient();
services.AddBundlesHttpClient();

services.AddSingleton<StartupContextProvider>();
Expand Down
1 change: 1 addition & 0 deletions src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<PackageReference Include="Microsoft.Azure.WebSites.DataProtection" Version="2.1.91-alpha" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="$(IdentityDependencyVersion)" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="$(IdentityDependencyVersion)" />
<PackageReference Include="Microsoft.Internal.AntiSSRF" Version="2.2.1" />
<PackageReference Include="Microsoft.Security.Utilities" Version="1.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Polly;
Expand Down
Loading