NotFoundResult throws NullReferenceException
See original GitHub issueDescription
When an id is not found on a GetAsync(id)
request, the controller properly returns a NotFoundResult
. However, this seems to break after that and what is actually returned to the client is a NullReferenceException
.
Most concerning from a security standpoint is that the stack trace is returned.
The most common problem is when detailed internal error messages such as stack traces, database dumps, and error codes are displayed to the user (hacker). These messages reveal implementation details that should never be revealed.
Reference: Improper Error Handling
I updated my sample repo with a simple integration test (NotFound
) that reproduces this behavior. Please advise if I am missing something.
…
Environment
- JsonApiDotNetCore Version: 4.0.0-alpha3
- Other Relevant Package Versions: not sure
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:16 (10 by maintainers)
Top Results From Across the Web
How do I return NotFound() IHttpActionResult with an error ...
Here's a one-liner for returning a IHttpActionResult NotFound with a simple message: return Content(HttpStatusCode.NotFound, "Foo does not ...
Read more >How to handle null values in ASP.NET Core MVC
When it comes to empty responses to requests, or returning null values from the action methods, the ASP.NET Core MVC framework returns HTTP ......
Read more >How To Throw Custom Exception - Build/Test Issues
When it calls the Dispatch method it encounters a null reference exception, but I can't determine what is null. Can anyone see some...
Read more >Is it better to return null or a new object? : r/csharp
I throw a MissingDataException, which my web server converts into a 404. If I need a non-exception path, I use the OrNull suffix...
Read more >How to Fix NullReferenceException in C#! (4 Step Process)
Let's learn what is a NullReferenceException, what causes it and a Step-by-Step ... HANDLING NULL REFERENCE EXCEPTION IN C# (URDU / HINDI).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see where there is a method
DisableDetailedErrorsIfProduction
that is disabling these errors if the “ASPNETCORE_ENVIRONMENT” environment variable equals “Production”, but not everyone’s production environments set that variable to the same value.The method is setting the
DisableErrorStackTraces
andDisableErrorSource
properties on theJsonApiOptions
class, but when I try to set the same properties on theJsonApiOptions
class available in theAddJsonApi
method, they aren’t there. Could these options be added to setup for people whose production environments set the “ASPNETCORE_ENVIRONMENT” variable to something besides “Production” (like “prod”, etc.)?@crgolden Chris, thanks for your effort to indicate problems with JADNC, a lot of points are valid.