Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/WebApplication1/Controllers/RequestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ [FromBody]ProgrammableServiceRequest request
{

//this action will be called anytime a user wants to interact with your application
_logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", request.Mobile, request.SessionId,
JsonConvert.SerializeObject(request));
var sanitizedRequest = JsonConvert.SerializeObject(request).Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", request.Mobile, request.SessionId, sanitizedRequest);

Check failure

Code scanning / CodeQL

Log entries created from user input

This log entry depends on a [user-provided value](1).

Copilot Autofix

AI over 1 year ago

To fix the problem, we need to sanitize the request.Mobile value before logging it. This can be done by removing any new line characters from the request.Mobile string. We will use the String.Replace method to ensure that no line endings are present in the user input. This will prevent any potential log forging or injection attacks.

Suggested changeset 1
examples/WebApplication1/Controllers/RequestController.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/examples/WebApplication1/Controllers/RequestController.cs b/examples/WebApplication1/Controllers/RequestController.cs
--- a/examples/WebApplication1/Controllers/RequestController.cs
+++ b/examples/WebApplication1/Controllers/RequestController.cs
@@ -44,3 +44,4 @@
             var sanitizedRequest = JsonConvert.SerializeObject(request).Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
-            _logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", request.Mobile, request.SessionId, sanitizedRequest);
+            var sanitizedMobile = request.Mobile.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+            _logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", sanitizedMobile, request.SessionId, sanitizedRequest);
             
EOF
@@ -44,3 +44,4 @@
var sanitizedRequest = JsonConvert.SerializeObject(request).Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", request.Mobile, request.SessionId, sanitizedRequest);
var sanitizedMobile = request.Mobile.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", sanitizedMobile, request.SessionId, sanitizedRequest);

Copilot is powered by AI and may make mistakes. Always verify output.

Check failure

Code scanning / CodeQL

Log entries created from user input

This log entry depends on a [user-provided value](1).

Copilot Autofix

AI over 1 year ago

To fix the problem, we need to sanitize the SessionId before logging it. This can be done by removing any newline characters from the SessionId to prevent log forging. We will use the Replace method to remove newline characters from the SessionId before logging it.

Suggested changeset 1
examples/WebApplication1/Controllers/RequestController.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/examples/WebApplication1/Controllers/RequestController.cs b/examples/WebApplication1/Controllers/RequestController.cs
--- a/examples/WebApplication1/Controllers/RequestController.cs
+++ b/examples/WebApplication1/Controllers/RequestController.cs
@@ -44,3 +44,4 @@
             var sanitizedRequest = JsonConvert.SerializeObject(request).Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
-            _logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", request.Mobile, request.SessionId, sanitizedRequest);
+            var sanitizedSessionId = request.SessionId.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+            _logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", request.Mobile, sanitizedSessionId, sanitizedRequest);
             
EOF
@@ -44,3 +44,4 @@
var sanitizedRequest = JsonConvert.SerializeObject(request).Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", request.Mobile, request.SessionId, sanitizedRequest);
var sanitizedSessionId = request.SessionId.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogDebug("received request for {msisdn} {session_id} {gs_request}", request.Mobile, sanitizedSessionId, sanitizedRequest);

Copilot is powered by AI and may make mistakes. Always verify output.

var response = await _programmableService.ExecuteInteraction(request, nameof(EvdController));
return Ok(response);
Expand Down