-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
- 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
Dependency ReviewThe following issues were found:
Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Vulnerabilitiessrc/webapp01/webapp01.csprojOnly included vulnerabilities with severity moderate or higher. OpenSSF Scorecard
Scanned Files
|
1 similar comment
Dependency ReviewThe following issues were found:
Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Vulnerabilitiessrc/webapp01/webapp01.csprojOnly included vulnerabilities with severity moderate or higher. OpenSSF Scorecard
Scanned Files
|
|
||
// 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
user-provided value
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified lines R36-R37
@@ -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); | ||
} |
catch (Exception ex) | ||
{ | ||
_logger.LogError("Database error: " + ex.Message); | ||
} |
Check notice
Code scanning / CodeQL
Generic catch clause Note
Show autofix suggestion
Hide autofix suggestion
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:
- Replace the generic
catch (Exception ex)
block with a specificcatch (SqlException ex)
block. - Optionally, add additional catch blocks for other specific exceptions if necessary.
- Ensure that the logging remains intact to provide diagnostic information.
-
Copy modified line R55 -
Copy modified line R57
@@ -54,5 +54,5 @@ | ||
} | ||
catch (Exception ex) | ||
catch (SqlException ex) | ||
{ | ||
_logger.LogError("Database error: " + ex.Message); | ||
_logger.LogError("SQL error: " + ex.Message); | ||
} |
Implements issue #72 - DevSecOps demo for GitHub Advanced Security