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 22 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 22 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.
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