-
Notifications
You must be signed in to change notification settings - Fork 1
Add DevSecOps7 demo page with intentionally vulnerable code for GHAS detection #113
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,181 @@ | ||
| @page | ||
| @model DevSecOps7Model | ||
| @{ | ||
| ViewData["Title"] = "DevSecOps 7 - GitHub Advanced Security"; | ||
| } | ||
|
|
||
| <div class="container"> | ||
| <div class="row"> | ||
| <div class="col-12"> | ||
| <h1 class="display-4 text-primary">@ViewData["Title"]</h1> | ||
| <p class="lead">Explore the cutting-edge features and capabilities of GitHub Advanced Security (GHAS)</p> | ||
| <hr /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Alert for TempData messages --> | ||
| @if (TempData["RegexResult"] != null) | ||
| { | ||
| <div class="alert alert-info alert-dismissible fade show" role="alert"> | ||
| @TempData["RegexResult"] | ||
| <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
| </div> | ||
| } | ||
|
|
||
| @if (TempData["RegexError"] != null) | ||
| { | ||
| <div class="alert alert-danger alert-dismissible fade show" role="alert"> | ||
| @TempData["RegexError"] | ||
| <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-dark text-white"> | ||
| <h3 class="card-title mb-0"> | ||
| <i class="bi bi-shield-check"></i> Latest GitHub Advanced Security News | ||
| </h3> | ||
| </div> | ||
| <div class="card-body"> | ||
| @if (Model.LatestNews.Any()) | ||
| { | ||
| <div class="list-group list-group-flush"> | ||
| @foreach (var newsItem in Model.LatestNews) | ||
| { | ||
| <div class="list-group-item d-flex align-items-start"> | ||
| <span class="badge bg-success rounded-pill me-3 mt-1">NEW</span> | ||
| <div> | ||
| <p class="mb-1">@newsItem</p> | ||
| <small class="text-muted">Updated: @DateTime.Now.ToString("MMM dd, yyyy")</small> | ||
| </div> | ||
| </div> | ||
| } | ||
| </div> | ||
| } | ||
| else | ||
| { | ||
| <p class="text-muted">No news available at this time.</p> | ||
| } | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- GHAS Features Overview --> | ||
| <div class="card mb-4"> | ||
| <div class="card-header bg-primary text-white"> | ||
| <h3 class="card-title mb-0">Core GHAS Features</h3> | ||
| </div> | ||
| <div class="card-body"> | ||
| <div class="row"> | ||
| <div class="col-md-6"> | ||
| <h5><i class="bi bi-search"></i> Code Scanning</h5> | ||
| <p>Automated vulnerability detection using CodeQL semantic analysis engine.</p> | ||
|
|
||
| <h5><i class="bi bi-key"></i> Secret Scanning</h5> | ||
| <p>Detect and prevent secrets from being committed to repositories.</p> | ||
| </div> | ||
| <div class="col-md-6"> | ||
| <h5><i class="bi bi-layers"></i> Dependency Review</h5> | ||
| <p>Understand security impact of dependency changes in pull requests.</p> | ||
|
|
||
| <h5><i class="bi bi-graph-up"></i> Security Overview</h5> | ||
| <p>Organization-wide security posture visibility and compliance tracking.</p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Sidebar with Demo Tools --> | ||
| <div class="col-lg-4"> | ||
| <!-- Security Demo Section --> | ||
| <div class="card mb-4"> | ||
| <div class="card-header bg-warning text-dark"> | ||
| <h4 class="card-title mb-0"> | ||
| <i class="bi bi-exclamation-triangle"></i> Security Demo | ||
| </h4> | ||
| </div> | ||
| <div class="card-body"> | ||
| <p class="text-muted small"> | ||
| This page contains intentionally vulnerable code for demonstration purposes. | ||
| These vulnerabilities should be detected by GHAS code scanning. | ||
| </p> | ||
|
|
||
| <!-- Regex Testing Form --> | ||
| <form method="post" asp-page-handler="TestRegex" class="mt-3"> | ||
| <div class="mb-3"> | ||
| <label for="pattern" class="form-label">Test Regex Pattern:</label> | ||
| <input type="text" class="form-control" id="pattern" name="pattern" | ||
| placeholder="Enter pattern (e.g., aaa)" value="aaa"> | ||
| <div class="form-text"> | ||
| ⚠️ This uses a vulnerable regex pattern susceptible to ReDoS attacks. | ||
| </div> | ||
| </div> | ||
| <button type="submit" class="btn btn-warning btn-sm"> | ||
| <i class="bi bi-play"></i> Test Pattern | ||
| </button> | ||
| </form> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Quick Links --> | ||
| <div class="card"> | ||
| <div class="card-header bg-info text-white"> | ||
| <h4 class="card-title mb-0">Quick Links</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 Repository | ||
| </a> | ||
| <a href="https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning" class="btn btn-outline-success btn-sm" target="_blank"> | ||
| <i class="bi bi-shield-check"></i> Code Scanning Guide | ||
| </a> | ||
| <a href="https://docs.github.com/en/code-security/secret-scanning" class="btn btn-outline-warning btn-sm" target="_blank"> | ||
| <i class="bi bi-key"></i> Secret Scanning | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Footer Section --> | ||
| <div class="row mt-5"> | ||
| <div class="col-12"> | ||
| <div class="alert alert-light" role="alert"> | ||
| <h5 class="alert-heading"> | ||
| <i class="bi bi-lightbulb"></i> Pro Tip: | ||
| </h5> | ||
| <p> | ||
| Enable GitHub Advanced Security on your repositories to automatically detect the | ||
| security vulnerabilities demonstrated in this page's source code. GHAS will identify | ||
| issues like hardcoded credentials, vulnerable regex patterns, and potential log injection attacks. | ||
| </p> | ||
| <hr> | ||
| <p class="mb-0"> | ||
| Learn more about implementing a comprehensive DevSecOps strategy with | ||
| <a href="https://github.com/features/security" target="_blank">GitHub Advanced Security</a>. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| @section Scripts { | ||
| <script> | ||
| // Simple script to auto-dismiss alerts after 5 seconds | ||
| setTimeout(function() { | ||
| const alerts = document.querySelectorAll('.alert-dismissible'); | ||
| alerts.forEach(alert => { | ||
| const bsAlert = new bootstrap.Alert(alert); | ||
| bsAlert.close(); | ||
| }); | ||
| }, 5000); | ||
| </script> | ||
| } |
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,107 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 DevSecOps7Model : PageModel | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly ILogger<DevSecOps7Model> _logger; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Hardcoded credentials for demo purposes - INSECURE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private const string CONNECTION_STRING = "Server=localhost;Database=TestDB;User Id=admin;Password=SecretPassword123!;"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Weak regex pattern - vulnerable to ReDoS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static readonly Regex VulnerableRegex = new Regex(@"^(a+)+$", RegexOptions.Compiled); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public DevSecOps7Model(ILogger<DevSecOps7Model> logger) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger = logger; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public List<string> LatestNews { get; set; } = new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void OnGet() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Log forging vulnerability - user input directly in logs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string userInput = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.LogInformation($"User accessed DevSecOps7 page: {userInput}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 2 days ago To fix the vulnerability, user input that is being logged should be sanitized so that log forging via new lines or format-breaking characters is not possible. Since the log entry is written as plain text (not HTML), the recommended technique is to strip out all line breaks and similar control characters from the value before including it in the log. This can be done using If reused elsewhere, it may be beneficial to create a small helper for sanitization, but for now, only demonstrated where flagged.
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Simulate getting latest news about GitHub Advanced Security | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LoadLatestGHASNews(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Demonstrate potential ReDoS vulnerability | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 2 days ago To fix the inefficient use of string testPattern = Request.Query.ContainsKey("pattern") ? Request.Query["pattern"].ToString() ?? "aaa" : "aaa";with a call to
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.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 2 days ago The best way to fix the problem is to ensure that any regex operation on attacker-controlled input either (a) uses a regular expression with guaranteed low complexity, or (b) sets a timeout on the regex evaluation, preventing ReDoS. Since the purpose of this demo is to show security practices, it's prudent to fix the dangerous usage by using the overload of the .NET In this specific context, lines which call You will need to add Specifically:
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.LogInformation($"Regex pattern match result: {isMatch} for input: {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 2 days ago To fix this vulnerability, sanitize the user input (
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.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 in exception handling | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _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 2 days ago To fix the problem, we should sanitize any user input before it is included in log entries. Since the logging targets text logs (not HTML), the main danger is control characters such as newlines, carriage returns, and tabs, which can be used to forge/mislead log entries. The appropriate remediation is to remove these characters from any user-supplied input before logging. A suitable fix is to call A similar change should be applied to other log entries in the file that incorporate unsanitized user input (e.g., lines 31, 41, 89, 100, and possibly 95), but the direct fix required by the error is for line 46. Update line 46 in src/webapp01/Pages/DevSecOps7.cshtml.cs as follows:
If broader sanitization is desired, consider encapsulating the logic in a helper method within the file.
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+47
Check noticeCode scanning / CodeQL Generic catch clause Note
Generic catch clause.
Copilot AutofixAI 2 days ago To fix this error, we should update the
Strictly, the most likely runtime exception here is Therefore, in the try-catch block that wraps catch (Exception ex)with catch (RegexMatchTimeoutException ex)
catch (ArgumentNullException ex)ensuring the handler's body is the same (just logging). To implement this, we may need to add a Lines to change:
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Simulate database connection with hardcoded credentials | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using var connection = new SqlConnection(CONNECTION_STRING); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Insecure SQL connection High Connection string Error loading related location Loading
Copilot AutofixAI 2 days ago To fix the problem, edit the connection string specified within the
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.LogInformation("Attempting database connection..."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Don't actually open connection for demo purposes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (Exception ex) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.LogError($"Database connection failed: {ex.Message}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+59
Check noticeCode scanning / CodeQL Generic catch clause Note
Generic catch clause.
Copilot AutofixAI 2 days ago To resolve the problem, we should replace
Other aspects of the code remain unchanged. No new dependencies or libraries are required.
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void LoadLatestGHASNews() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LatestNews = new List<string> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "GitHub Advanced Security now supports enhanced code scanning with CodeQL 2.20", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "New secret scanning patterns added for over 200 service providers", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Dependency review alerts now include detailed remediation guidance", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Security advisories integration improved for better vulnerability management", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Custom CodeQL queries can now be shared across organizations", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "AI-powered security suggestions available in GitHub Copilot for Security", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "New compliance frameworks supported in security overview dashboard", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Enhanced SARIF support for third-party security tools integration" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Potential JSON deserialization vulnerability | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string jsonData = JsonConvert.SerializeObject(LatestNews); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 2 days ago To fix the problem, we should remove the assignment to the unused local variable (
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.LogInformation($"Loaded {LatestNews.Count} news items about GitHub Advanced Security"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public IActionResult OnPostTestRegex(string pattern) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(pattern)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return BadRequest("Pattern cannot be empty"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Log forging vulnerability in POST handler | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.LogInformation($"Testing regex pattern submitted by user: {pattern}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Vulnerable regex that could cause ReDoS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool result = VulnerableRegex.IsMatch(pattern); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TempData["RegexResult"] = $"Pattern '{pattern}' match result: {result}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (Exception ex) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Logging sensitive information | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.LogError($"Regex test failed for pattern: {pattern}. Exception: {ex}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TempData["RegexError"] = "Pattern evaluation failed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+97
to
+102
Check noticeCode scanning / CodeQL Generic catch clause Note
Generic catch clause.
Copilot AutofixAI 2 days ago To fix the problem, replace the broad catch (
Suggested changeset
1
src/webapp01/Pages/DevSecOps7.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 2 days ago
To fix the inefficient use of
ContainsKeyand the indexer onRequest.Query, replace the two operations with a singleTryGetValuecall. Specifically, in theOnGetmethod on line 30 in filesrc/webapp01/Pages/DevSecOps7.cshtml.cs, update the code so thatRequest.Query.TryGetValue("user", out var userVals)is used. This can then safely use the value if it exists, defaulting to"anonymous"if it doesn't or if conversion fails. The change is localized to line 30, and does not require any new imports, as all necessary functionality is provided by ASP.NET Core.