@@ -17,7 +17,7 @@ internal sealed class Tools(ILogger<Tools> logger)
1717 [ Description ( "Starts a content generation workflow and returns the instance ID for tracking." ) ]
1818 public string StartContentGenerationWorkflow ( [ Description ( "The topic for content generation" ) ] string topic )
1919 {
20- this . _logger . LogInformation ( "Starting content generation workflow for topic: {Topic}" , topic ) ;
20+ this . _logger . LogInformation ( "Starting content generation workflow for topic: {Topic}" , SanitizeLogValue ( topic ) ) ;
2121
2222 const int MaxReviewAttempts = 3 ;
2323 const float ApprovalTimeoutHours = 72 ;
@@ -34,7 +34,7 @@ internal sealed class Tools(ILogger<Tools> logger)
3434
3535 this . _logger . LogInformation (
3636 "Content generation workflow scheduled to be started for topic '{Topic}' with instance ID: {InstanceId}" ,
37- topic ,
37+ SanitizeLogValue ( topic ) ,
3838 instanceId ) ;
3939
4040 return $ "Workflow started with instance ID: { instanceId } ";
@@ -45,7 +45,7 @@ public async Task<object> GetWorkflowStatusAsync(
4545 [ Description ( "The instance ID of the workflow to check" ) ] string instanceId ,
4646 [ Description ( "Whether to include detailed information" ) ] bool includeDetails = true )
4747 {
48- this . _logger . LogInformation ( "Getting status for workflow instance: {InstanceId}" , instanceId ) ;
48+ this . _logger . LogInformation ( "Getting status for workflow instance: {InstanceId}" , SanitizeLogValue ( instanceId ) ) ;
4949
5050 // Get the current agent context using the session-static property
5151 OrchestrationMetadata ? status = await DurableAgentContext . Current . GetOrchestrationStatusAsync (
@@ -54,7 +54,7 @@ public async Task<object> GetWorkflowStatusAsync(
5454
5555 if ( status is null )
5656 {
57- this . _logger . LogInformation ( "Workflow instance '{InstanceId}' not found." , instanceId ) ;
57+ this . _logger . LogInformation ( "Workflow instance '{InstanceId}' not found." , SanitizeLogValue ( instanceId ) ) ;
5858 return new
5959 {
6060 instanceId ,
@@ -78,7 +78,16 @@ public async Task SubmitHumanApprovalAsync(
7878 [ Description ( "The instance ID of the workflow to submit feedback for" ) ] string instanceId ,
7979 [ Description ( "Feedback to submit" ) ] HumanApprovalResponse feedback )
8080 {
81- this . _logger . LogInformation ( "Submitting human approval for workflow instance: {InstanceId}" , instanceId ) ;
81+ this . _logger . LogInformation ( "Submitting human approval for workflow instance: {InstanceId}" , SanitizeLogValue ( instanceId ) ) ;
8282 await DurableAgentContext . Current . RaiseOrchestrationEventAsync ( instanceId , "HumanApproval" , feedback ) ;
8383 }
84+
85+ /// <summary>
86+ /// Sanitizes a user-provided value for safe inclusion in log entries
87+ /// by removing control characters that could be used for log forging.
88+ /// </summary>
89+ private static string SanitizeLogValue ( string value ) =>
90+ value
91+ . Replace ( "\r " , string . Empty , StringComparison . Ordinal )
92+ . Replace ( "\n " , string . Empty , StringComparison . Ordinal ) ;
8493}
0 commit comments