Skip to content

Commit d7c077d

Browse files
authored
Merge pull request #1048 from TechnologyEnhancedLearning/Develop/Fixes/TD-3730-No-Rate-Limiting-Enabled
Develop/fixes/td 3730 no rate limiting enabled
2 parents ee85515 + f1875e1 commit d7c077d

File tree

45 files changed

+422
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+422
-141
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ obj
5252
/OpenAPI/LearningHub.Nhs.OpenApi/web.config
5353
/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj.user
5454
/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user
55+
/ReportAPI/LearningHub.Nhs.ReportApi/web.config

AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<PackageReference Include="HtmlSanitizer" Version="6.0.453" />
9090
<PackageReference Include="IdentityModel" Version="4.6.0" />
9191
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.2" />
92-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.47" />
92+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.48" />
9393
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
9494
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.36" />
9595
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.36" />

LearningHub.Nhs.WebUI/Configuration/Settings.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ public Settings()
186186
/// </summary>
187187
public string GoogleAnalyticsId { get; set; }
188188

189+
/// <summary>
190+
/// Gets or sets the PasswordRequestLimitingPeriod.
191+
/// </summary>
192+
public int PasswordRequestLimitingPeriod { get; set; }
193+
194+
/// <summary>
195+
/// Gets or sets the PasswordRequestLimit.
196+
/// </summary>
197+
public int PasswordRequestLimit { get; set; }
198+
189199
/// <summary>
190200
/// Gets or sets the SupportUrls.
191201
/// </summary>

LearningHub.Nhs.WebUI/Controllers/AccountController.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,20 @@ public async Task<IActionResult> ForgotPassword(Models.Account.ForgotPasswordVie
11981198
return this.Ok(new { duplicate = true });
11991199
}
12001200

1201-
await this.userService.ForgotPasswordAsync(model.EmailAddress);
1202-
return this.View("ForgotPasswordAcknowledgement");
1201+
var passwordRequestLimitingPeriod = this.Settings.PasswordRequestLimitingPeriod;
1202+
var passwordRequestLimit = this.Settings.PasswordRequestLimit;
1203+
var status = await this.userService.CanRequestPasswordResetAsync(model.EmailAddress, passwordRequestLimitingPeriod, passwordRequestLimit);
1204+
if (status)
1205+
{
1206+
await this.userService.ForgotPasswordAsync(model.EmailAddress);
1207+
return this.View("ForgotPasswordAcknowledgement");
1208+
}
1209+
else
1210+
{
1211+
this.ViewBag.Period = passwordRequestLimitingPeriod;
1212+
this.ViewBag.Limit = passwordRequestLimit;
1213+
return this.View("TooManyRequests");
1214+
}
12031215
}
12041216

12051217
/// <summary>

LearningHub.Nhs.WebUI/Controllers/HomeController.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace LearningHub.Nhs.WebUI.Controllers
66
using System.Linq;
77
using System.Net.Http;
88
using System.Threading.Tasks;
9-
using elfhHub.Nhs.Models.Common;
109
using LearningHub.Nhs.Models.Content;
1110
using LearningHub.Nhs.Models.Enums.Content;
1211
using LearningHub.Nhs.Models.Extensions;
@@ -21,7 +20,6 @@ namespace LearningHub.Nhs.WebUI.Controllers
2120
using Microsoft.AspNetCore.Diagnostics;
2221
using Microsoft.AspNetCore.Hosting;
2322
using Microsoft.AspNetCore.Mvc;
24-
using Microsoft.Extensions.Configuration;
2523
using Microsoft.Extensions.Logging;
2624
using Microsoft.Extensions.Options;
2725
using Microsoft.FeatureManagement;
@@ -54,7 +52,6 @@ public class HomeController : BaseController
5452
/// <param name="dashboardService">Dashboard service.</param>
5553
/// <param name="contentService">Content service.</param>
5654
/// <param name="featureManager"> featureManager.</param>
57-
/// <param name="configuration"> config.</param>
5855
public HomeController(
5956
IHttpClientFactory httpClientFactory,
6057
IWebHostEnvironment hostingEnvironment,
@@ -65,8 +62,7 @@ public HomeController(
6562
LearningHubAuthServiceConfig authConfig,
6663
IDashboardService dashboardService,
6764
IContentService contentService,
68-
IFeatureManager featureManager,
69-
Microsoft.Extensions.Configuration.IConfiguration configuration)
65+
IFeatureManager featureManager)
7066
: base(hostingEnvironment, httpClientFactory, logger, settings.Value)
7167
{
7268
this.authConfig = authConfig;
@@ -75,7 +71,6 @@ public HomeController(
7571
this.dashboardService = dashboardService;
7672
this.contentService = contentService;
7773
this.featureManager = featureManager;
78-
this.configuration = configuration;
7974
}
8075

8176
/// <summary>
@@ -170,26 +165,16 @@ public IActionResult Error(int? httpStatusCode)
170165
}
171166
else
172167
{
173-
if (originalPath == "/TooManyRequests")
168+
this.ViewBag.ErrorHeader = httpStatusCode.Value switch
174169
{
175-
this.ViewBag.Period = this.configuration["IpRateLimiting:GeneralRules:0:Period"];
176-
this.ViewBag.Limit = this.configuration["IpRateLimiting:GeneralRules:0:Limit"];
177-
178-
return this.View("TooManyRequests");
179-
}
180-
else
181-
{
182-
this.ViewBag.ErrorHeader = httpStatusCode.Value switch
183-
{
184-
401 => "You do not have permission to access this page",
185-
404 => "We cannot find the page you are looking for",
186-
_ => "We cannot find the page you are looking for",
187-
};
170+
401 => "You do not have permission to access this page",
171+
404 => "We cannot find the page you are looking for",
172+
_ => "We cannot find the page you are looking for",
173+
};
188174

189-
this.ViewBag.HttpStatusCode = httpStatusCode.Value;
190-
this.ViewBag.HomePageUrl = "/home";
191-
return this.View("CustomError");
192-
}
175+
this.ViewBag.HttpStatusCode = httpStatusCode.Value;
176+
this.ViewBag.HomePageUrl = "/home";
177+
return this.View("CustomError");
193178
}
194179
}
195180

