Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"405: Method not allowed" = Misleading error message → Replace with better HTTP status code #11260

Closed
SetTrend opened this issue Jun 16, 2019 · 9 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates investigate Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue.

Comments

@SetTrend
Copy link

SetTrend commented Jun 16, 2019

Is your feature request related to a problem? Please describe.

If HttpPost/HttpDelete attributes won't precisely reflect the Web API endpoint, HTTP status 405 Method not allowed is returned to the client.

I believe this status message to be inappropriate, confusing and misleading.

Describe the solution you'd like

I suggest to, instead, return one of the following status codes in the above case:

  • 400 Bad Request
  • 404 Not Found
  • 501 Not Implemented

Additional context

See the following two StackOverflow issues:

@analogrelay
Copy link
Contributor

If HttpPost/HttpDelete attributes won't precisely reflect the Web API endpoint

To clarify, do you mean you have a situation where you specify HttpPost but the user sends a GET or DELETE or other non-POST method?

I believe this status message to be inappropriate, confusing and misleading.

I'm not sure I understand why you think this is an inappropriate response assuming I understand your scenario correctly. The server is making clear (via the attributes) which HTTP Method is allowed (POST, DELETE, etc.) and if the client uses a different one, we return a 405 error, to tell the client they used the wrong HTTP Method.

Can you provide a small runnable sample that reproduces the problem and describe what behavior you'd expect to see?

@analogrelay analogrelay added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Jun 16, 2019
@SetTrend
Copy link
Author

SetTrend commented Jun 16, 2019

At this time I'm in a critical project phase at my customers'. So, I currently don't have time/resources to create a sample project.

Let me give you a brief example:

[Route("api/[controller]")]
[ApiController]
public class MyController
{
  public ActionResult Delete(int id)
  {...}
}

-or-

[Route("api/[controller]")]
[ApiController]
public class MyController
{
  [HttpDelete]
  public ActionResult Delete(int id)
  {...}
}

Both return "405 Method not allowed" on a request like

DELETE http://localhost/api/my/1 HTTP/1.1

@analogrelay
Copy link
Contributor

analogrelay commented Jun 17, 2019

Ah, I see. So you are using an HTTP method allowed by the request. Thanks for the extra context! Someone from MVC would need to look at this further (they'll look at it during their regular triage process). Getting a runnable sample project would certainly help diagnose the issue.

@mkArtakMSFT
Copy link
Member

Thanks for contacting us, @SetTrend.
Please share the full controller code.

@SetTrend
Copy link
Author

Thanks, @anurse and @mkArtakMSFT, for your kind help.

At this time my controller works as expected because I found the reason for this issue after a while and corrected the code.

I may be able to get some spare time in 2-3 weeks to create a sample project. If that'd be sufficient for you?

@mkArtakMSFT
Copy link
Member

Sure, that will be fine. I hope, though, that we may be able to find time and try to repro this on our own before then.

/cc @rynowak , @pranavkm

@mkArtakMSFT
Copy link
Member

@ryanbrandenburg please work with @pranavkm and try to repro this.

@pranavkm
Copy link
Contributor

@SetTrend my guess is that you have another action with the exact route but a different HTTP method constraint. It's the most likely explanation for why you're seeing a 405. If you think this isn't the case and have an application that reproduces the issue, feel free to reopen this issue.

@silkfire
Copy link

silkfire commented Oct 7, 2019

@SetTrend What did you change in your code in order to resolve this issue?

@rynowak @mkArtakMSFT @pranavkm Coming from 2.2, I find it strange that I'm getting 405 instead of 404. The Method Not Allowed status code indicates that the resource does exist, but not under the requested verb, shouldn't this be considered a security issue as this exposes the knowledge of resource to a caller that they should not even know the existence of?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates investigate Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue.
Projects
None yet
Development

No branches or pull requests

6 participants