Skip to content

feat: Implement DevSecOps demo page for GHAS features #73

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CalinL
Copy link
Contributor

@CalinL CalinL commented May 29, 2025

  • Add new DevSecOps.cshtml page with GHAS latest news and features
  • Implement ILogger for backend logging and security demonstrations
  • Add intentionally vulnerable code patterns for GHAS demo:
    • Log forging vulnerabilities
    • SQL injection patterns
    • Regex DoS vulnerabilities
    • Hard-coded credentials
  • Update package dependencies:
    • System.Text.Json 8.0.4 (vulnerable version for demo)
    • Microsoft.Data.SqlClient 5.0.2 (vulnerable version for demo)
    • Newtonsoft.Json 12.0.2 (vulnerable version for demo)
  • Add navigation menu link to DevSecOps demo page
  • Update Index page with links to new DevSecOps features
  • Build verified without compilation errors

Implements issue #72 - DevSecOps demo for GitHub Advanced Security

- Add new DevSecOps.cshtml page with GHAS latest news and features
- Implement ILogger for backend logging and security demonstrations
- Add intentionally vulnerable code patterns for GHAS demo:
  * Log forging vulnerabilities
  * SQL injection patterns
  * Regex DoS vulnerabilities
  * Hard-coded credentials
- Update package dependencies:
  * System.Text.Json 8.0.4 (vulnerable version for demo)
  * Microsoft.Data.SqlClient 5.0.2 (vulnerable version for demo)
  * Newtonsoft.Json 12.0.2 (vulnerable version for demo)
- Add navigation menu link to DevSecOps demo page
- Update Index page with links to new DevSecOps features
- Build verified without compilation errors

Implements issue #72 - DevSecOps demo for GitHub Advanced Security
Copy link

Dependency Review

The following issues were found:
  • ❌ 3 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ✅ 0 package(s) with unknown licenses.
See the Details below.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA d256bd3.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Vulnerabilities

src/webapp01/webapp01.csproj

NameVersionVulnerabilitySeverity
Microsoft.Data.SqlClient5.0.2Microsoft.Data.SqlClient and System.Data.SqlClient vulnerable to SQL Data Provider Security Feature Bypass high
Newtonsoft.Json12.0.2Improper Handling of Exceptional Conditions in Newtonsoft.Jsonhigh
System.Text.Json8.0.4Microsoft Security Advisory CVE-2024-43485 | .NET Denial of Service Vulnerabilityhigh
Only included vulnerabilities with severity moderate or higher.

OpenSSF Scorecard

PackageVersionScoreDetails
nuget/Microsoft.Data.SqlClient 5.0.2 🟢 6.7
Details
CheckScoreReason
Token-Permissions⚠️ -1No tokens found
Packaging⚠️ -1packaging workflow not detected
Maintained🟢 1030 commit(s) and 7 issue activity found in the last 90 days -- score normalized to 10
Code-Review🟢 9Found 27/30 approved changesets -- score normalized to 9
Dangerous-Workflow⚠️ -1no workflows found
Security-Policy🟢 10security policy file detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Vulnerabilities🟢 100 existing vulnerabilities detected
Signed-Releases⚠️ 0Project has not signed or included provenance with any releases.
Branch-Protection⚠️ -1internal error: error during GetBranch(release/5.2): error during branchesHandler.query: internal error: githubv4.Query: Resource not accessible by integration
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies🟢 10all dependencies are pinned
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
nuget/Newtonsoft.Json 12.0.2 🟢 4.7
Details
CheckScoreReason
Code-Review🟢 3Found 10/30 approved changesets -- score normalized to 3
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Maintained⚠️ 12 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Packaging⚠️ -1packaging workflow not detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy⚠️ 0security policy file not detected
Binary-Artifacts🟢 10no binaries found in the repo
Fuzzing⚠️ 0project is not fuzzed
Vulnerabilities🟢 100 existing vulnerabilities detected
License🟢 10license file detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
Signed-Releases⚠️ 0Project has not signed or included provenance with any releases.
SAST🟢 7SAST tool detected but not run on all commits
nuget/System.Text.Json 8.0.4 🟢 5.4
Details
CheckScoreReason
Maintained🟢 1030 commit(s) and 24 issue activity found in the last 90 days -- score normalized to 10
Code-Review🟢 10all changesets reviewed
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
Security-Policy🟢 10security policy file detected
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Branch-Protection🟢 5branch protection is not maximal on development and all release branches
Fuzzing⚠️ 0project is not fuzzed
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
Vulnerabilities🟢 82 existing vulnerabilities detected
Binary-Artifacts⚠️ 0binaries present in source code
Pinned-Dependencies⚠️ 2dependency not pinned by hash detected -- score normalized to 2

