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 @@ -112,7 +112,11 @@ private static void ValidateReportingEndpoints(NetSecureHeadersOptions options,
{
failures.Add($"{scope}: Reporting endpoint '{endpoint.Group}' URL must not be null, empty, or whitespace. Fix: provide an absolute HTTPS URL such as 'https://reports.example.com/csp'.");
}
else if (!Uri.TryCreate(endpoint.Url, UriKind.Absolute, out _))
else if (!Uri.TryCreate(endpoint.Url, UriKind.Absolute, out var uri))
{
failures.Add($"{scope}: Reporting endpoint '{endpoint.Group}' URL must be absolute. Fix: use a full URL such as 'https://reports.example.com/csp'.");
}
else if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)
{
failures.Add($"{scope}: Reporting endpoint '{endpoint.Group}' URL must be absolute. Fix: use a full URL such as 'https://reports.example.com/csp'.");
}
Expand Down
20 changes: 20 additions & 0 deletions tests/SafeWebCore.Tests/NetSecureHeadersOptionsValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ public void StartWithRelativeReportingEndpointUrlThrowsOptionsValidationExceptio
Assert.Contains("Fix: use a full URL such as 'https://reports.example.com/csp'", exception.Message);
}

[Fact]
public void NonHttpSchemeReportingEndpointUrlThrowsOptionsValidationException()
{
// Arrange
var hostBuilder = CreateHostBuilder(opts =>
{
opts.ReportingEndpoints.Add(new()
{
Group = "default",
Url = "file:///reports"
});
});

// Act
var exception = Assert.Throws<OptionsValidationException>(() => hostBuilder.Start());

// Assert
Assert.Contains("Reporting endpoint 'default' URL must be absolute", exception.Message);
}

[Fact]
public void StartWithNelEnabledButEmptyNelValueThrowsOptionsValidationException()
{
Expand Down
Loading