Skip to content

Commit 0ed20f1

Browse files
fix(security): replace 2 generic catches in Agent.Host/Program.cs
Added JsonException, IOException, NotImplementedException, InvalidOperationException, ArgumentException handlers Refs: CodeQL cs/catch-of-all-exceptions
1 parent 894f836 commit 0ed20f1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Agent.Host/Program.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535

3636
return response.Success ? 0 : 1;
3737
}
38+
catch (System.Text.Json.JsonException jsonEx)
39+
{
40+
await WriteErrorResponse($"JSON error: {jsonEx.Message}");
41+
return 1;
42+
}
43+
catch (IOException ioEx)
44+
{
45+
await WriteErrorResponse($"I/O error: {ioEx.Message}");
46+
return 1;
47+
}
3848
catch (Exception ex)
3949
{
4050
await WriteErrorResponse($"Unhandled exception: {ex.Message}");
@@ -91,6 +101,27 @@ static async Task<AgentExecutionResponse> ExecuteAgentAsync(AgentExecutionReques
91101
response.Error = $"Agent execution exceeded maximum duration of {request.MaxDurationSeconds ?? 60} seconds";
92102
response.DurationMs = stopwatch.ElapsedMilliseconds;
93103
}
104+
catch (NotImplementedException notImplEx)
105+
{
106+
stopwatch.Stop();
107+
response.Success = false;
108+
response.Error = $"Not implemented: {notImplEx.Message}";
109+
response.DurationMs = stopwatch.ElapsedMilliseconds;
110+
}
111+
catch (InvalidOperationException invalidOpEx)
112+
{
113+
stopwatch.Stop();
114+
response.Success = false;
115+
response.Error = $"Invalid operation: {invalidOpEx.Message}";
116+
response.DurationMs = stopwatch.ElapsedMilliseconds;
117+
}
118+
catch (ArgumentException argEx)
119+
{
120+
stopwatch.Stop();
121+
response.Success = false;
122+
response.Error = $"Invalid argument: {argEx.Message}";
123+
response.DurationMs = stopwatch.ElapsedMilliseconds;
124+
}
94125
catch (Exception ex)
95126
{
96127
stopwatch.Stop();

0 commit comments

Comments
 (0)