Scanned Files

  • src/webapp01/webapp01.csproj

1 similar comment
Copy link

Dependency Review

The following issues were found:
  • ❌ 3 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ✅ 0 package(s) with unknown licenses.
See the Details below.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA d256bd3.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Vulnerabilities

src/webapp01/webapp01.csproj

NameVersionVulnerabilitySeverity
Microsoft.Data.SqlClient5.0.2Microsoft.Data.SqlClient and System.Data.SqlClient vulnerable to SQL Data Provider Security Feature Bypass high
Newtonsoft.Json12.0.2Improper Handling of Exceptional Conditions in Newtonsoft.Jsonhigh
System.Text.Json8.0.4Microsoft Security Advisory CVE-2024-43485 | .NET Denial of Service Vulnerabilityhigh
Only included vulnerabilities with severity moderate or higher.

OpenSSF Scorecard

PackageVersionScoreDetails
nuget/Microsoft.Data.SqlClient 5.0.2 🟢 6.7
Details
CheckScoreReason
Token-Permissions⚠️ -1No tokens found
Packaging⚠️ -1packaging workflow not detected
Maintained🟢 1030 commit(s) and 7 issue activity found in the last 90 days -- score normalized to 10
Code-Review🟢 9Found 27/30 approved changesets -- score normalized to 9
Dangerous-Workflow⚠️ -1no workflows found
Security-Policy🟢 10security policy file detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Vulnerabilities🟢 100 existing vulnerabilities detected
Signed-Releases⚠️ 0Project has not signed or included provenance with any releases.
Branch-Protection⚠️ -1internal error: error during GetBranch(release/5.2): error during branchesHandler.query: internal error: githubv4.Query: Resource not accessible by integration
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies🟢 10all dependencies are pinned
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
nuget/Newtonsoft.Json 12.0.2 🟢 4.7
Details
CheckScoreReason
Code-Review🟢 3Found 10/30 approved changesets -- score normalized to 3
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Maintained⚠️ 12 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Packaging⚠️ -1packaging workflow not detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy⚠️ 0security policy file not detected
Binary-Artifacts🟢 10no binaries found in the repo
Fuzzing⚠️ 0project is not fuzzed
Vulnerabilities🟢 100 existing vulnerabilities detected
License🟢 10license file detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
Signed-Releases⚠️ 0Project has not signed or included provenance with any releases.
SAST🟢 7SAST tool detected but not run on all commits
nuget/System.Text.Json 8.0.4 🟢 5.4
Details
CheckScoreReason
Maintained🟢 1030 commit(s) and 24 issue activity found in the last 90 days -- score normalized to 10
Code-Review🟢 10all changesets reviewed
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
Security-Policy🟢 10security policy file detected
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Branch-Protection🟢 5branch protection is not maximal on development and all release branches
Fuzzing⚠️ 0project is not fuzzed
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
Vulnerabilities🟢 82 existing vulnerabilities detected
Binary-Artifacts⚠️ 0binaries present in source code
Pinned-Dependencies⚠️ 2dependency not pinned by hash detected -- score normalized to 2

Scanned Files

  • src/webapp01/webapp01.csproj


// Insecure: Log user data without sanitization for demo purposes
string userAgent = Request.Headers["User-Agent"].ToString();
_logger.LogInformation("User accessed DevSecOps page with User-Agent: " + userAgent);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.

Copilot Autofix

AI 29 days ago

To fix the issue, the user-provided User-Agent header should be sanitized before being logged. Since the logs are likely stored as plain text, newline characters should be removed from the User-Agent string to prevent log forging. This can be achieved using String.Replace to replace newline characters (\n and \r) with an empty string. Additionally, the input should be clearly marked in the log entry to avoid confusion.

Changes will be made to line 36 in the OnGet method to sanitize the userAgent value before logging it.


Suggested changeset 1
src/webapp01/Pages/DevSecOps.cshtml.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/webapp01/Pages/DevSecOps.cshtml.cs b/src/webapp01/Pages/DevSecOps.cshtml.cs
--- a/src/webapp01/Pages/DevSecOps.cshtml.cs
+++ b/src/webapp01/Pages/DevSecOps.cshtml.cs
@@ -35,3 +35,4 @@
             string userAgent = Request.Headers["User-Agent"].ToString();
