mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
Enhance rate limiting and mobile UI improvements for full mobile support!
Added new rate limiter policies "OneRequest" and "OneRequestPerIP" in `Program.cs`. Updated routing middleware and user authentication logic. Enhanced mobile navigation with a hamburger menu in multiple HTML files (`admin.html`, `user.html`, `archives.html`, `banned.html`, `error.html`, `login.html`, `paste.html`, `privatepaste.html`, `recent_pastes.html`). Introduced a notification system in `admin.html` and `login.html`. Updated CSS and JavaScript for better mobile responsiveness and user experience.
This commit is contained in:
+21
-4
@@ -40,6 +40,13 @@ class Program
|
||||
builder.Services.AddResponseCompression();
|
||||
|
||||
|
||||
builder.Services.AddRateLimiter(_ => _
|
||||
.AddFixedWindowLimiter(policyName: "OneRequest", options =>
|
||||
{
|
||||
options.PermitLimit = 1;
|
||||
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
|
||||
options.QueueLimit = 2;
|
||||
}));
|
||||
builder.Services.AddRateLimiter(_ => _
|
||||
.AddFixedWindowLimiter(policyName: "fixed", options =>
|
||||
{
|
||||
@@ -56,6 +63,16 @@ class Program
|
||||
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
|
||||
options.QueueLimit = 4;
|
||||
}));
|
||||
builder.Services.AddRateLimiter(options =>
|
||||
{
|
||||
options.AddPolicy("OneRequestPerIP", context =>
|
||||
RateLimitPartition.GetConcurrencyLimiter(context.Request.Headers["X-Forwarded-For"].ToString() ?? context.Connection.RemoteIpAddress?.ToString() ?? "unknown", key => new ConcurrencyLimiterOptions
|
||||
{
|
||||
PermitLimit = 1,
|
||||
QueueProcessingOrder = QueueProcessingOrder.OldestFirst,
|
||||
QueueLimit = 1
|
||||
}));
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@@ -69,7 +86,7 @@ class Program
|
||||
|
||||
//app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseRateLimiter();
|
||||
@@ -1477,7 +1494,7 @@ class Program
|
||||
string ip = context.Request.Headers["X-Forwarded-For"].ToString() ?? context.Connection.RemoteIpAddress.ToString();
|
||||
string uploaderUUID = string.Empty;
|
||||
string token = context.Request.Cookies["token"] ?? context.Request.Headers["Authorization"];
|
||||
|
||||
var user = await GetLoggedInUserAsync(token);
|
||||
|
||||
if (string.IsNullOrEmpty(requestBody))
|
||||
{
|
||||
@@ -1486,7 +1503,7 @@ class Program
|
||||
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No content uploaded" }.ToString());
|
||||
return;
|
||||
}
|
||||
if (await IsLoggedInAsync(token))
|
||||
if (string.IsNullOrEmpty(user.UUID))
|
||||
{
|
||||
using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
|
||||
{
|
||||
@@ -1497,7 +1514,7 @@ class Program
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
await reader.ReadAsync();
|
||||
uploaderUUID = reader.GetString(0);
|
||||
var user = await GetLoggedInUserAsync(token);
|
||||
|
||||
if (user.State != 0)
|
||||
{
|
||||
context.Response.StatusCode = 401;
|
||||
|
||||
Reference in New Issue
Block a user