A caught exception's stack trace or full text is sent back in a response
What it finds
ex.ToString() and ex.StackTrace contain type names, file paths and the structure of the code, which help an attacker more than a user. A generic message with a correlation id, and the details in the log, serve both. The rule reports them passed to the result helpers of ASP.NET controllers and to WriteAsync inside a catch that names the exception.
From the rule's source, exception_details_in_response.rs.
using System;using Microsoft.AspNetCore.Mvc; class OrdersController : ControllerBase{ IActionResult Get() { try { return Ok(Load()); } catch (Exception ex) { return BadRequest(ex.ToString());tx0 reports: BadRequest sends the exception's details to the client } } object Load() => null;} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:exception-details-in-response" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:exception-details-in-response] reason="..."tx0 explain tx0/csharp:exception-details-in-response shows the same in the terminal. Found a false positive? Report it.