-
Notifications
You must be signed in to change notification settings - Fork 1
Implement DevSecOps5 page with latest GHAS features and security vulnerability demos #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
@page | ||
@model DevSecOps5Model | ||
@{ | ||
ViewData["Title"] = "DevSecOps5 - Latest GHAS Features Demo"; | ||
} | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<h1 class="display-4 text-primary">@ViewData["Title"]</h1> | ||
<p class="lead">Explore the newest features and capabilities of GitHub Advanced Security (GHAS) 2025</p> | ||
<hr /> | ||
</div> | ||
</div> | ||
|
||
<!-- Alert for demo messages --> | ||
@if (TempData["SecurityTest"] != null) | ||
{ | ||
<div class="alert alert-warning alert-dismissible fade show" role="alert"> | ||
<i class="bi bi-exclamation-triangle"></i> @TempData["SecurityTest"] | ||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
</div> | ||
} | ||
|
||
<div class="row"> | ||
<!-- Latest GHAS News Section --> | ||
<div class="col-lg-8"> | ||
<div class="card mb-4"> | ||
<div class="card-header bg-gradient bg-primary text-white"> | ||
<h3 class="card-title mb-0"> | ||
<i class="bi bi-newspaper"></i> Latest GitHub Advanced Security News 2025 | ||
</h3> | ||
</div> | ||
<div class="card-body"> | ||
@if (Model.LatestGHASNews.Any()) | ||
{ | ||
<div class="row"> | ||
@foreach (var newsItem in Model.LatestGHASNews) | ||
{ | ||
<div class="col-md-6 mb-3"> | ||
<div class="card border-success"> | ||
<div class="card-body"> | ||
<span class="badge bg-success mb-2">HOT</span> | ||
<p class="card-text">@newsItem</p> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
</div> | ||
} | ||
else | ||
{ | ||
<p class="text-muted">No latest news available.</p> | ||
} | ||
</div> | ||
</div> | ||
|
||
<!-- GHAS 2025 Features Overview --> | ||
<div class="card mb-4"> | ||
<div class="card-header bg-info text-white"> | ||
<h3 class="card-title mb-0">🚀 GHAS 2025 Enhanced Features</h3> | ||
</div> | ||
<div class="card-body"> | ||
<div class="row"> | ||
<div class="col-md-6"> | ||
<h5><i class="bi bi-robot"></i> AI-Powered Code Review</h5> | ||
<p>Enhanced CodeQL with AI suggestions for vulnerability remediation.</p> | ||
|
||
<h5><i class="bi bi-shield-lock"></i> Advanced Secret Scanning</h5> | ||
<p>Real-time secret detection with custom pattern matching and auto-remediation.</p> | ||
</div> | ||
<div class="col-md-6"> | ||
<h5><i class="bi bi-graph-up-arrow"></i> Supply Chain Security</h5> | ||
<p>Enhanced dependency graph with SBOM generation and license compliance.</p> | ||
|
||
<h5><i class="bi bi-cloud-security"></i> Cloud Security Posture</h5> | ||
<p>Infrastructure as Code scanning with cloud configuration analysis.</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Security Testing Sidebar --> | ||
<div class="col-lg-4"> | ||
<!-- Vulnerability Demo Section --> | ||
<div class="card mb-4 border-warning"> | ||
<div class="card-header bg-warning text-dark"> | ||
<h4 class="card-title mb-0"> | ||
<i class="bi bi-bug"></i> Security Vulnerability Demo | ||
</h4> | ||
</div> | ||
<div class="card-body"> | ||
<p class="text-muted small"> | ||
⚠️ This demo contains intentionally vulnerable code patterns for GHAS detection testing. | ||
</p> | ||
|
||
<!-- SQL Test Form --> | ||
<form method="post" asp-page-handler="TestSql" class="mb-3"> | ||
<div class="mb-3"> | ||
<label for="sqlInput" class="form-label">SQL Query Test:</label> | ||
<input type="text" class="form-control" id="sqlInput" name="sqlInput" | ||
placeholder="Enter test query" value="SELECT * FROM users"> | ||
<div class="form-text text-danger"> | ||
⚠️ This may be vulnerable to SQL injection | ||
</div> | ||
</div> | ||
<button type="submit" class="btn btn-warning btn-sm"> | ||
<i class="bi bi-play-circle"></i> Test SQL | ||
</button> | ||
</form> | ||
|
||
<!-- Regex Test Form --> | ||
<form method="post" asp-page-handler="TestRegex" class="mb-3"> | ||
<div class="mb-3"> | ||
<label for="regexPattern" class="form-label">Regex Pattern Test:</label> | ||
<input type="text" class="form-control" id="regexPattern" name="regexPattern" | ||
placeholder="Enter regex pattern" value="(a+)+"> | ||
<div class="form-text text-danger"> | ||
⚠️ This may be vulnerable to ReDoS attacks | ||
</div> | ||
</div> | ||
<button type="submit" class="btn btn-warning btn-sm"> | ||
<i class="bi bi-play-circle"></i> Test Regex | ||
</button> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
<!-- Quick Actions --> | ||
<div class="card"> | ||
<div class="card-header bg-secondary text-white"> | ||
<h4 class="card-title mb-0">GHAS Resources</h4> | ||
</div> | ||
<div class="card-body"> | ||
<div class="d-grid gap-2"> | ||
<a href="https://docs.github.com/en/code-security" class="btn btn-outline-primary btn-sm" target="_blank"> | ||
<i class="bi bi-book"></i> GHAS Documentation | ||
</a> | ||
<a href="https://github.com/github/codeql" class="btn btn-outline-secondary btn-sm" target="_blank"> | ||
<i class="bi bi-github"></i> CodeQL Queries | ||
</a> | ||
<a href="https://docs.github.com/en/code-security/code-scanning" class="btn btn-outline-success btn-sm" target="_blank"> | ||
<i class="bi bi-shield-check"></i> Code Scanning Setup | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Demo Stats Section --> | ||
<div class="row mt-4"> | ||
<div class="col-12"> | ||
<div class="card bg-light"> | ||
<div class="card-body"> | ||
<h5 class="card-title">Demo Statistics</h5> | ||
<div class="row text-center"> | ||
<div class="col-md-3"> | ||
<h4 class="text-danger">@Model.VulnerabilityCount</h4> | ||
<small>Vulnerabilities Detected</small> | ||
</div> | ||
<div class="col-md-3"> | ||
<h4 class="text-warning">@Model.SecretsFound</h4> | ||
<small>Secrets Found</small> | ||
</div> | ||
<div class="col-md-3"> | ||
<h4 class="text-info">@Model.DependenciesScanned</h4> | ||
<small>Dependencies Scanned</small> | ||
</div> | ||
<div class="col-md-3"> | ||
<h4 class="text-success">@Model.SecurityScore</h4> | ||
<small>Security Score</small> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Add Bootstrap Icons if not already included --> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet"> |
Original file line number | Diff line number | Diff line change | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,181 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using Microsoft.AspNetCore.Mvc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using Microsoft.AspNetCore.Mvc.RazorPages; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using System.Text.RegularExpressions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using Microsoft.Data.SqlClient; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using Newtonsoft.Json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using System.Text.Json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace webapp01.Pages | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public class DevSecOps5Model : PageModel | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private readonly ILogger<DevSecOps5Model> _logger; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Hardcoded database credentials for demo purposes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private const string DB_CONNECTION = "Server=localhost;Database=DemoApp;User Id=admin;Password=SuperSecret123!;TrustServerCertificate=true;"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: API Key hardcoded for demo purposes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private const string API_KEY = "sk-demo-1234567890abcdef-NEVER-USE-IN-PROD"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Vulnerable regex pattern susceptible to ReDoS attacks | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private static readonly Regex VulnerableRegex = new Regex(@"^(a+)+$", RegexOptions.Compiled); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private static readonly Regex EmailRegex = new Regex(@"^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$", RegexOptions.Compiled); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public DevSecOps5Model(ILogger<DevSecOps5Model> logger) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger = logger; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public List<string> LatestGHASNews { get; set; } = new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public int VulnerabilityCount { get; set; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public int SecretsFound { get; set; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public int DependenciesScanned { get; set; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public string SecurityScore { get; set; } = "C+"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void OnGet() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// LOG FORGING: User input directly logged without sanitization | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string userAgent = Request.Headers.UserAgent.ToString(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string ipAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string userInput = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Direct user input in logs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogInformation($"DevSecOps5 page accessed by user: {userInput} from IP: {ipAddress} with UserAgent: {userAgent}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Log entries created from user input High
This log entry depends on a
user-provided value Error loading related location Loading
Copilot AutofixAI about 2 months ago To fix this problem, sanitize user-provided input before including it in any log statement. For logs intended to be stored and reviewed as plain text, newline and carriage return characters should be removed or replaced from the user-provided strings to prevent log forging. The simplest way is to replace them with empty strings or with visible delimiters (like a space). In this code, sanitize the
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LoadLatestGHASNews(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GenerateSecurityStats(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Simulate database connection with hardcoded credentials | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Don't actually connect for demo, but log the attempt with sensitive info | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogInformation($"Attempting database connection to: {DB_CONNECTION}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogDebug($"Using API key: {API_KEY}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using var connection = new SqlConnection(DB_CONNECTION); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Simulated connection - don't actually open | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogInformation("Database connection simulation completed"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catch (Exception ex) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// LOG FORGING: Exception details with user input | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogError($"Database connection failed for user {userInput}: {ex.Message}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Log entries created from user input High
This log entry depends on a
user-provided value Error loading related location Loading
Copilot AutofixAI about 2 months ago To fix the problem, sanitize the user input before logging it. Since the logs are likely plain text, the best practice is to remove or replace newline characters (
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+60
to
+64
Check noticeCode scanning / CodeQL Generic catch clause Note
Generic catch clause.
Copilot AutofixAI about 2 months ago To fix the problem, the catch clause on line 60 should be changed to catch only specific exception types that are expected from the simulated database connection code. Since the code is using Edit only the catch clause on line 60 in
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Test vulnerable regex patterns | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TestVulnerableRegex(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private void LoadLatestGHASNews() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LatestGHASNews = new List<string> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"GitHub Advanced Security now includes AI-powered vulnerability remediation suggestions", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"New CodeQL 2.25 with enhanced C# and .NET analysis capabilities released", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Secret scanning now supports 500+ new token patterns including cloud services", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Dependency review with automated security updates and license compliance checking", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Advanced threat modeling integration with STRIDE methodology support", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Real-time security alerts with Slack and Microsoft Teams integration", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Enhanced SARIF support with custom security rule definitions", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Supply chain security with SBOM generation and provenance tracking" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Potential JSON deserialization vulnerability | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string jsonData = JsonConvert.SerializeObject(LatestGHASNews); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Deserializing without type validation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var deserializedData = JsonConvert.DeserializeObject<List<string>>(jsonData); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / CodeQL Useless assignment to local variable Warning
This assignment to
deserializedData Error loading related location Loading
Copilot AutofixAI about 2 months ago To fix this problem, we should remove the useless assignment to the local variable
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogInformation($"Successfully loaded {LatestGHASNews.Count} latest GHAS news items"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catch (Exception ex) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogError($"Failed to process GHAS news: {ex.Message}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+93
to
+96
Check noticeCode scanning / CodeQL Generic catch clause Note
Generic catch clause.
Copilot AutofixAI about 2 months ago To fix the problem, replace the generic
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private void GenerateSecurityStats() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Simulate security statistics | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Random rand = new Random(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VulnerabilityCount = rand.Next(15, 25); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SecretsFound = rand.Next(3, 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DependenciesScanned = rand.Next(150, 300); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string[] scores = { "A+", "A", "B+", "B", "C+", "C", "D" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SecurityScore = scores[rand.Next(scores.Length)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogInformation($"Generated security stats - Vulnerabilities: {VulnerabilityCount}, Secrets: {SecretsFound}, Dependencies: {DependenciesScanned}, Score: {SecurityScore}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private void TestVulnerableRegex() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Testing with potentially dangerous regex patterns | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string testPattern = Request.Query.ContainsKey("pattern") ? Request.Query["pattern"].ToString() ?? "aaa" : "aaa"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / CodeQL Inefficient use of ContainsKey Note
Inefficient use of 'ContainsKey' and
indexer Error loading related location Loading
Copilot AutofixAI about 2 months ago To resolve the "inefficient use of ContainsKey" error detected by CodeQL on line 116, replace the separate use of Edit required:
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bool isMatch = VulnerableRegex.IsMatch(testPattern); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Denial of Service from comparison of user input against expensive regex High
This regex operation with dangerous complexity depends on a
user-provided value Error loading related location Loading
Copilot AutofixAI about 2 months ago To mitigate the risk of regex-based denial of service, the best fix is to specify a timeout for the regex operation. In C#, this can be done by constructing the Required changes:
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogInformation($"Vulnerable regex test result: {isMatch} for pattern: {testPattern}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Log entries created from user input High
This log entry depends on a
user-provided value Error loading related location Loading
Copilot AutofixAI about 2 months ago To fix the problem, we need to sanitize the user input (
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catch (Exception ex) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// LOG FORGING: User input in error logs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogError($"Regex evaluation failed for pattern: {testPattern}. Error: {ex.Message}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Log entries created from user input High
This log entry depends on a
user-provided value Error loading related location Loading
Copilot AutofixAI about 2 months ago To fix the log forging vulnerability, we must sanitize the user input (
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+123
to
+127
Check noticeCode scanning / CodeQL Generic catch clause Note
Generic catch clause.
Copilot AutofixAI about 2 months ago To fix the problem, the catch clause should be narrowed to only handle exceptions that are expected from the
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public IActionResult OnPostTestSql(string sqlInput) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!string.IsNullOrEmpty(sqlInput)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Direct SQL input logging (potential injection vulnerability demo) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogWarning($"SQL test executed: {sqlInput}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: Simulated SQL injection vulnerability | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string userAgent = Request.Headers.UserAgent.ToString(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string queryToExecute = $"SELECT * FROM logs WHERE query = '{sqlInput}' AND user_agent = '{userAgent}'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogInformation($"Constructed query: {queryToExecute}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TempData["SecurityTest"] = $"SQL Query processed: {sqlInput} (Check logs for potential injection patterns)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return RedirectToPage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public IActionResult OnPostTestRegex(string regexPattern) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!string.IsNullOrEmpty(regexPattern)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// INSECURE: User-provided regex pattern could cause ReDoS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var userRegex = new Regex(regexPattern, RegexOptions.Compiled); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
string testString = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// LOG FORGING: User input in logs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogWarning($"Testing user-provided regex pattern: {regexPattern}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DateTime start = DateTime.Now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bool result = userRegex.IsMatch(testString); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TimeSpan duration = DateTime.Now - start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogInformation($"Regex test completed in {duration.TotalMilliseconds}ms - Result: {result}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TempData["SecurityTest"] = $"Regex pattern '{regexPattern}' processed in {duration.TotalMilliseconds:F2}ms - Result: {result}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catch (Exception ex) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// LOG FORGING: Exception with user input | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_logger.LogError($"Regex test failed for pattern '{regexPattern}': {ex.Message}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TempData["SecurityTest"] = $"Regex test failed: {ex.Message}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+170
to
+175
Check noticeCode scanning / CodeQL Generic catch clause Note
Generic catch clause.
Copilot AutofixAI about 2 months ago To fix the problem, we should replace the generic
Suggested changeset
1
src/webapp01/Pages/DevSecOps5.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return RedirectToPage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Check notice
Code scanning / CodeQL
Inefficient use of ContainsKey Note
Copilot Autofix
AI about 2 months ago
To fix the flagged inefficiency on line 40, replace the current pattern:
with the more efficient approach using
TryGetValue
:However, since the original code is a single-line assignment of
userInput
, and we want to keep the assignment style, we can use a short inline replacement:But this does not handle the case where
TryGetValue
fails; it would leaveuserValue
asdefault
(i.e., an empty StringValues, not null; its.ToString()
is ""), which would change behavior (returns empty string rather than "anonymous"). It's best to use an if/else or a conditional operator. So, this is the ideal inline replacement:This preserves semantics—if the "user" query string has a value, use it; otherwise, use "anonymous".
Only the code at line 40 in src/webapp01/Pages/DevSecOps5.cshtml.cs needs changing; no new imports or methods are required.