-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
public class LogForgingMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
private readonly ILogger<LogForgingMiddleware> _logger; | ||
|
||
public LogForgingMiddleware(RequestDelegate next, ILogger<LogForgingMiddleware> logger) | ||
{ | ||
_next = next; | ||
_logger = logger; | ||
} | ||
|
||
public async Task InvokeAsync(HttpContext context) | ||
{ | ||
string username = context.Request.Query["username"]; | ||
// BAD: User input logged as-is | ||
_logger.LogWarning(username + " log in requested."); | ||
Check failure Code scanning / CodeQL Log entries created from user input High
This log entry depends on a
user-provided value Error loading related location Loading |
||
// GOOD: User input logged with new-lines removed | ||
_logger.LogWarning(username?.Replace(Environment.NewLine, "") + " log in requested"); | ||
|
||
await _next(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,6 @@ | |
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
app.UseMiddleware<LogForgingMiddleware>(); | ||
|
||
app.Run(); |