Skip to content
Open
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 @@ -37,7 +37,7 @@ public IActionResult Index()
, blockDurationInSeconds: 6
, redirectToController: "home"
, redirectToAction: "index"
, id: (int)Filters.FireWallGuardModules.RejectRefreshViolations)]
, id: (int)Filters.FireWallGuardActions.RejectRefreshViolations)]
public async Task<IActionResult> Query(WhoisQuery model)
{

Expand Down Expand Up @@ -65,7 +65,7 @@ public async Task<IActionResult> Query(WhoisQuery model)
/// Allow the user to get 5 visits to the block page
/// </summary>
/// <returns></returns>
[Walter.Web.FireWall.Annotations.Ignore(skip: Filters.FireWallGuardModules.ALL, skipCount: 5)]
[Walter.Web.FireWall.Annotations.Ignore(skip: Filters.FireWallGuardActions.ALL, skipCount: 5)]
public IActionResult Blocked()
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MyFireWall(IServiceProvider serviceProvider, IMemoryCache memory, ILogger
foreach (var item in data)
{
item.AddHock = null;
item.NoValidate = Filters.FireWallGuardModules.RejectAddHockRequests | Filters.FireWallGuardModules.RejectCrossSiteRequests;
item.NoValidate = Filters.FireWallGuardActions.RejectAddHockRequests | Filters.FireWallGuardActions.RejectCrossSiteRequests;

}
data = KnownLinks.EndpointsInPath("*.css", "*.png", "*.jpg", "*.js");
Expand Down Expand Up @@ -181,7 +181,7 @@ private void MyFireWall_OnIncident(object sender, Walter.Web.FireWall.EventArgum
e.AllowRaiseIncident = true;

// It's no big deal if the user refreshes the page
if (e.Page.HasViolated(Filters.FireWallGuardModules.RejectRefreshViolations))
if (e.Page.HasViolated(Filters.FireWallGuardActions.RejectRefreshViolations))
{
e.AllowRaiseIncident = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IP2Location.IPGeolocation" Version="8.6.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" />
<PackageReference Include="IP2Location.IPGeolocation" Version="8.6.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="Walter.Web.FireWall" Version="2021.3.2.1415" />
<PackageReference Include="Walter.Web.FireWall.DefaultEndpoints" Version="2021.3.2.1415" />
<PackageReference Include="Walter.Web.FireWall" Version="2021.4.5.1653" />
<PackageReference Include="Walter.Web.FireWall.DefaultEndpoints" Version="2021.4.5.1653" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public UserDiscoveryController(ILogger<UserDiscoveryController> logger, IFireWal
/// there is also a Json version allowing you to automate monitoring
/// </remarks>
/// <returns>the text report of the firewall, </returns>
[Ignore(skip: FireWallGuardModules.API_ENDPOINT_LAX)]
[Ignore(skip: FireWallGuardActions.API_ENDPOINT_LAX)]
[NoCache]
[HttpGet("API/Reporting/Text")]
public string Get()
Expand Down Expand Up @@ -114,7 +114,8 @@ public IActionResult CSP(CSPModel model)
[HttpGet]
[NoCache]
[Route(Links.UserEndpointJavaScript)]
[Ignore(Walter.Web.FireWall.Filters.FireWallGuardModules.EmbeddedResources)]
[Ignore(Walter.Web.FireWall.Filters.FireWallGuardActions.EmbeddedResources)]
[FireWallConfiguration(FireWallConfigurationElement.DiscoveryJavaScript)]
public FileContentResult ValidateUser()
{
//use the ID to force reloading the script after the user has logged in or logged off
Expand All @@ -130,116 +131,91 @@ public FileContentResult ValidateUser()
}
else
{
_logger?.LogError("ValidateUser javascript generation failed for {Page}", _page.ToString());
javaScript = UTF8Encoding.UTF8.GetBytes($"console.log('could not generate userValidation')");
_logger?.Lazy().LogError("ValidateUser javascript generation failed for {Page}", _page.ToString());
javaScript = System.Text.UTF8Encoding.UTF8.GetBytes($"console.log('could not generate userValidation')");
return File(fileContents: javaScript, contentType: "text/javascript");
}
}
catch (ArgumentException e)
{
_page.Exception = e;

_fireWall.LogException<RunTimeErrors>(RunTimeErrors.ArgumentNullException, e, "Missing a configuration element or using wrong release for your deployment");
var javaScript = System.Diagnostics.Debugger.IsAttached
? UTF8Encoding.UTF8.GetBytes($"console.log('could not generate userValidation due to {e.Message}')")
: UTF8Encoding.UTF8.GetBytes($"//Validate log {DateTime.Now} for errors and update settings");
? System.Text.UTF8Encoding.UTF8.GetBytes($"console.log('could not generate userValidation due to {e.Message}')")
: System.Text.UTF8Encoding.UTF8.GetBytes($"//Validate log {DateTime.Now} for errors and update settings");
return File(fileContents: javaScript, contentType: "text/javascript");
}
catch (Exception e)
{
_page.Exception = e;

_fireWall.LogException<RunTimeErrors>(RunTimeErrors.ArgumentNullException, e, $"User type discovery will not work as good as it could please fix {e.Message}");
var javaScript = UTF8Encoding.UTF8.GetBytes($"console.log('could not generate userValidation due to {e.Message}')");
var javaScript = System.Text.UTF8Encoding.UTF8.GetBytes($"console.log('could not generate userValidation due to {e.Message}')");
return File(fileContents: javaScript, contentType: "text/javascript");
}
finally
{
_logger?.LogInformation("ValidateUser called");
_logger?.Lazy().LogInformation("ValidateUser called");
}
}

[HttpPost]
[Route(Links.BeaconPoint)]
[DisableFirewall]
[CrossSite(useDefaultRedirect: false), Ignore(skip: FireWallGuardModules.ALL & ~FireWallGuardModules.RejectCrossSiteRequests)]
public StatusCodeResult Beacon(string model)
[CrossSite, Ignore(skip: FireWallGuardActions.ALL & ~FireWallGuardActions.RejectCrossSiteRequests)]
[ModelFilter(associations: RequestersAssociations.InCurrentPage, generateIncident: false)]
[FireWallConfiguration(FireWallConfigurationElement.Beacon)]
public StatusCodeResult Beacon([FromBody] Beacon model)
{
if (!string.IsNullOrEmpty(model))
if (!ModelState.IsValid)
{
var beacon = JsonConvert.DeserializeObject<Beacon>(model);
_fireWall.ModelIsValid(pageContext: _page, model: beacon, out var errors);
if (errors.Sum(s => s.BlockinSeverityScore) < 100)
{
_fireWall.LogPageRequest(beacon, _page);
}
else
_logger?.Lazy().LogWarning("beacon: failed has {errors} errors", ModelState.ErrorCount);
return this.Ok();//no need to make a fuss
}


_fireWall.ModelIsValid(pageContext: _page, model: model, out var errors);
if (errors.Sum(s => s.BlockingSeverityScore) < 100)
{
_fireWall.LogPageRequest(model, _page);
}
else
{
foreach (var error in errors)
{
foreach (var error in errors)
{
_logger?.LogWarning("beacon: {warn}", error);
}
_logger?.Lazy().LogWarning("beacon: {warn}", error);
}
}
return this.Ok();
}

[HttpPost]
[Route(Links.IsUserEndpoint)]
[CrossSite(useDefaultRedirect: false), Ignore(skip: FireWallGuardModules.ALL & ~FireWallGuardModules.RejectCrossSiteRequests)]
public StatusCodeResult UserDiscovery([FromBody] Discovery model)
[CrossSite, Ignore(skip: FireWallGuardActions.ALL & ~FireWallGuardActions.RejectCrossSiteRequests)]
[FireWallConfiguration(FireWallConfigurationElement.DiscoveryModel)]
public StatusCodeResult UserDiscovery([FromBody] string json)
{
if (model is null)
{
_logger?.LogInformation("user discovery called but the model field or data types are not compatible, please wait, update the model to fix the users discovery javascript");
return this.NoContent();
}
else
if (_page.TryLogDiscovery(json))
{
_fireWall.ModelIsValid(pageContext: _page, model: model, out var errors);
if (errors.Count == 0 || (errors.Count > 0 && errors.Sum(s => s.BlockinSeverityScore) < 100))
{
_fireWall.LogPageRequest(model, _page);
return Ok();
}
else
{
_logger?.LogWarning("Assume an attempt was made to send a tampered model to {url} due to it achieving an error score of {score}", _page.OriginalUrl.AbsoluteUri, errors.Sum(s => s.BlockinSeverityScore));
if (errors.Sum(s => s.BlockinSeverityScore) > 100)
{
var fwu = _page.User.AsFirewallUser();
using (var scope = _logger?.BeginScope<string>($"User {fwu.Id} from {fwu.IPAddress} tampered with the model send back to {Links.IsUserEndpoint} and triggered {errors.Count} warnings"))
{
for (var i = 0; i < errors.Count; i++)
{
_logger?.LogWarning("incident:{count} reason:{reason} context:{context} weight:{weight}", i + 1, errors[i].Reason, errors[i].BlockingContext, errors[i].BlockinSeverityScore);
}
}
//tamper detected so return a 404
return this.NotFound();
}
//model data is not valid, could be tampered but could also just be not containing required values
return this.BadRequest();
}
return Ok();
}
return this.BadRequest();
}

[HttpPost]
[Route(Links.SiteMapEndPoint)]
[CrossSite(useDefaultRedirect: false), Ignore(skip: FireWallGuardModules.ALL & ~FireWallGuardModules.RejectCrossSiteRequests)]
public async Task<StatusCodeResult> SiteMap([FromBody] SiteMapDiscovery model)
[CrossSite(useDefaultRedirect: false), Ignore(skip: FireWallGuardActions.ALL & ~FireWallGuardActions.RejectCrossSiteRequests)]
[FireWallConfiguration(FireWallConfigurationElement.SiteMapModel)]
public async Task<StatusCodeResult> SiteMap([FromBody] string json)
{
_logger.Lazy().LogInformation("Url discovery called");

if (model is null)
return NoContent();
else
if (_page.TryLogSiteMap(json))
{
_fireWall.ModelIsValid(pageContext: _page, model: model, out var errors);

if (errors.Sum(s => s.BlockinSeverityScore) < 100 && _page.RootPage != null)
{
_logger.Lazy().LogDebug("Url discovery send to firewall");
await _fireWall.LogSiteMapAsync(page: _page, model: model).ConfigureAwait(false);
}
return Ok();
}
else
{
return BadRequest();
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Walter.Web.Firewall" Version="2021.3.2.1415" />
<PackageReference Include="Walter.Web.FireWall.SMTPLogger" Version="2021.3.2.1415" />
<PackageReference Include="Walter.Web.Firewall" Version="2021.4.5.1653" />
<PackageReference Include="Walter.Web.FireWall.SMTPLogger" Version="2021.4.5.1653" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public void ConfigureServices(IServiceCollection services)
services.AddFireWall<MyFireWall>(FireWallTrial.License, FireWallTrial.DomainKey, new Uri("https://www.mydomain.com", UriKind.Absolute), options =>

{


//use nuget package default endpoints to enable firewall management dashboard, than use administration to manage it
options.Administration.GenerateConnectFile = false;

options.Cypher.ApplicationPassword = "The password is 5 x 5, but I will not say in what order!";
options.UseSession = true;

Expand Down Expand Up @@ -162,10 +163,7 @@ public void ConfigureServices(IServiceCollection services)
//configure the firewall to be active on each request by registering the firewall filter
services.AddMvc(setupAction =>
{
//enable the firewall on all endpoints in this application
setupAction.Filters.Add<Walter.Web.FireWall.Filters.FireWallFilter>();
//inform the browser of our privacy policy if you render views

//inform the browser of our privacy policy if you render views
setupAction.Filters.Add<Walter.Web.FireWall.Filters.PrivacyPreferencesFilter>();
//view the filter documentation at https://firewallapi.asp-waf.com/?topic=html/N-Walter.Web.FireWall.Filters.htm

Expand Down