question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NotFoundResult throws NullReferenceException

See original GitHub issue

Description

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
crgoldencommented, Nov 9, 2019

the stack trace is returned

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 and DisableErrorSource properties on the JsonApiOptions class, but when I try to set the same properties on the JsonApiOptions class available in the AddJsonApi 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.)?

0reactions
wisepotatocommented, Nov 26, 2019

@crgolden Chris, thanks for your effort to indicate problems with JADNC, a lot of points are valid.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found