Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Defaults_work_correctly()

Assert.Equal(20, options.MaxEntries);
Assert.Equal(32, options.MaxBodyCaptureSizeKb);
Assert.False(options.AllowLocalCompareTargets);
Assert.Null(options.AllowLocalCompareTargets);
Assert.Empty(options.IgnorePaths);
}

Expand Down
6 changes: 6 additions & 0 deletions DebugProbe.AspNetCore/Extensions/DebugProbeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Http;

namespace DebugProbe.AspNetCore.Extensions;
Expand Down Expand Up @@ -60,6 +61,11 @@ public static IServiceCollection AddDebugProbe(this IServiceCollection services,
/// </summary>
public static IApplicationBuilder UseDebugProbe(this IApplicationBuilder app)
{
var options = app.ApplicationServices.GetRequiredService<DebugProbeOptions>();
var environment = app.ApplicationServices.GetRequiredService<IHostEnvironment>();

options.AllowLocalCompareTargets ??= environment.IsDevelopment();

app.UseMiddleware<DebugProbeMiddleware>();
app.ApplicationServices.GetRequiredService<DebugEntryStore>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal static class CompareUrlValidator
return (false, null, "Failed to resolve compare server host");
}

if (!options.AllowLocalCompareTargets)
if (options.AllowLocalCompareTargets != true)
{
if (IsLocalHostName(parsed.Host))
{
Expand Down
5 changes: 3 additions & 2 deletions DebugProbe.AspNetCore/Options/DebugProbeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ public class DebugProbeOptions
internal int MaxBodyCaptureSizeBytes => MaxBodyCaptureSizeKb * 1024;

/// <summary>
/// Allows compare requests to local or private network targets.
/// Allows compare operations to target localhost and private network addresses.
/// Defaults to true in Development and false in other environments unless explicitly configured.
/// </summary>
public bool AllowLocalCompareTargets { get; set; }
public bool? AllowLocalCompareTargets { get; set; }

/// <summary>
/// Additional request paths to ignore.
Expand Down
1 change: 0 additions & 1 deletion DebugProbe.SampleApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
builder.Services.AddDebugProbe(options =>
{
options.MaxEntries = 10;
options.AllowLocalCompareTargets = true;
});

var app = builder.Build();
Expand Down
Loading