-
Notifications
You must be signed in to change notification settings - Fork 1
Add DevSecOps page with security news and examples; update project dependencies #67
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 1 commit
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,19 @@ | ||
@page | ||
@model webapp01.Pages.DevSecOpsModel | ||
@{ | ||
ViewData["Title"] = "DevSecOps"; | ||
} | ||
|
||
<h2>DevSecOps & GitHub Advanced Security News</h2> | ||
<div> | ||
<ul> | ||
<li><strong>May 2025:</strong> GitHub Advanced Security now supports secret scanning for custom patterns.</li> | ||
<li><strong>April 2025:</strong> Code scanning with CodeQL adds new C# queries for insecure deserialization.</li> | ||
<li><strong>March 2025:</strong> Push protection for credentials is now enabled by default for all repos.</li> | ||
</ul> | ||
</div> | ||
<p>Below is a demonstration of insecure C# code for educational purposes only.</p> | ||
<pre> | ||
@Model.InsecureLogExample | ||
@Model.InsecureRegexExample | ||
</pre> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||||||||||||||||||||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||||||||||||||||||||||||||
using Microsoft.Extensions.Logging; | ||||||||||||||||||||||||||
using System.Text.RegularExpressions; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
namespace webapp01.Pages | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
public class DevSecOpsModel : PageModel | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
private readonly ILogger<DevSecOpsModel> _logger; | ||||||||||||||||||||||||||
public string InsecureLogExample { get; private set; } | ||||||||||||||||||||||||||
public string InsecureRegexExample { get; private set; } | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public DevSecOpsModel(ILogger<DevSecOpsModel> logger) | ||||||||||||||||||||||||||
Check warning on line 13 in src/webapp01/Pages/DevSecOps.cshtml.cs
|
||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
_logger = logger; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public void OnGet() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
// Insecure log forging example | ||||||||||||||||||||||||||
string userInput = "attacker\nInjectedLogEntry"; | ||||||||||||||||||||||||||
_logger.LogInformation("User input: {UserInput}", userInput); | ||||||||||||||||||||||||||
InsecureLogExample = $"_logger.LogInformation(\"User input: {{UserInput}}\", \"{userInput}\");"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Insecure regex example (ReDoS) | ||||||||||||||||||||||||||
string evilInput = new string('a', 10000) + "!"; | ||||||||||||||||||||||||||
string pattern = "(a+)+!"; | ||||||||||||||||||||||||||
try | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
Regex.Match(evilInput, pattern); | ||||||||||||||||||||||||||
InsecureRegexExample = $"Regex.Match(evilInput, \"{pattern}\"); // Potential ReDoS"; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
catch { } | ||||||||||||||||||||||||||
Check noticeCode scanning / CodeQL Generic catch clause Note
Generic catch clause.
Copilot AutofixAI 17 days ago To fix the issue, we will replace the generic
Suggested changeset
1
src/webapp01/Pages/DevSecOps.cshtml.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} |
Check notice
Code scanning / CodeQL
Poor error handling: empty catch block Note
Copilot Autofix
AI 17 days ago
To fix the issue, the empty catch block should be replaced with proper exception handling. At a minimum, the exception should be logged to provide visibility into what went wrong. Depending on the application's requirements, additional actions (e.g., notifying the user, retrying the operation) may also be necessary.
In this case, we will log the exception using the
_logger
instance, which is already available in the class. This ensures that any issues with theRegex.Match
operation are recorded for debugging and monitoring purposes.