LearningHub.Nhs.WebUI/Interfaces/IUserService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,15 @@ public interface IUserService
418418
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
419419
Task<EmailChangeValidationTokenViewModel> RegenerateEmailChangeValidationTokenAsync(string newPrimaryEmail, bool isUserRoleUpgrade);
420420

421+
/// <summary>
422+
/// User Can request for password reset.
423+
/// </summary>
424+
/// <param name="emailAddress">The email Address.</param>
425+
/// <param name="passwordRequestLimitingPeriod">The passwordRequestLimitingPeriod.</param>
426+
/// <param name="passwordRequestLimit">ThepasswordRequestLimit.</param>
427+
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
428+
Task<bool> CanRequestPasswordResetAsync(string emailAddress, int passwordRequestLimitingPeriod, int passwordRequestLimit);
429+
421430
/// <summary>
422431
/// GenerateEmailChangeValidationTokenAndSendEmail.
423432
/// </summary>

LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<PackageReference Include="HtmlAgilityPack" Version="1.11.72" />
114114
<PackageReference Include="IdentityModel" Version="4.6.0" />
115115
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
116-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.47" />
116+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.48" />
117117
<PackageReference Include="linqtotwitter" Version="6.9.0" />
118118
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
119119
<PackageReference Include="Microsoft.ApplicationInsights.EventCounterCollector" Version="2.21.0" />

LearningHub.Nhs.WebUI/Middleware/LHIPRateLimitMiddleware.cs

Lines changed: 0 additions & 57 deletions
This file was deleted.

LearningHub.Nhs.WebUI/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
app.UseAuthorization();
8585

8686
app.UseMiddleware<NLogMiddleware>();
87-
app.UseMiddleware<LHIPRateLimitMiddleware>();
8887
app.UseStaticFiles();
8988

9089
app.Map(TimezoneInfoMiddleware.TimezoneInfoUrl, b => b.UseMiddleware<TimezoneInfoMiddleware>());

LearningHub.Nhs.WebUI/ServiceCollectionExtension.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ public static void ConfigureServices(this IServiceCollection services, IConfigur
111111
}
112112
});
113113

114-
ConfigureIpRateLimiting(services, configuration);
115-
116114
// this method setup so httpcontext is available from controllers
117115
services.AddHttpContextAccessor();
118116
services.AddSingleton(learningHubAuthSvcConf);
@@ -139,17 +137,5 @@ public static void ConfigureServices(this IServiceCollection services, IConfigur
139137

140138
services.AddFeatureManagement();
141139
}
142-
143-
/// <summary>
144-
/// ConfigureIpRateLimiting.
145-
/// </summary>
146-
/// <param name="services">The services.</param>
147-
/// <param name="configuration">The configuration.</param>
148-
private static void ConfigureIpRateLimiting(IServiceCollection services, IConfiguration configuration)
149-
{
150-
services.Configure<IpRateLimitOptions>(configuration.GetSection("IpRateLimiting"));
151-
services.AddInMemoryRateLimiting();
152-
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
153-
}
154140
}
155141
}

0 commit comments

Comments
 (0)