Skip to content

Commit 9e3878b

Browse files
CopilotCalinL
andcommitted
Implement DevSecOps5 page with latest GHAS features and security demos
Co-authored-by: CalinL <10718943+CalinL@users.noreply.github.com>
1 parent 1c63dbc commit 9e3878b

File tree

4 files changed

+371
-0
lines changed

4 files changed

+371
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
@page
2+
@model DevSecOps5Model
3+
@{
4+
ViewData["Title"] = "DevSecOps5 - Latest GHAS Features Demo";
5+
}
6+
7+
<div class="container">
8+
<div class="row">
9+
<div class="col-12">
10+
<h1 class="display-4 text-primary">@ViewData["Title"]</h1>
11+
<p class="lead">Explore the newest features and capabilities of GitHub Advanced Security (GHAS) 2025</p>
12+
<hr />
13+
</div>
14+
</div>
15+
16+
<!-- Alert for demo messages -->
17+
@if (TempData["SecurityTest"] != null)
18+
{
19+
<div class="alert alert-warning alert-dismissible fade show" role="alert">
20+
<i class="bi bi-exclamation-triangle"></i> @TempData["SecurityTest"]
21+
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
22+
</div>
23+
}
24+
25+
<div class="row">
26+
<!-- Latest GHAS News Section -->
27+
<div class="col-lg-8">
28+
<div class="card mb-4">
29+
<div class="card-header bg-gradient bg-primary text-white">
30+
<h3 class="card-title mb-0">
31+
<i class="bi bi-newspaper"></i> Latest GitHub Advanced Security News 2025
32+
</h3>
33+
</div>
34+
<div class="card-body">
35+
@if (Model.LatestGHASNews.Any())
36+
{
37+
<div class="row">
38+
@foreach (var newsItem in Model.LatestGHASNews)
39+
{
40+
<div class="col-md-6 mb-3">
41+
<div class="card border-success">
42+
<div class="card-body">
43+
<span class="badge bg-success mb-2">HOT</span>
44+
<p class="card-text">@newsItem</p>
45+
</div>
46+
</div>
47+
</div>
48+
}
49+
</div>
50+
}
51+
else
52+
{
53+
<p class="text-muted">No latest news available.</p>
54+
}
55+
</div>
56+
</div>
57+
58+
<!-- GHAS 2025 Features Overview -->
59+
<div class="card mb-4">
60+
<div class="card-header bg-info text-white">
61+
<h3 class="card-title mb-0">🚀 GHAS 2025 Enhanced Features</h3>
62+
</div>
63+
<div class="card-body">
64+
<div class="row">
65+
<div class="col-md-6">
66+
<h5><i class="bi bi-robot"></i> AI-Powered Code Review</h5>
67+
<p>Enhanced CodeQL with AI suggestions for vulnerability remediation.</p>
68+
69+
<h5><i class="bi bi-shield-lock"></i> Advanced Secret Scanning</h5>
70+
<p>Real-time secret detection with custom pattern matching and auto-remediation.</p>
71+
</div>
72+
<div class="col-md-6">
73+
<h5><i class="bi bi-graph-up-arrow"></i> Supply Chain Security</h5>
74+
<p>Enhanced dependency graph with SBOM generation and license compliance.</p>
75+
76+
<h5><i class="bi bi-cloud-security"></i> Cloud Security Posture</h5>
77+
<p>Infrastructure as Code scanning with cloud configuration analysis.</p>
78+
</div>
79+
</div>
80+
</div>
81+
</div>
82+
</div>
83+
84+
<!-- Security Testing Sidebar -->
85+
<div class="col-lg-4">
86+
<!-- Vulnerability Demo Section -->
87+
<div class="card mb-4 border-warning">
88+
<div class="card-header bg-warning text-dark">
89+
<h4 class="card-title mb-0">
90+
<i class="bi bi-bug"></i> Security Vulnerability Demo
91+
</h4>
92+
</div>
93+
<div class="card-body">
94+
<p class="text-muted small">
95+
⚠️ This demo contains intentionally vulnerable code patterns for GHAS detection testing.
96+
</p>
97+
98+
<!-- SQL Test Form -->
99+
<form method="post" asp-page-handler="TestSql" class="mb-3">
100+
<div class="mb-3">
101+
<label for="sqlInput" class="form-label">SQL Query Test:</label>
102+
<input type="text" class="form-control" id="sqlInput" name="sqlInput"
103+
placeholder="Enter test query" value="SELECT * FROM users">
104+
<div class="form-text text-danger">
105+
⚠️ This may be vulnerable to SQL injection
106+
</div>
107+
</div>
108+
<button type="submit" class="btn btn-warning btn-sm">
109+
<i class="bi bi-play-circle"></i> Test SQL
110+
</button>
111+
</form>
112+
113+
<!-- Regex Test Form -->
114+
<form method="post" asp-page-handler="TestRegex" class="mb-3">
115+
<div class="mb-3">
116+
<label for="regexPattern" class="form-label">Regex Pattern Test:</label>
117+
<input type="text" class="form-control" id="regexPattern" name="regexPattern"
118+
placeholder="Enter regex pattern" value="(a+)+">
119+
<div class="form-text text-danger">
120+
⚠️ This may be vulnerable to ReDoS attacks
121+
</div>
122+
</div>
123+
<button type="submit" class="btn btn-warning btn-sm">
124+
<i class="bi bi-play-circle"></i> Test Regex
125+
</button>
126+
</form>
127+
</div>
128+
</div>
129+
130+
<!-- Quick Actions -->
131+
<div class="card">
132+
<div class="card-header bg-secondary text-white">
133+
<h4 class="card-title mb-0">GHAS Resources</h4>
134+
</div>
135+
<div class="card-body">
136+
<div class="d-grid gap-2">
137+
<a href="https://docs.github.com/en/code-security" class="btn btn-outline-primary btn-sm" target="_blank">
138+
<i class="bi bi-book"></i> GHAS Documentation
139+
</a>
140+
<a href="https://github.com/github/codeql" class="btn btn-outline-secondary btn-sm" target="_blank">
141+
<i class="bi bi-github"></i> CodeQL Queries
142+
</a>
143+
<a href="https://docs.github.com/en/code-security/code-scanning" class="btn btn-outline-success btn-sm" target="_blank">
144+
<i class="bi bi-shield-check"></i> Code Scanning Setup
145+
</a>
146+
</div>
147+
</div>
148+
</div>
149+
</div>
150+
</div>
151+
152+
<!-- Demo Stats Section -->
153+
<div class="row mt-4">
154+
<div class="col-12">
155+
<div class="card bg-light">
156+
<div class="card-body">
157+
<h5 class="card-title">Demo Statistics</h5>
158+
<div class="row text-center">
159+
<div class="col-md-3">
160+
<h4 class="text-danger">@Model.VulnerabilityCount</h4>
161+
<small>Vulnerabilities Detected</small>
162+
</div>
163+
<div class="col-md-3">
164+
<h4 class="text-warning">@Model.SecretsFound</h4>
165+
<small>Secrets Found</small>
166+
</div>
167+
<div class="col-md-3">
168+
<h4 class="text-info">@Model.DependenciesScanned</h4>
169+
<small>Dependencies Scanned</small>
170+
</div>
171+
<div class="col-md-3">
172+
<h4 class="text-success">@Model.SecurityScore</h4>
173+
<small>Security Score</small>
174+
</div>
175+
</div>
176+
</div>
177+
</div>
178+
</div>
179+
</div>
180+
</div>
181+
182+
<!-- Add Bootstrap Icons if not already included -->
183+
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Text.RegularExpressions;
4+
using Microsoft.Data.SqlClient;
5+
using Newtonsoft.Json;
6+
using System.Text.Json;
7+
8+
namespace webapp01.Pages
9+
{
10+
public class DevSecOps5Model : PageModel
11+
{
12+
private readonly ILogger<DevSecOps5Model> _logger;
13+
14+
// INSECURE: Hardcoded database credentials for demo purposes
15+
private const string DB_CONNECTION = "Server=localhost;Database=DemoApp;User Id=admin;Password=SuperSecret123!;TrustServerCertificate=true;";
16+
17+
// INSECURE: API Key hardcoded for demo purposes
18+
private const string API_KEY = "sk-demo-1234567890abcdef-NEVER-USE-IN-PROD";
19+
20+
// INSECURE: Vulnerable regex pattern susceptible to ReDoS attacks
21+
private static readonly Regex VulnerableRegex = new Regex(@"^(a+)+$", RegexOptions.Compiled);
22+
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);
23+
24+
public DevSecOps5Model(ILogger<DevSecOps5Model> logger)
25+
{
26+
_logger = logger;
27+
}
28+
29+
public List<string> LatestGHASNews { get; set; } = new();
30+
public int VulnerabilityCount { get; set; }
31+
public int SecretsFound { get; set; }
32+
public int DependenciesScanned { get; set; }
33+
public string SecurityScore { get; set; } = "C+";
34+
35+
public void OnGet()
36+
{
37+
// LOG FORGING: User input directly logged without sanitization
38+
string userAgent = Request.Headers.UserAgent.ToString();
39+
string ipAddress = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown";
40+
string userInput = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous";
41+
42+
// INSECURE: Direct user input in logs
43+
_logger.LogInformation($"DevSecOps5 page accessed by user: {userInput} from IP: {ipAddress} with UserAgent: {userAgent}");
44+
45+
LoadLatestGHASNews();
46+
GenerateSecurityStats();
47+
48+
// INSECURE: Simulate database connection with hardcoded credentials
49+
try
50+
{
51+
// Don't actually connect for demo, but log the attempt with sensitive info
52+
_logger.LogInformation($"Attempting database connection to: {DB_CONNECTION}");
53+
_logger.LogDebug($"Using API key: {API_KEY}");
54+
55+
using var connection = new SqlConnection(DB_CONNECTION);
56+
// Simulated connection - don't actually open
57+
58+
_logger.LogInformation("Database connection simulation completed");
59+
}
60+
catch (Exception ex)
61+
{
62+
// LOG FORGING: Exception details with user input
63+
_logger.LogError($"Database connection failed for user {userInput}: {ex.Message}");
64+
}
65+
66+
// INSECURE: Test vulnerable regex patterns
67+
TestVulnerableRegex();
68+
}
69+
70+
private void LoadLatestGHASNews()
71+
{
72+
LatestGHASNews = new List<string>
73+
{
74+
"GitHub Advanced Security now includes AI-powered vulnerability remediation suggestions",
75+
"New CodeQL 2.25 with enhanced C# and .NET analysis capabilities released",
76+
"Secret scanning now supports 500+ new token patterns including cloud services",
77+
"Dependency review with automated security updates and license compliance checking",
78+
"Advanced threat modeling integration with STRIDE methodology support",
79+
"Real-time security alerts with Slack and Microsoft Teams integration",
80+
"Enhanced SARIF support with custom security rule definitions",
81+
"Supply chain security with SBOM generation and provenance tracking"
82+
};
83+
84+
// INSECURE: Potential JSON deserialization vulnerability
85+
try
86+
{
87+
string jsonData = JsonConvert.SerializeObject(LatestGHASNews);
88+
// INSECURE: Deserializing without type validation
89+
var deserializedData = JsonConvert.DeserializeObject<List<string>>(jsonData);
90+
91+
_logger.LogInformation($"Successfully loaded {LatestGHASNews.Count} latest GHAS news items");
92+
}
93+
catch (Exception ex)
94+
{
95+
_logger.LogError($"Failed to process GHAS news: {ex.Message}");
96+
}
97+
}
98+
99+
private void GenerateSecurityStats()
100+
{
101+
// Simulate security statistics
102+
Random rand = new Random();
103+
VulnerabilityCount = rand.Next(15, 25);
104+
SecretsFound = rand.Next(3, 8);
105+
DependenciesScanned = rand.Next(150, 300);
106+
107+
string[] scores = { "A+", "A", "B+", "B", "C+", "C", "D" };
108+
SecurityScore = scores[rand.Next(scores.Length)];
109+
110+
_logger.LogInformation($"Generated security stats - Vulnerabilities: {VulnerabilityCount}, Secrets: {SecretsFound}, Dependencies: {DependenciesScanned}, Score: {SecurityScore}");
111+
}
112+
113+
private void TestVulnerableRegex()
114+
{
115+
// INSECURE: Testing with potentially dangerous regex patterns
116+
string testPattern = Request.Query.ContainsKey("pattern") ? Request.Query["pattern"].ToString() ?? "aaa" : "aaa";
117+
118+
try
119+
{
120+
bool isMatch = VulnerableRegex.IsMatch(testPattern);
121+
_logger.LogInformation($"Vulnerable regex test result: {isMatch} for pattern: {testPattern}");
122+
}
123+
catch (Exception ex)
124+
{
125+
// LOG FORGING: User input in error logs
126+
_logger.LogError($"Regex evaluation failed for pattern: {testPattern}. Error: {ex.Message}");
127+
}
128+
}
129+
130+
public IActionResult OnPostTestSql(string sqlInput)
131+
{
132+
if (!string.IsNullOrEmpty(sqlInput))
133+
{
134+
// INSECURE: Direct SQL input logging (potential injection vulnerability demo)
135+
_logger.LogWarning($"SQL test executed: {sqlInput}");
136+
137+
// INSECURE: Simulated SQL injection vulnerability
138+
string userAgent = Request.Headers.UserAgent.ToString();
139+
string queryToExecute = $"SELECT * FROM logs WHERE query = '{sqlInput}' AND user_agent = '{userAgent}'";
140+
141+
_logger.LogInformation($"Constructed query: {queryToExecute}");
142+
143+
TempData["SecurityTest"] = $"SQL Query processed: {sqlInput} (Check logs for potential injection patterns)";
144+
}
145+
146+
return RedirectToPage();
147+
}
148+
149+
public IActionResult OnPostTestRegex(string regexPattern)
150+
{
151+
if (!string.IsNullOrEmpty(regexPattern))
152+
{
153+
try
154+
{
155+
// INSECURE: User-provided regex pattern could cause ReDoS
156+
var userRegex = new Regex(regexPattern, RegexOptions.Compiled);
157+
string testString = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
158+
159+
// LOG FORGING: User input in logs
160+
_logger.LogWarning($"Testing user-provided regex pattern: {regexPattern}");
161+
162+
DateTime start = DateTime.Now;
163+
bool result = userRegex.IsMatch(testString);
164+
TimeSpan duration = DateTime.Now - start;
165+
166+
_logger.LogInformation($"Regex test completed in {duration.TotalMilliseconds}ms - Result: {result}");
167+
168+
TempData["SecurityTest"] = $"Regex pattern '{regexPattern}' processed in {duration.TotalMilliseconds:F2}ms - Result: {result}";
169+
}
170+
catch (Exception ex)
171+
{
172+
// LOG FORGING: Exception with user input
173+
_logger.LogError($"Regex test failed for pattern '{regexPattern}': {ex.Message}");
174+
TempData["SecurityTest"] = $"Regex test failed: {ex.Message}";
175+
}
176+
}
177+
178+
return RedirectToPage();
179+
}
180+
}
181+
}

src/webapp01/Pages/Index.cshtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
1313
<strong>New!</strong> Check out our <a asp-page="/DevSecOps" class="btn btn-primary btn-sm">DevSecOps Demo</a>
1414
page to see the latest GHAS features and security demonstrations.
1515
</p>
16+
<p class="card-text">
17+
<strong>Latest!</strong> Explore our enhanced <a asp-page="/DevSecOps5" class="btn btn-success btn-sm">DevSecOps5 Demo</a>
18+
featuring the newest 2025 GHAS capabilities and vulnerability testing.
19+
</p>
1620
</div>
1721
</div>

src/webapp01/Pages/Shared/_Layout.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<li class="nav-item">
2929
<a class="nav-link text-dark" asp-area="" asp-page="/DevSecOps">DevSecOps Demo</a>
3030
</li>
31+
<li class="nav-item">
32+
<a class="nav-link text-dark" asp-area="" asp-page="/DevSecOps5">DevSecOps5 Latest</a>
33+
</li>
3134
<li class="nav-item">
3235
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
3336
</li>

0 commit comments

Comments
 (0)