-            _logger.LogInformation("User accessed DevSecOps page with User-Agent: " + userAgent);
+            string sanitizedUserAgent = userAgent.Replace("\n", "").Replace("\r", "");
+            _logger.LogInformation("User accessed DevSecOps page with sanitized User-Agent: " + sanitizedUserAgent);
         }
EOF
@@ -35,3 +35,4 @@
string userAgent = Request.Headers["User-Agent"].ToString();
_logger.LogInformation("User accessed DevSecOps page with User-Agent: " + userAgent);
string sanitizedUserAgent = userAgent.Replace("\n", "").Replace("\r", "");
_logger.LogInformation("User accessed DevSecOps page with sanitized User-Agent: " + sanitizedUserAgent);
}
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +55 to +58
catch (Exception ex)
{
_logger.LogError("Database error: " + ex.Message);
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI 29 days ago

To fix the problem, replace the generic catch clause catch (Exception ex) with specific exception types that are relevant to the database operation. For SQL-related errors, the SqlException class should be caught. If additional exceptions need to be handled, they can be added as separate catch blocks. This approach ensures that only relevant exceptions are caught, improving error diagnosis and handling.

Steps to implement the fix:

  1. Replace the generic catch (Exception ex) block with a specific catch (SqlException ex) block.
  2. Optionally, add additional catch blocks for other specific exceptions if necessary.
  3. Ensure that the logging remains intact to provide diagnostic information.

Suggested changeset 1
src/webapp01/Pages/DevSecOps.cshtml.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/webapp01/Pages/DevSecOps.cshtml.cs b/src/webapp01/Pages/DevSecOps.cshtml.cs
--- a/src/webapp01/Pages/DevSecOps.cshtml.cs
+++ b/src/webapp01/Pages/DevSecOps.cshtml.cs
@@ -54,5 +54,5 @@
                 }
-                catch (Exception ex)
+                catch (SqlException ex)
                 {
-                    _logger.LogError("Database error: " + ex.Message);
+                    _logger.LogError("SQL error: " + ex.Message);
                 }
EOF
@@ -54,5 +54,5 @@
}
catch (Exception ex)
catch (SqlException ex)
{
_logger.LogError("Database error: " + ex.Message);
_logger.LogError("SQL error: " + ex.Message);
}
Copilot is powered by AI and may make mistakes. Always verify output.
@CalinL CalinL requested a review from Copilot June 26, 2025 18:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new DevSecOps demo page showcasing GitHub Advanced Security features, intentionally includes vulnerable code patterns for demonstration, and updates navigation and dependencies accordingly.

  • Downgrade package versions to known vulnerable releases and add Newtonsoft.Json for demo purposes
  • Add navigation link, index page cards, and a new Razor page with accompanying PageModel
  • Implement ILogger usage and include demo security vulnerabilities (SQL injection, regex DoS, log forging, hard-coded credentials)

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/webapp01/webapp01.csproj Downgraded Microsoft.Data.SqlClient & System.Text.Json; added Newtonsoft.Json v12.0.2
src/webapp01/Pages/Shared/_Layout.cshtml Inserted "DevSecOps Demo" link into navbar
src/webapp01/Pages/Index.cshtml Added DevSecOps cards and buttons to the home page
src/webapp01/Pages/DevSecOps.cshtml.cs Introduced DevSecOpsModel with OnGet/OnPost and demo vulnerabilities
src/webapp01/Pages/DevSecOps.cshtml Created demo page layout, news list, form, and animations
Comments suppressed due to low confidence (2)

src/webapp01/Pages/DevSecOps.cshtml.cs:1

  • The new DevSecOpsModel methods (OnGet, OnPost) implement key demonstration scenarios but lack unit or integration tests. Consider adding tests to cover these handlers and verify expected behaviors.
using Microsoft.AspNetCore.Mvc;

src/webapp01/Pages/Shared/_Layout.cshtml:20

  • The closing tag and the
    start tag are on the same line, which hurts readability. Split them onto separate lines with proper indentation for cleaner HTML structure.
                </button>                <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The System.Data.SqlClient namespace is not used in this file (you’re using Microsoft.Data.SqlClient). You can remove this unused using directive to keep imports clean.

Suggested change
using System.Data.SqlClient;

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant