Skip to content

Commit c0630c6

Browse files
CopilotCalinL
andcommitted
Add DevSecOps-4837 demo page with GHAS features and intentional vulnerabilities
Co-authored-by: CalinL <10718943+CalinL@users.noreply.github.com>
1 parent 29ac226 commit c0630c6

File tree

4 files changed

+374
-1
lines changed

4 files changed

+374
-1
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
@page
2+
@model DevSecOps4837Model
3+
@{
4+
ViewData["Title"] = "DevSecOps Demo 4837 - GitHub Advanced Security Features";
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 latest GitHub Advanced Security (GHAS) features and capabilities</p>
12+
<hr />
13+
</div>
14+
</div>
15+
16+
<!-- Latest GHAS News Section -->
17+
<div class="row">
18+
<div class="col-lg-8">
19+
<div class="card mb-4 shadow">
20+
<div class="card-header bg-success text-white">
21+
<h3 class="card-title mb-0">
22+
<i class="bi bi-newspaper"></i> Latest GitHub Advanced Security News
23+
</h3>
24+
</div>
25+
<div class="card-body">
26+
@if (Model.GHASNews.Any())
27+
{
28+
<div class="list-group list-group-flush">
29+
@foreach (var newsItem in Model.GHASNews)
30+
{
31+
<div class="list-group-item">
32+
<div class="d-flex w-100 justify-content-between">
33+
<h5 class="mb-1">
34+
<span class="badge bg-primary">GHAS</span> @newsItem.Title
35+
</h5>
36+
<small class="text-muted">@newsItem.Date.ToString("MMM dd, yyyy")</small>
37+
</div>
38+
<p class="mb-1">@newsItem.Description</p>
39+
</div>
40+
}
41+
</div>
42+
}
43+
else
44+
{
45+
<p class="text-muted">Loading latest GHAS news...</p>
46+
}
47+
</div>
48+
</div>
49+
50+
<!-- Security Features Overview -->
51+
<div class="card mb-4 shadow">
52+
<div class="card-header bg-dark text-white">
53+
<h3 class="card-title mb-0">
54+
<i class="bi bi-shield-lock"></i> Core GHAS Capabilities
55+
</h3>
56+
</div>
57+
<div class="card-body">
58+
<div class="accordion" id="ghasFeatures">
59+
<div class="accordion-item">
60+
<h2 class="accordion-header" id="headingOne">
61+
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
62+
<strong>🔍 CodeQL Code Scanning</strong>
63+
</button>
64+
</h2>
65+
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#ghasFeatures">
66+
<div class="accordion-body">
67+
Advanced semantic code analysis that identifies security vulnerabilities across 12+ languages including C#, Java, Python, JavaScript, and Go. CodeQL's deep program analysis goes beyond pattern matching to understand data flow and control flow.
68+
</div>
69+
</div>
70+
</div>
71+
<div class="accordion-item">
72+
<h2 class="accordion-header" id="headingTwo">
73+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
74+
<strong>🔑 Secret Scanning</strong>
75+
</button>
76+
</h2>
77+
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#ghasFeatures">
78+
<div class="accordion-body">
79+
Automatically detects exposed credentials and tokens for over 200+ service providers. Partner with providers for automatic token revocation and integrates with push protection to prevent secrets from entering repositories.
80+
</div>
81+
</div>
82+
</div>
83+
<div class="accordion-item">
84+
<h2 class="accordion-header" id="headingThree">
85+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
86+
<strong>📦 Dependency Review & Dependabot</strong>
87+
</button>
88+
</h2>
89+
<div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#ghasFeatures">
90+
<div class="accordion-body">
91+
Automated vulnerability detection in dependencies with pull request-level security impact analysis. Dependabot automatically creates PRs to update vulnerable dependencies with secure versions.
92+
</div>
93+
</div>
94+
</div>
95+
</div>
96+
</div>
97+
</div>
98+
</div>
99+
100+
<!-- Sidebar with Security Demo -->
101+
<div class="col-lg-4">
102+
<div class="card mb-4 shadow border-warning">
103+
<div class="card-header bg-warning text-dark">
104+
<h4 class="card-title mb-0">
105+
<i class="bi bi-exclamation-triangle-fill"></i> Security Demo Zone
106+
</h4>
107+
</div>
108+
<div class="card-body">
109+
<div class="alert alert-danger" role="alert">
110+
<strong>⚠️ Warning:</strong> This page contains intentionally vulnerable code for GHAS demonstration purposes.
111+
</div>
112+
113+
<form method="post" asp-page-handler="ProcessInput">
114+
<div class="mb-3">
115+
<label for="userInput" class="form-label">Test Input (Log Forging Demo):</label>
116+
<input type="text" class="form-control" id="userInput" name="userInput"
117+
placeholder="Enter text to log">
118+
<small class="form-text text-muted">
119+
Input will be logged directly - vulnerable to log injection
120+
</small>
121+
</div>
122+
<button type="submit" class="btn btn-warning btn-sm w-100">
123+
<i class="bi bi-play-circle"></i> Submit Test
124+
</button>
125+
</form>
126+
127+
<hr />
128+
129+
<h6 class="text-danger">Detected Vulnerabilities:</h6>
130+
<ul class="small">
131+
<li>Log Forging/Injection</li>
132+
<li>ReDoS (Regular Expression DoS)</li>
133+
<li>Hardcoded Database Credentials</li>
134+
<li>SQL Injection Risk</li>
135+
</ul>
136+
</div>
137+
</div>
138+
139+
<!-- Resources Card -->
140+
<div class="card shadow">
141+
<div class="card-header bg-info text-white">
142+
<h5 class="card-title mb-0">
143+
<i class="bi bi-book"></i> Resources
144+
</h5>
145+
</div>
146+
<div class="card-body">
147+
<div class="d-grid gap-2">
148+
<a href="https://docs.github.com/en/code-security/code-scanning" class="btn btn-outline-primary btn-sm" target="_blank">
149+
Code Scanning Docs
150+
</a>
151+
<a href="https://codeql.github.com/" class="btn btn-outline-secondary btn-sm" target="_blank">
152+
CodeQL Documentation
153+
</a>
154+
<a href="https://github.com/security" class="btn btn-outline-success btn-sm" target="_blank">
155+
GitHub Security
156+
</a>
157+
<a asp-page="/Index" class="btn btn-outline-dark btn-sm">
158+
Back to Home
159+
</a>
160+
</div>
161+
</div>
162+
</div>
163+
</div>
164+
</div>
165+
166+
<!-- Footer with Pro Tips -->
167+
<div class="row mt-4">
168+
<div class="col-12">
169+
<div class="alert alert-info" role="alert">
170+
<h5 class="alert-heading">
171+
<i class="bi bi-lightbulb-fill"></i> DevSecOps Best Practices
172+
</h5>
173+
<hr>
174+
<ul class="mb-0">
175+
<li><strong>Shift Left:</strong> Integrate security scanning early in the development lifecycle</li>
176+
<li><strong>Automate:</strong> Use GitHub Actions to automate security scans on every commit and PR</li>
177+
<li><strong>Remediate:</strong> Address high-severity vulnerabilities immediately with Dependabot and CodeQL suggestions</li>
178+
<li><strong>Monitor:</strong> Use Security Overview dashboard for organization-wide security posture</li>
179+
</ul>
180+
</div>
181+
</div>
182+
</div>
183+
</div>
184+
185+
@section Scripts {
186+
<script>
187+
// Auto-refresh timestamp display
188+
document.addEventListener('DOMContentLoaded', function() {
189+
console.log('DevSecOps Demo Page 4837 Loaded');
190+
});
191+
</script>
192+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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+
/// <summary>
11+
/// DevSecOps Demo Page Model - Contains intentional security vulnerabilities for GHAS demonstration
12+
/// WARNING: This code is intentionally insecure for educational purposes only
13+
/// </summary>
14+
public class DevSecOps4837Model : PageModel
15+
{
16+
private readonly ILogger<DevSecOps4837Model> _logger;
17+
18+
// SECURITY ISSUE: Hardcoded database credentials - will be detected by GHAS Secret Scanning
19+
private const string DB_CONNECTION_STRING = "Server=demo-sql.database.windows.net;Database=GHASDemo;User Id=demoadmin;Password=P@ssw0rd123!;";
20+
21+
// SECURITY ISSUE: Vulnerable regex pattern susceptible to ReDoS (Regular Expression Denial of Service)
22+
// This pattern has nested quantifiers which can cause exponential backtracking
23+
private static readonly Regex VulnerableEmailRegex = new Regex(@"^([a-zA-Z0-9]+)*@([a-zA-Z0-9]+)*\.com$", RegexOptions.Compiled);
24+
25+
public DevSecOps4837Model(ILogger<DevSecOps4837Model> logger)
26+
{
27+
_logger = logger;
28+
_logger.LogInformation("DevSecOps4837Model initialized");
29+
}
30+
31+
public List<GHASNewsItem> GHASNews { get; set; } = new List<GHASNewsItem>();
32+
33+
public void OnGet()
34+
{
35+
// SECURITY ISSUE: Log Forging - Unsanitized user input directly in log statements
36+
string userName = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous";
37+
_logger.LogInformation($"User {userName} accessed DevSecOps-4837 page");
38+
39+
// SECURITY ISSUE: Another log forging example with query parameter
40+
string action = Request.Query.ContainsKey("action") ? Request.Query["action"].ToString() ?? "view" : "view";
41+
_logger.LogInformation($"Action performed: {action} by user {userName}");
42+
43+
// Load GHAS news with intentional vulnerabilities
44+
LoadGHASNews();
45+
46+
// Demonstrate regex vulnerability
47+
DemonstrateRegexVulnerability();
48+
49+
// Demonstrate SQL injection risk
50+
DemonstrateSQLRisk();
51+
}
52+
53+
private void LoadGHASNews()
54+
{
55+
_logger.LogInformation("Loading latest GitHub Advanced Security news");
56+
57+
GHASNews = new List<GHASNewsItem>
58+
{
59+
new GHASNewsItem
60+
{
61+
Title = "CodeQL 2.20 Released with Enhanced Security Analysis",
62+
Description = "New CodeQL version includes improved support for C#, Java, and JavaScript with 50+ new security queries for OWASP Top 10 vulnerabilities.",
63+
Date = DateTime.Now.AddDays(-2)
64+
},
65+
new GHASNewsItem
66+
{
67+
Title = "Secret Scanning Push Protection Now GA",
68+
Description = "Push protection prevents developers from accidentally committing secrets to repositories, with support for 200+ token patterns.",
69+
Date = DateTime.Now.AddDays(-5)
70+
},
71+
new GHASNewsItem
72+
{
73+
Title = "Dependabot Security Updates Enhanced",
74+
Description = "Automated dependency updates now include intelligent PR grouping and compatibility scoring to reduce alert fatigue.",
75+
Date = DateTime.Now.AddDays(-7)
76+
},
77+
new GHASNewsItem
78+
{
79+
Title = "AI-Powered Security Fix Suggestions",
80+
Description = "GitHub Copilot for Security now provides context-aware fix suggestions for code scanning alerts with one-click remediation.",
81+
Date = DateTime.Now.AddDays(-10)
82+
},
83+
new GHASNewsItem
84+
{
85+
Title = "Custom CodeQL Query Suites",
86+
Description = "Organizations can now create and share custom CodeQL query suites across repositories for industry-specific compliance requirements.",
87+
Date = DateTime.Now.AddDays(-14)
88+
},
89+
new GHASNewsItem
90+
{
91+
Title = "Security Overview Dashboard Updates",
92+
Description = "New metrics and visualizations for tracking security posture across enterprise organizations with improved filtering and export capabilities.",
93+
Date = DateTime.Now.AddDays(-18)
94+
}
95+
};
96+
97+
// SECURITY ISSUE: Unnecessary JSON serialization/deserialization that could introduce vulnerabilities
98+
string jsonData = JsonConvert.SerializeObject(GHASNews);
99+
var tempData = JsonConvert.DeserializeObject<List<GHASNewsItem>>(jsonData);
100+
101+
_logger.LogInformation($"Loaded {GHASNews.Count} GHAS news items");
102+
}
103+
104+
private void DemonstrateRegexVulnerability()
105+
{
106+
// SECURITY ISSUE: Testing vulnerable regex pattern that could cause ReDoS
107+
string testEmail = Request.Query.ContainsKey("email") ? Request.Query["email"].ToString() ?? "test@example.com" : "test@example.com";
108+
109+
try
110+
{
111+
// This vulnerable regex can cause exponential backtracking with inputs like "aaaaaaaaaaaaaaaaaaaaaaaaa@aaaaaaaaaaaaaaa"
112+
bool isValidEmail = VulnerableEmailRegex.IsMatch(testEmail);
113+
_logger.LogInformation($"Email validation result for {testEmail}: {isValidEmail}");
114+
}
115+
catch (Exception ex)
116+
{
117+
// SECURITY ISSUE: Logging full exception details which might contain sensitive information
118+
_logger.LogError($"Regex validation failed for email: {testEmail}. Exception: {ex}");
119+
}
120+
}
121+
122+
private void DemonstrateSQLRisk()
123+
{
124+
// SECURITY ISSUE: Using hardcoded connection string
125+
try
126+
{
127+
using var connection = new SqlConnection(DB_CONNECTION_STRING);
128+
_logger.LogInformation("Database connection configured with demo credentials");
129+
130+
// SECURITY ISSUE: Potential SQL injection if this were to accept user input
131+
string userId = Request.Query.ContainsKey("userId") ? Request.Query["userId"].ToString() ?? "1" : "1";
132+
string unsafeQuery = $"SELECT * FROM Users WHERE UserId = {userId}"; // SQL INJECTION RISK
133+
134+
// Log the unsafe query (for demonstration - not actually executing)
135+
_logger.LogWarning($"Unsafe SQL query constructed: {unsafeQuery}");
136+
}
137+
catch (Exception ex)
138+
{
139+
_logger.LogError($"Database operation failed: {ex.Message}");
140+
}
141+
}
142+
143+
public IActionResult OnPostProcessInput(string userInput)
144+
{
145+
if (string.IsNullOrEmpty(userInput))
146+
{
147+
_logger.LogWarning("Empty input received in ProcessInput handler");
148+
return Page();
149+
}
150+
151+
// SECURITY ISSUE: Log Forging - User input directly in logs without sanitization
152+
_logger.LogInformation($"Processing user input: {userInput}");
153+
154+
// SECURITY ISSUE: User input could contain newlines or control characters
155+
_logger.LogInformation($"Input length: {userInput.Length}, Content: {userInput}");
156+
157+
// Demonstrate potential command injection risk (not actually executing)
158+
if (userInput.Contains(";") || userInput.Contains("|"))
159+
{
160+
_logger.LogWarning($"Suspicious input detected with special characters: {userInput}");
161+
}
162+
163+
TempData["Message"] = $"Input processed: {userInput}";
164+
return RedirectToPage();
165+
}
166+
}
167+
168+
/// <summary>
169+
/// Model for GHAS news items
170+
/// </summary>
171+
public class GHASNewsItem
172+
{
173+
public string Title { get; set; } = string.Empty;
174+
public string Description { get; set; } = string.Empty;
175+
public DateTime Date { get; set; }
176+
}
177+
}

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> View our newest <a asp-page="/DevSecOps-4837" class="btn btn-success btn-sm">DevSecOps Demo 4837</a>
18+
with the most recent GitHub Advanced Security updates and features.
19+
</p>
1620
</div>
1721
</div>

src/webapp01/webapp01.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.2" />
1414
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
1515
<PackageReference Include="System.Text.Json" Version="8.0.4" />
16-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
16+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
1717
</ItemGroup>
1818

1919
</Project>

0 commit comments

Comments
 (0)