C Sharp Stack Trace In Action Result
Description
This detector identifies ASP.NET Core controller action methods that return stack trace or exception details directly in HTTP responses. Exposing stack traces in action results is a security vulnerability because it leaks sensitive internal application details (file paths, method names, library versions, server architecture) to potential attackers, enabling reconnaissance and facilitating further attacks.
Detection Strategy
• The detector only activates when the Microsoft.AspNetCore.Mvc namespace is imported in the file, ensuring analysis is scoped to ASP.NET Core MVC controller code.
• The detector scans for method definitions that qualify as controller actions — specifically methods inside classes that inherit from MVC controller base types and return action result types (e.g., IActionResult, ActionResult).
• Within each identified controller action's body block, the detector inspects all return statements for expressions that expose exception or stack trace information, such as returning exception objects, exception messages, stack trace strings, or wrapping them directly in response objects (e.g., Ok(ex), BadRequest(ex.StackTrace)).
• A vulnerability is reported when a controller action method is found to return or leak exception/stack trace data through its action result, flagging the specific return statement responsible for the exposure.
Vulnerable code example
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/items")]
public class ItemsController : ControllerBase
{
[HttpGet("{id}")]
public IActionResult Get(int id)...✅ Secure code example
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
[ApiController]
[Route("api/items")]
public class ItemsController : ControllerBase
{
private readonly ILogger<ItemsController> _logger;...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' pentesting team, fill out this contact form.