-
Notifications
You must be signed in to change notification settings - Fork 4
Demo-Code02 - Add demo files with intentional security vulnerabilities for GitHub A… #138
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
…dvanced Security training - Created Terraform configuration for Azure resources including a VM, network security group, and public IP. - Added insecure JavaScript and Python scripts demonstrating common vulnerabilities. - Introduced an ARM template with insecure configurations, including hardcoded credentials and CORS misconfigurations. - Implemented a Flask route with SQL injection vulnerabilities and improper error handling. - Developed a Razor Page with intentional security flaws, including hardcoded API keys and log forging issues.
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. Vulnerabilitiesdevsecops-demo/Pipfile.lockOnly included vulnerabilities with severity moderate or higher. License Issuesdevsecops-demo/Pipfile.lock
OpenSSF Scorecard
Scanned Files
|
| resource "azurerm_network_security_group" "catapp-sg" { | ||
| name = "${var.prefix}-sg" | ||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.myresourcegroup.name | ||
|
|
||
| security_rule { | ||
| name = "HTTP" | ||
| priority = 100 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "80" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "HTTPS" | ||
| priority = 102 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "443" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "SSH" | ||
| priority = 101 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "22" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
| } |
Check failure
Code scanning / defsec
An inbound network security rule allows traffic from /0. Error
| resource "azurerm_network_security_group" "catapp-sg" { | ||
| name = "${var.prefix}-sg" | ||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.myresourcegroup.name | ||
|
|
||
| security_rule { | ||
| name = "HTTP" | ||
| priority = 100 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "80" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "HTTPS" | ||
| priority = 102 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "443" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "SSH" | ||
| priority = 101 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "22" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
| } |
Check failure
Code scanning / defsec
An inbound network security rule allows traffic from /0. Error
| resource "azurerm_network_security_group" "catapp-sg" { | ||
| name = "${var.prefix}-sg" | ||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.myresourcegroup.name | ||
|
|
||
| security_rule { | ||
| name = "HTTP" | ||
| priority = 100 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "80" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "HTTPS" | ||
| priority = 102 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "443" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "SSH" | ||
| priority = 101 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "22" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
| } |
Check failure
Code scanning / defsec
An inbound network security rule allows traffic from /0. Error
| resource "azurerm_network_security_group" "catapp-sg" { | ||
| name = "${var.prefix}-sg" | ||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.myresourcegroup.name | ||
|
|
||
| security_rule { | ||
| name = "HTTP" | ||
| priority = 100 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "80" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "HTTPS" | ||
| priority = 102 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "443" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "SSH" | ||
| priority = 101 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "22" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
| } |
Check failure
Code scanning / defsec
SSH access should not be accessible from the Internet, should be blocked on port 22 Error
| resource "azurerm_virtual_machine" "catapp" { | ||
| name = "${var.prefix}-meow" | ||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.myresourcegroup.name | ||
| vm_size = var.vm_size | ||
|
|
||
| network_interface_ids = [azurerm_network_interface.catapp-nic.id] | ||
| delete_os_disk_on_termination = "true" | ||
|
|
||
| storage_image_reference { | ||
| publisher = var.image_publisher | ||
| offer = var.image_offer | ||
| sku = var.image_sku | ||
| version = var.image_version | ||
| } | ||
|
|
||
| storage_os_disk { | ||
| name = "${var.prefix}-osdisk" | ||
| managed_disk_type = "Standard_LRS" | ||
| caching = "ReadWrite" | ||
| create_option = "FromImage" | ||
| } | ||
|
|
||
| os_profile { | ||
| computer_name = var.prefix | ||
| admin_username = var.admin_username | ||
| admin_password = var.admin_password | ||
| } | ||
|
|
||
| os_profile_linux_config { | ||
| disable_password_authentication = false | ||
| } | ||
|
|
||
| tags = {} | ||
|
|
||
| # Added to allow destroy to work correctly. | ||
| depends_on = [azurerm_network_interface_security_group_association.catapp-nic-sg-ass] | ||
| } |
Check failure
Code scanning / defsec
Password authentication should be disabled on Azure virtual machines Error
| try: | ||
| print(xs[7]) | ||
| print(xs[8]) | ||
| except: pass |
Check notice
Code scanning / CodeQL
Except block handles 'BaseException' Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, the fix is to stop catching BaseException via a bare except: and instead catch only the specific exception types that are expected, or at least Exception, so that KeyboardInterrupt and SystemExit can still propagate. When ignoring errors, it is still better to be explicit about which kinds of problems you are discarding.
For the block at lines 7–10, the only plausible runtime error is an IndexError from accessing xs[7] or xs[8]. If we want to preserve the behavior “ignore out-of-range index errors,” we can change except: to except IndexError:. That will no longer swallow KeyboardInterrupt or SystemExit, but will still ignore the indexing error exactly as before. No additional imports or helper functions are needed; IndexError is a built-in exception. The other bare except: on line 16 is not the one CodeQL highlighted in the prompt, and per instructions we only change the snippet directly associated with the reported issue, so we leave it unchanged.
Concretely, in devsecops-demo/insecure-01.py, replace line 10:
10: except: passwith:
10: except IndexError: passleaving the rest of the file intact.
-
Copy modified line R10
| @@ -7,7 +7,7 @@ | ||
| try: | ||
| print(xs[7]) | ||
| print(xs[8]) | ||
| except: pass | ||
| except IndexError: pass | ||
|
|
||
| ys=[1, 2, None, None] | ||
| for y in ys: |
| try: | ||
| print(xs[7]) | ||
| print(xs[8]) | ||
| except: pass |
Check notice
Code scanning / CodeQL
Empty except Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix an empty except block you should either (1) remove the try/except entirely if you don’t need it, (2) catch only the specific exception types you expect, and/or (3) add real handling such as logging, cleanup, or re‑raising. You should avoid bare except: and avoid silently ignoring exceptions.
For this snippet, the minimal, behavior‑preserving fix is:
- Replace the bare
except:with anexcept IndexError as e:(the expected error fromxs[8]). - Replace the
passwith a small, explicit handling action that still keeps the program running but no longer silently hides the issue, e.g. printing an explanatory message that includes the exception text.
This keeps the program structure and visible side effects close to the original intent (demonstration code that continues after an out‑of‑range access) while satisfying the static analysis rule and improving debuggability. Only devsecops-demo/insecure-01.py needs edits, and no new imports or helper functions are required.
-
Copy modified lines R10-R11
| @@ -7,7 +7,8 @@ | ||
| try: | ||
| print(xs[7]) | ||
| print(xs[8]) | ||
| except: pass | ||
| except IndexError as e: | ||
| print(f"Index error while accessing xs: {e}") | ||
|
|
||
| ys=[1, 2, None, None] | ||
| for y in ys: |
| for y in ys: | ||
| try: | ||
| print(str(y+3)) #TypeErrors ahead | ||
| except: continue #not how to handle them |
Check notice
Code scanning / CodeQL
Except block handles 'BaseException' Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, this problem is fixed by never using a bare except: (which is equivalent to except BaseException:). Instead, catch specific exception types such as Exception or, even better, the concrete error you expect (here TypeError), and let KeyboardInterrupt/SystemExit propagate naturally.
In this particular snippet, the loop over ys is intentionally causing TypeError when adding 3 to None. The current behavior is: on any exception, skip to the next y. To preserve functionality while avoiding catching KeyboardInterrupt and SystemExit, we should change except: on line 16 to catch TypeError specifically (or at least Exception). That way, only the expected error from y + 3 is handled, and the loop still continues on those errors. No additional imports or helper methods are needed. The change is confined to devsecops-demo/insecure-01.py, lines 13–16, where we replace except: continue with except TypeError: continue.
-
Copy modified lines R16-R17
| @@ -13,7 +13,8 @@ | ||
| for y in ys: | ||
| try: | ||
| print(str(y+3)) #TypeErrors ahead | ||
| except: continue #not how to handle them | ||
| except TypeError: # not how to handle them | ||
| continue | ||
|
|
||
| #some imports | ||
| import telnetlib |
| except: continue #not how to handle them | ||
|
|
||
| #some imports | ||
| import telnetlib |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
To fix an unused import, the general approach is to remove the import statement for any module that is never referenced in the file. This eliminates unnecessary dependencies and slightly reduces load time and mental overhead.
In this file (devsecops-demo/insecure-01.py), the best fix is to delete the import telnetlib line at line 19, leaving the import ftplib line intact because we have not been asked to address it and it may be used or intentionally present for demonstration purposes. No additional methods, imports, or definitions are needed; we are only removing a redundant import.
| @@ -16,7 +16,6 @@ | ||
| except: continue #not how to handle them | ||
|
|
||
| #some imports | ||
| import telnetlib | ||
| import ftplib | ||
|
|
||
| #B303 and B324 |
|
|
||
| #some imports | ||
| import telnetlib | ||
| import ftplib |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
To fix the problem, remove the unused ftplib import so that all imports in the file correspond to code that is actually used. This reduces unnecessary dependencies and improves readability without affecting functionality, since ftplib is never referenced.
Concretely, in devsecops-demo/insecure-01.py, delete the line import ftplib at line 20, leaving the telnetlib and hashlib imports intact. No additional methods, imports, or definitions are required, as the rest of the code already runs without ftplib.
| @@ -17,7 +17,6 @@ | ||
|
|
||
| #some imports | ||
| import telnetlib | ||
| import ftplib | ||
|
|
||
| #B303 and B324 | ||
| s = b"I am a string" |
| @@ -0,0 +1,30 @@ | |||
|
|
|||
| from flask import request, render_template, make_response | |||
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
To fix the problem, remove the unused symbol make_response from the import statement so that only the actually used imports remain. This avoids an unnecessary dependency, keeps the imports clean, and does not change any functionality since make_response is not used.
Concretely, in devsecops-demo/routes-01.py, on line 2, change from flask import request, render_template, make_response to import only request and render_template. No other code changes are required, and no new methods, imports, or definitions are needed.
-
Copy modified line R2
| @@ -1,5 +1,5 @@ | ||
|
|
||
| from flask import request, render_template, make_response | ||
| from flask import request, render_template | ||
|
|
||
| from server.webapp import flaskapp, cursor | ||
| from server.models import Book |
| def index(): | ||
| name = request.args.get('name') | ||
| author = request.args.get('author') | ||
| read = bool(request.args.get('read')) |
Check notice
Code scanning / CodeQL
Unused local variable Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
To fix the problem, we should either (a) remove the unused variable assignment entirely, or (b) rename it to something like _read or _ if it is intentionally unused for documentation purposes. Since the right-hand side has no side effects and the parameter is not used at all, the simplest change that does not alter functionality is to delete the assignment line.
Specifically, in devsecops-demo/routes-01.py, within the index view function, remove line 12: read = bool(request.args.get('read')). No other code depends on read, so no additional changes are required. No imports, methods, or definitions need to be added.
| @@ -9,7 +9,6 @@ | ||
| def index(): | ||
| name = request.args.get('name') | ||
| author = request.args.get('author') | ||
| read = bool(request.args.get('read')) | ||
|
|
||
| if name: | ||
| cursor.execute( |
| string drive = Request.Query.ContainsKey("drive") ? Request.Query["drive"] : "C"; | ||
| var str = $"/C fsutil volume diskfree {drive}:"; | ||
|
|
||
| _logger.LogInformation($"Executing command: {str}"); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to prevent log entries from being forged with user-controlled data, any user input that is included in log messages should be normalized before logging. For plain-text logs, the primary step is to remove or neutralize newline and other control characters so that an attacker cannot break out of the intended log line or inject additional lines. For logs that might be displayed as HTML, HTML-encoding before logging can also be used, but here we only know that we are writing to an ILogger, which commonly backs plain-text or structured logs.
The best minimal fix here is to sanitize the drive value (or the derived str) before using it in the log message. A straightforward approach is to remove carriage return and newline characters from drive before constructing str, or alternatively to sanitize str before logging it. To preserve existing functionality (constructing the same command string for later use), we should only change what is logged, not the command variable itself. That suggests adding a sanitized copy for log purposes. Concretely, in OnGet, we can introduce a sanitizedStr variable that replaces \r and \n with empty strings (or spaces) and then log sanitizedStr. This requires only changes within Privacy.cshtml.cs around lines 20–22 and does not require new imports.
-
Copy modified line R21 -
Copy modified line R23
| @@ -18,8 +18,9 @@ | ||
| { | ||
| string drive = Request.Query.ContainsKey("drive") ? Request.Query["drive"] : "C"; | ||
| var str = $"/C fsutil volume diskfree {drive}:"; | ||
| var sanitizedStr = str.Replace("\r", string.Empty).Replace("\n", string.Empty); | ||
|
|
||
| _logger.LogInformation($"Executing command: {str}"); | ||
| _logger.LogInformation($"Executing command: {sanitizedStr}"); | ||
| _logger.LogInformation($"User: {User.Identity?.Name}"); | ||
| _logger.LogInformation($"Admin: {User.IsInRole("Admin")}"); | ||
| _logger.LogInformation("Admin" + adminUserName); |
| // SECURITY ISSUE: SQL connection with hardcoded credentials | ||
| try | ||
| { | ||
| using var sqlConnection = new SqlConnection(DB_CONNECTION); |
Check failure
Code scanning / CodeQL
Insecure SQL connection High
Connection string
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix insecure SQL connections, the connection string passed to SqlConnection (or constructed via SqlConnectionStringBuilder) must explicitly set Encrypt=True so that the client refuses to connect without TLS. Optionally, TrustServerCertificate=False can be added to ensure proper certificate validation, but the CodeQL rule specifically requires Encrypt=True.
For this file, the minimal and safest fix without changing any behavior is to update the DB_CONNECTION constant on line 21 to include Encrypt=True; at the end of the connection string. No other code changes are required because the constant is only used to construct the SqlConnection. We do not need new methods, imports, or refactoring to SqlConnectionStringBuilder; simply appending Encrypt=True; to the existing string is sufficient and preserves the rest of the functionality and demo behavior.
Concretely:
- Edit
src/webapp01/Pages/DevSecOps-7492.cshtml.cs. - On line 21, change
private const string DB_CONNECTION = "Server=demo-server;Database=SecurityDemo;User Id=demouser;Password=DemoPass2026!;";
to
private const string DB_CONNECTION = "Server=demo-server;Database=SecurityDemo;User Id=demouser;Password=DemoPass2026!;Encrypt=True;"; - No other lines or files need modification.
-
Copy modified line R21
| @@ -18,7 +18,7 @@ | ||
| private readonly ILogger<DevSecOps7492Model> _logger; | ||
|
|
||
| // SECURITY ISSUE: Hardcoded database credentials - for demo purposes only! | ||
| private const string DB_CONNECTION = "Server=demo-server;Database=SecurityDemo;User Id=demouser;Password=DemoPass2026!;"; | ||
| private const string DB_CONNECTION = "Server=demo-server;Database=SecurityDemo;User Id=demouser;Password=DemoPass2026!;Encrypt=True;"; | ||
|
|
||
| // SECURITY ISSUE: Vulnerable regex pattern susceptible to ReDoS (Regular Expression Denial of Service) | ||
| private static readonly Regex InsecureRegex = new Regex(@"^(([a-z])+.)+[A-Z]([a-z])+$", RegexOptions.None); |
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to prevent log forging when logging user input, you should sanitize or encode that input before logging. For plain-text logs, the most important step is to remove or neutralize line breaks and other control characters so a single logical log entry cannot be split into multiple physical lines. Optionally, you can also normalize other non-printable characters.
For this specific file, the best minimal fix without changing behavior is to sanitize the user-controlled strings before interpolating them into log messages. We can introduce a small helper method (e.g., SanitizeForLog) inside DevSecOps7492Model that removes \r and \n from strings (and safely handles null), then use it whenever we log user input. We only have to modify code in the shown snippet, so we’ll define this helper as a private method in the same class and replace direct uses of userName, userAgent, and testInput in log messages with their sanitized counterparts. No new imports are needed because we can implement sanitization with string.Replace, which is already available.
Concretely:
- Add a private method in
DevSecOps7492Model(near other members) that takes astring?and returns a sanitizedstring, removing\rand\n. - In
OnGet, create sanitized local variables (e.g.,sanitizedUserName,sanitizedUserAgent,sanitizedTestInput) using this helper. - Use those sanitized variables in all log lines that currently interpolate user-controlled data: lines 45, 46, 63, and 68.
- Keep exception and other non-user-controlled data unchanged.
This preserves existing functionality while preventing an attacker from injecting line breaks into log entries.
-
Copy modified lines R34-R46 -
Copy modified lines R56-R58 -
Copy modified lines R61-R62 -
Copy modified line R76 -
Copy modified line R78 -
Copy modified lines R83-R84
| @@ -31,6 +31,19 @@ | ||
| _logger = logger; | ||
| } | ||
|
|
||
| private static string SanitizeForLog(string? value) | ||
| { | ||
| if (value == null) | ||
| { | ||
| return string.Empty; | ||
| } | ||
|
|
||
| // Remove newline characters to prevent log forging via line injection | ||
| return value | ||
| .Replace("\r", string.Empty) | ||
| .Replace("\n", string.Empty); | ||
| } | ||
|
|
||
| public List<string> LatestGHASNews { get; set; } = new(); | ||
| public int PageViews { get; set; } | ||
|
|
||
| @@ -40,10 +53,13 @@ | ||
| string userAgent = Request.Headers["User-Agent"].ToString(); | ||
| string remoteIp = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown"; | ||
| string userName = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous"; | ||
|
|
||
| string sanitizedUserAgent = SanitizeForLog(userAgent); | ||
| string sanitizedUserName = SanitizeForLog(userName); | ||
|
|
||
| // Log forging vulnerability - attacker can inject newlines and fake log entries | ||
| _logger.LogInformation($"DevSecOps-7492 page accessed by: {userName} from IP: {remoteIp}"); | ||
| _logger.LogInformation($"User-Agent: {userAgent}"); | ||
| _logger.LogInformation($"DevSecOps-7492 page accessed by: {sanitizedUserName} from IP: {remoteIp}"); | ||
| _logger.LogInformation($"User-Agent: {sanitizedUserAgent}"); | ||
|
|
||
| // Simulate page view counter | ||
| PageViews = new Random().Next(1000, 5000); | ||
| @@ -59,13 +73,15 @@ | ||
| { | ||
| // This regex is vulnerable to ReDoS attacks | ||
| var match = InsecureRegex.IsMatch(testInput); | ||
| string sanitizedTestInput = SanitizeForLog(testInput); | ||
| // Log forging in conditional logic | ||
| _logger.LogInformation($"Regex test performed on input: {testInput}, result: {match}"); | ||
| _logger.LogInformation($"Regex test performed on input: {sanitizedTestInput}, result: {match}"); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); | ||
| string sanitizedTestInput = SanitizeForLog(testInput); | ||
| _logger.LogError($"Regex evaluation failed for user input: {sanitizedTestInput}. Exception details: {ex.ToString()}"); | ||
| } | ||
| } | ||
|
|
| // This regex is vulnerable to ReDoS attacks | ||
| var match = InsecureRegex.IsMatch(testInput); | ||
| // Log forging in conditional logic | ||
| _logger.LogInformation($"Regex test performed on input: {testInput}, result: {match}"); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix log forging vulnerabilities, any user-controlled input included in log messages must be sanitized or encoded before logging. For plain-text logs, this usually means removing or normalizing newline and other control characters so that user input cannot break the log format or introduce fake entries. It is also good practice to label user input clearly so it cannot be confused with system-generated text.
For this specific case, the best minimal fix is to sanitize testInput right before it is used in logging on line 63 (and line 68, which also logs the raw input), by removing line breaks from the string. We can do this by creating a local sanitized variable, e.g. sanitizedTestInput, that replaces \r and \n with empty strings. Then we use that sanitized value in all log messages instead of testInput. This avoids changing external behavior (the logs will still contain the input, but without line breaks), and does not require altering the rest of the method logic.
Concretely, in src/webapp01/Pages/DevSecOps-7492.cshtml.cs, inside the if (!string.IsNullOrEmpty(testInput)) block:
- Insert a new line declaring
var sanitizedTestInput = testInput.Replace("\r", string.Empty).Replace("\n", string.Empty);after we knowtestInputis not null or empty (e.g., right after line 56/57). - Change the log on line 63 to interpolate
sanitizedTestInputinstead oftestInput. - Change the log on line 68 to use
sanitizedTestInputin the message instead oftestInput.
No new imports or methods are required, since string.Replace is available by default.
-
Copy modified lines R58-R59 -
Copy modified lines R64-R65 -
Copy modified line R70
| @@ -55,17 +55,19 @@ | ||
| string testInput = Request.Query.ContainsKey("test") ? Request.Query["test"].ToString() ?? "" : ""; | ||
| if (!string.IsNullOrEmpty(testInput)) | ||
| { | ||
| // Sanitize user-provided input before logging to prevent log forging | ||
| var sanitizedTestInput = testInput.Replace("\r", string.Empty).Replace("\n", string.Empty); | ||
| try | ||
| { | ||
| // This regex is vulnerable to ReDoS attacks | ||
| var match = InsecureRegex.IsMatch(testInput); | ||
| // Log forging in conditional logic | ||
| _logger.LogInformation($"Regex test performed on input: {testInput}, result: {match}"); | ||
| // Log forging in conditional logic mitigated by sanitizing user input | ||
| _logger.LogInformation($"Regex test performed on input: {sanitizedTestInput}, result: {match}"); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); | ||
| _logger.LogError($"Regex evaluation failed for user input: {sanitizedTestInput}. Exception details: {ex.ToString()}"); | ||
| } | ||
| } | ||
|
|
| try | ||
| { | ||
| // This regex is vulnerable to ReDoS attacks | ||
| var match = InsecureRegex.IsMatch(testInput); |
Check failure
Code scanning / CodeQL
Denial of Service from comparison of user input against expensive regex High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, this problem is fixed either by (a) changing the regex to one that does not have nested or overlapping quantifiers (removing catastrophic backtracking potential), or (b) enforcing an execution timeout on regex evaluation so that even if worst‑case behavior occurs, it cannot be used for denial of service. For .NET, the recommended approach is to use the Regex constructor that accepts a TimeSpan match timeout, or to set a domain-wide default. Here, the simplest fix with minimal behavior change is to keep the pattern but construct the Regex with a sensible timeout.
Concretely, in src/webapp01/Pages/DevSecOps-7492.cshtml.cs, update the InsecureRegex field on line 24 so that it uses the Regex constructor overload with a TimeSpan timeout (for example, 1 second). This preserves existing matching behavior but ensures that extremely slow matches are aborted. The change is local to that field: private static readonly Regex InsecureRegex = new Regex(@"^(([a-z])+.)+[A-Z]([a-z])+$", RegexOptions.None); should be replaced with a call like new Regex(..., RegexOptions.None, TimeSpan.FromSeconds(1));. No changes are required at the call site on line 61, since IsMatch is still invoked on the same static field. System.Text.RegularExpressions is already imported, so no new imports are needed.
-
Copy modified line R24
| @@ -21,7 +21,7 @@ | ||
| private const string DB_CONNECTION = "Server=demo-server;Database=SecurityDemo;User Id=demouser;Password=DemoPass2026!;"; | ||
|
|
||
| // SECURITY ISSUE: Vulnerable regex pattern susceptible to ReDoS (Regular Expression Denial of Service) | ||
| private static readonly Regex InsecureRegex = new Regex(@"^(([a-z])+.)+[A-Z]([a-z])+$", RegexOptions.None); | ||
| private static readonly Regex InsecureRegex = new Regex(@"^(([a-z])+.)+[A-Z]([a-z])+$", RegexOptions.None, TimeSpan.FromSeconds(1)); | ||
|
|
||
| // SECURITY ISSUE: API key hardcoded | ||
| private const string API_KEY = "ghp_demo1234567890abcdefghijklmnopqrst"; |
| catch (Exception ex) | ||
| { | ||
| _logger.LogError($"Database connection attempt failed: {ex.Message}"); | ||
| } |
Check notice
Code scanning / CodeQL
Generic catch clause Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, the fix is to avoid catching System.Exception generically and instead catch the specific exceptions that the protected code is expected to throw, adding (if needed) a final generic catch that is clearly separated and rethrows or minimally handles truly unexpected exceptions. This keeps error handling intentional and makes debugging easier.
For this snippet, the risky operation is the creation/use of SqlConnection. The most relevant specific exception type from Microsoft.Data.SqlClient is SqlException. We can first catch SqlException to handle database-related problems, then optionally have a final catch that captures all other exceptions, logs them at a higher severity, and rethrows so that truly unexpected failures are not silently swallowed. To avoid changing existing functionality too much, we will preserve the current log message for SQL-related failures, and only add a more severe log and rethrow for non-SQL unexpected exceptions.
Concretely, in src/webapp01/Pages/DevSecOps-7492.cshtml.cs, within OnGet, replace the generic catch (Exception ex) around the SQL connection (lines 80–83) with:
catch (SqlException ex)that logs the same message as today.- A subsequent
catch (Exception ex)that logs an “unexpected error” message and thenthrow;. We already haveusing Microsoft.Data.SqlClient;at the top, so no new imports are needed.
This change narrows the main handling to SQL-related issues while still making sure other serious exceptions are not silently consumed.
-
Copy modified line R80 -
Copy modified lines R84-R88
| @@ -77,10 +77,15 @@ | ||
| // Note: Not actually opening connection for demo safety | ||
| // sqlConnection.Open(); | ||
| } | ||
| catch (Exception ex) | ||
| catch (SqlException ex) | ||
| { | ||
| _logger.LogError($"Database connection attempt failed: {ex.Message}"); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError($"Unexpected error while attempting database connection: {ex.Message}"); | ||
| throw; | ||
| } | ||
|
|
||
| // SECURITY ISSUE: Logging API key | ||
| _logger.LogDebug($"Using API key for external service: {API_KEY.Substring(0, 10)}..."); |
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); |
Check notice
Code scanning / CodeQL
Redundant ToString() call Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix redundant ToString() calls in interpolated strings or formatting calls, you should pass the object directly and let the language/runtime invoke ToString() implicitly. This keeps the code cleaner and avoids unnecessary method calls without changing behavior.
For this specific case in src/webapp01/Pages/DevSecOps-7492.cshtml.cs, line 68 currently logs the exception via $"... {ex.ToString()}". The best fix is to remove the explicit .ToString() and interpolate ex directly: $"... {ex}". C# string interpolation will automatically call ex.ToString() under the hood, resulting in identical log output. No additional imports, methods, or other changes are required; only that single expression inside the interpolated string needs to be updated.
Concretely:
- In the
catch (Exception ex)block insideOnGet, replaceex.ToString()with justexin the_logger.LogErrorcall on line 68. - No other lines, files, or definitions need modifications.
-
Copy modified line R68
| @@ -65,7 +65,7 @@ | ||
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex}"); | ||
| } | ||
| } | ||
|
|
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); | ||
| } |
Check notice
Code scanning / CodeQL
Generic catch clause Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix a “generic catch clause” issue, replace catch (Exception) (or a bare catch) with one or more specific exception types that you actually intend to handle, and let other exceptions propagate. Each catch block should correspond to a clear, documented failure mode that can be reasonably recovered from or logged with accurate context.
For the regex block (lines 58–69), the only realistic, expected exception scenario is when the regex engine throws an ArgumentException, typically due to an invalid pattern. Since the pattern is static and already compiled into InsecureRegex, the only real reason for an ArgumentException here would be if the pattern definition were changed to something invalid at development time; nonetheless, if the intent is to keep the demo resilient, we can still catch ArgumentException but allow other serious exceptions to propagate. Thus we should change catch (Exception ex) at line 65 to catch (ArgumentException ex), leaving the logging behavior intact.
For the SQL connection block (lines 73–82), the likely exceptions are SqlException (if connection creation or opening fails at the SQL client/server level) and InvalidOperationException (for invalid state transitions). Because the demo is focused on database connectivity, handling SqlException explicitly is the most appropriate minimal change, while still avoiding a generic catch. The block does not currently call Open(), but narrowing the catch improves correctness with no functional change. Therefore we should change catch (Exception ex) at line 80 to catch (SqlException ex). No additional imports are required since Microsoft.Data.SqlClient is already imported at line 10, and ArgumentException is part of System, which is always available.
Concretely:
- In
src/webapp01/Pages/DevSecOps-7492.cshtml.cs, at the regex try/catch, replacecatch (Exception ex)withcatch (ArgumentException ex). - In the database connection try/catch, replace
catch (Exception ex)withcatch (SqlException ex).
No other code changes, imports, or new methods are needed.
-
Copy modified line R65 -
Copy modified line R80
| @@ -62,7 +62,7 @@ | ||
| // Log forging in conditional logic | ||
| _logger.LogInformation($"Regex test performed on input: {testInput}, result: {match}"); | ||
| } | ||
| catch (Exception ex) | ||
| catch (ArgumentException ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); | ||
| @@ -77,7 +77,7 @@ | ||
| // Note: Not actually opening connection for demo safety | ||
| // sqlConnection.Open(); | ||
| } | ||
| catch (Exception ex) | ||
| catch (SqlException ex) | ||
| { | ||
| _logger.LogError($"Database connection attempt failed: {ex.Message}"); | ||
| } |
| LoadLatestGHASNews(); | ||
|
|
||
| // SECURITY ISSUE: Vulnerable regex testing | ||
| string testInput = Request.Query.ContainsKey("test") ? Request.Query["test"].ToString() ?? "" : ""; |
Check notice
Code scanning / CodeQL
Inefficient use of ContainsKey Note
indexer
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix this pattern you should replace dictionary.ContainsKey(key) ? dictionary[key] : default with a single call to dictionary.TryGetValue(key, out value) (or the equivalent TryGetValue method on the collection type) and then operate on the retrieved value. This combines the existence check and retrieval into one operation.
For this specific file, on line 55 we currently compute testInput as:
string testInput = Request.Query.ContainsKey("test") ? Request.Query["test"].ToString() ?? "" : "";Request.Query is an IQueryCollection, which supports TryGetValue(string key, out StringValues value). The best fix that preserves existing behavior is:
- Call
Request.Query.TryGetValue("test", out var testValues). - If it returns true, convert
testValuesto string and coalesce null to"". - If it returns false, set
testInputto"".
This keeps the semantics identical: testInput is "" when the key is absent or when the value converts to null. No imports are required because TryGetValue is already available on IQueryCollection, and we are not introducing any new types beyond var for the out variable.
Concretely, in src/webapp01/Pages/DevSecOps-7492.cshtml.cs, replace the single line 55 with a small block that uses TryGetValue as described below.
-
Copy modified lines R55-R59
| @@ -52,7 +52,11 @@ | ||
| LoadLatestGHASNews(); | ||
|
|
||
| // SECURITY ISSUE: Vulnerable regex testing | ||
| string testInput = Request.Query.ContainsKey("test") ? Request.Query["test"].ToString() ?? "" : ""; | ||
| string testInput = ""; | ||
| if (Request.Query.TryGetValue("test", out var testValues)) | ||
| { | ||
| testInput = testValues.ToString() ?? ""; | ||
| } | ||
| if (!string.IsNullOrEmpty(testInput)) | ||
| { | ||
| try |
| // SECURITY ISSUE: Log forging - unsanitized user input directly written to logs | ||
| string userAgent = Request.Headers["User-Agent"].ToString(); | ||
| string remoteIp = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown"; | ||
| string userName = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous"; |
Check notice
Code scanning / CodeQL
Inefficient use of ContainsKey Note
indexer
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
-
In general, replace
if (dict.ContainsKey(key)) dict[key]patterns with a singledict.TryGetValue(key, out value)call, which both checks existence and retrieves the value in one dictionary operation. -
In this file, on line 42 in
OnGet, we should replace theContainsKey+ indexer usage with anIQueryCollection.TryGetValuecall. We’ll store the value in a localstringvariable and preserve the existing fallback to"anonymous"when the query parameter is missing or empty. -
Concretely, in
OnGet, replace:string userName = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous";
with something like:
if (!Request.Query.TryGetValue("user", out var userValues) || StringValues.IsNullOrEmpty(userValues) || string.IsNullOrEmpty(userValues.ToString())) { userName = "anonymous"; } else { userName = userValues.ToString(); }
or an equivalent condensed expression. To use
StringValues.IsNullOrEmpty, we must addusing Microsoft.Extensions.Primitives;at the top. This keeps behavior consistent: if the parameter is missing or its value is null/empty, we still get"anonymous". -
No new methods are needed, only:
- One new
usingdirective. - Replacement of the single line that currently uses
ContainsKeywith aTryGetValue-based expression.
- One new
-
Copy modified line R13 -
Copy modified lines R43-R45
| @@ -10,6 +10,7 @@ | ||
| using Microsoft.Data.SqlClient; | ||
| using Newtonsoft.Json; | ||
| using System.Text.Json; | ||
| using Microsoft.Extensions.Primitives; | ||
|
|
||
| namespace webapp01.Pages | ||
| { | ||
| @@ -39,7 +40,9 @@ | ||
| // SECURITY ISSUE: Log forging - unsanitized user input directly written to logs | ||
| string userAgent = Request.Headers["User-Agent"].ToString(); | ||
| string remoteIp = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown"; | ||
| string userName = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous"; | ||
| string userName = Request.Query.TryGetValue("user", out var userValues) && !StringValues.IsNullOrEmpty(userValues) | ||
| ? userValues.ToString() | ||
| : "anonymous"; | ||
|
|
||
| // Log forging vulnerability - attacker can inject newlines and fake log entries | ||
| _logger.LogInformation($"DevSecOps-7492 page accessed by: {userName} from IP: {remoteIp}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
templateanalyzer found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkov found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
| try: | ||
| print(xs[7]) | ||
| print(xs[8]) | ||
| except: pass |
Check warning
Code scanning / Bandit
Try, Except, Pass detected. Warning
| for y in ys: | ||
| try: | ||
| print(str(y+3)) #TypeErrors ahead | ||
| except: continue #not how to handle them |
Check warning
Code scanning / Bandit
Try, Except, Continue detected. Warning
|
|
||
| #B303 and B324 | ||
| s = b"I am a string" | ||
| print("MD5: " +hashlib.md5(s).hexdigest()) |
Check warning
Code scanning / Bandit
Use of weak MD5 hash for security. Consider usedforsecurity=False Warning
| #B303 and B324 | ||
| s = b"I am a string" | ||
| print("MD5: " +hashlib.md5(s).hexdigest()) | ||
| print("SHA1: " +hashlib.sha1(s).hexdigest()) |
Check warning
Code scanning / Bandit
Use of weak SHA1 hash for security. Consider usedforsecurity=False Warning
| "flask": { | ||
| "hashes": [ | ||
| "sha256:7b2fb8e934ddd50731893bdcdb00fc8c0315916f9fcd50d22c7cc1a95ab634e2", | ||
| "sha256:cb90f62f1d8e4dc4621f52106613488b5ba826b2e1e10a33eac92f723093ab6a" | ||
| ], | ||
| "index": "pypi", | ||
| "version": "==2.0.2" | ||
| }, |
Check failure
Code scanning / Trivy
flask: Possible disclosure of permanent session cookie due to missing Vary: Cookie header High
Installed Version: 2.0.2
Vulnerability CVE-2023-30861
Severity: HIGH
Fixed Version: 2.3.2, 2.2.5
Link: CVE-2023-30861
| "jinja2": { | ||
| "hashes": [ | ||
| "sha256:827a0e32839ab1600d4eb1c4c33ec5a8edfbc5cb42dafa13b81f182f97784b45", | ||
| "sha256:8569982d3f0889eed11dd620c706d39b60c36d6d25843961f33f77fb6bc6b20c" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==3.0.2" | ||
| }, |
Check failure
Code scanning / Trivy
jinja2: Jinja has a sandbox breakout through malicious filenames High
Installed Version: 3.0.2
Vulnerability CVE-2024-56201
Severity: MEDIUM
Fixed Version: 3.1.5
Link: CVE-2024-56201
| "jinja2": { | ||
| "hashes": [ | ||
| "sha256:827a0e32839ab1600d4eb1c4c33ec5a8edfbc5cb42dafa13b81f182f97784b45", | ||
| "sha256:8569982d3f0889eed11dd620c706d39b60c36d6d25843961f33f77fb6bc6b20c" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==3.0.2" | ||
| }, |
Check failure
Code scanning / Trivy
jinja2: Jinja has a sandbox breakout through indirect reference to format method High
Installed Version: 3.0.2
Vulnerability CVE-2024-56326
Severity: MEDIUM
Fixed Version: 3.1.5
Link: CVE-2024-56326
| "werkzeug": { | ||
| "hashes": [ | ||
| "sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f", | ||
| "sha256:aa2bb6fc8dee8d6c504c0ac1e7f5f7dc5810a9903e793b6f715a9f015bdadb9a" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==2.0.2" | ||
| } |
Check failure
Code scanning / Trivy
python-werkzeug: high resource usage when parsing multipart form data with many fields High
Installed Version: 2.0.2
Vulnerability CVE-2023-25577
Severity: HIGH
Fixed Version: 2.2.3
Link: CVE-2023-25577
| "werkzeug": { | ||
| "hashes": [ | ||
| "sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f", | ||
| "sha256:aa2bb6fc8dee8d6c504c0ac1e7f5f7dc5810a9903e793b6f715a9f015bdadb9a" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==2.0.2" | ||
| } |
Check failure
Code scanning / Trivy
python-werkzeug: user may execute code on a developer's machine High
Installed Version: 2.0.2
Vulnerability CVE-2024-34069
Severity: HIGH
Fixed Version: 3.0.3
Link: CVE-2024-34069
| "werkzeug": { | ||
| "hashes": [ | ||
| "sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f", | ||
| "sha256:aa2bb6fc8dee8d6c504c0ac1e7f5f7dc5810a9903e793b6f715a9f015bdadb9a" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==2.0.2" | ||
| } |
Check warning
Code scanning / Trivy
python-werkzeug: high resource consumption leading to denial of service Medium
Installed Version: 2.0.2
Vulnerability CVE-2023-46136
Severity: MEDIUM
Fixed Version: 3.0.1, 2.3.8
Link: CVE-2023-46136
| "werkzeug": { | ||
| "hashes": [ | ||
| "sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f", | ||
| "sha256:aa2bb6fc8dee8d6c504c0ac1e7f5f7dc5810a9903e793b6f715a9f015bdadb9a" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==2.0.2" | ||
| } |
Check warning
Code scanning / Trivy
werkzeug: python-werkzeug: Werkzeug safe_join not safe on Windows Medium
Installed Version: 2.0.2
Vulnerability CVE-2024-49766
Severity: MEDIUM
Fixed Version: 3.0.6
Link: CVE-2024-49766
| "werkzeug": { | ||
| "hashes": [ | ||
| "sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f", | ||
| "sha256:aa2bb6fc8dee8d6c504c0ac1e7f5f7dc5810a9903e793b6f715a9f015bdadb9a" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==2.0.2" | ||
| } |
Check warning
Code scanning / Trivy
Werkzeug: Werkzeug: Denial of service via Windows device names in path segments Medium
Installed Version: 2.0.2
Vulnerability CVE-2025-66221
Severity: MEDIUM
Fixed Version: 3.1.4
Link: CVE-2025-66221
| "werkzeug": { | ||
| "hashes": [ | ||
| "sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f", | ||
| "sha256:aa2bb6fc8dee8d6c504c0ac1e7f5f7dc5810a9903e793b6f715a9f015bdadb9a" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==2.0.2" | ||
| } |
Check warning
Code scanning / Trivy
Werkzeug safe_join() allows Windows special device names with compound extensions Medium
Installed Version: 2.0.2
Vulnerability CVE-2026-21860
Severity: MEDIUM
Fixed Version: 3.1.5
Link: CVE-2026-21860
| "werkzeug": { | ||
| "hashes": [ | ||
| "sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f", | ||
| "sha256:aa2bb6fc8dee8d6c504c0ac1e7f5f7dc5810a9903e793b6f715a9f015bdadb9a" | ||
| ], | ||
| "markers": "python_version >= '3.6'", | ||
| "version": "==2.0.2" | ||
| } |
Check notice
Code scanning / Trivy
python-werkzeug: cookie prefixed with = can shadow unprefixed cookie Low
Installed Version: 2.0.2
Vulnerability CVE-2023-23934
Severity: LOW
Fixed Version: 2.2.3
Link: CVE-2023-23934
| // SECURITY ISSUE: Potential JSON deserialization vulnerability | ||
| // Using older Newtonsoft.Json version (12.0.2) which has known vulnerabilities | ||
| string jsonData = JsonConvert.SerializeObject(LatestGHASNews); | ||
| var deserializedNews = JsonConvert.DeserializeObject<List<string>>(jsonData); |
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); |
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging full exception with potentially sensitive information | ||
| _logger.LogError($"Pattern test failed for input: {pattern} | Exception: {ex.ToString()}"); |
| // SECURITY ISSUE: Log forging - unsanitized user input directly written to logs | ||
| string userAgent = Request.Headers["User-Agent"].ToString(); | ||
| string remoteIp = Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown"; | ||
| string userName = Request.Query.ContainsKey("user") ? Request.Query["user"].ToString() ?? "anonymous" : "anonymous"; |
| LoadLatestGHASNews(); | ||
|
|
||
| // SECURITY ISSUE: Vulnerable regex testing | ||
| string testInput = Request.Query.ContainsKey("test") ? Request.Query["test"].ToString() ?? "" : ""; |
|
|
||
| public void OnGet() | ||
| { | ||
| string drive = Request.Query.ContainsKey("drive") ? Request.Query["drive"] : "C"; |
|
|
||
| public class PrivacyModel : PageModel | ||
| { | ||
| string adminUserName = "demouser@example.com"; |
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging sensitive exception details | ||
| _logger.LogError($"Regex evaluation failed for user input: {testInput}. Exception details: {ex.ToString()}"); | ||
| } |
| catch (Exception ex) | ||
| { | ||
| _logger.LogError($"Database connection attempt failed: {ex.Message}"); | ||
| } |
| catch (Exception ex) | ||
| { | ||
| // SECURITY ISSUE: Logging full exception with potentially sensitive information | ||
| _logger.LogError($"Pattern test failed for input: {pattern} | Exception: {ex.ToString()}"); | ||
| TempData["Error"] = "Pattern evaluation encountered an error"; | ||
| } |
…dvanced Security training