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

Wrong HTTP response code from API for unauthorized request #58

Closed
josecelano opened this issue Aug 10, 2022 · 3 comments
Closed

Wrong HTTP response code from API for unauthorized request #58

josecelano opened this issue Aug 10, 2022 · 3 comments

Comments

@josecelano
Copy link
Member

josecelano commented Aug 10, 2022

Request without token:

$ curl -i http://127.0.0.1:1212/api/torrents
HTTP/1.1 500 Internal Server Error
content-type: text/plain; charset=utf-8
content-length: 51
date: Wed, 10 Aug 2022 08:32:46 GMT

Unhandled rejection: Err { reason: "unauthorized" }

Request with token:

$ curl -i http://127.0.0.1:1212/api/torrents?token=MyAccessToken
HTTP/1.1 200 OK
content-type: application/json
content-length: 2
date: Wed, 10 Aug 2022 08:45:47 GMT

[]

I think the response code should be 401 for this endpoint.

NOTE for other endpoints: if knowing the resource URL implies getting info you should not have, then you should return 404 instead of 403 (Insecure Direct Object References (IDOR)).

Links

  1. https://auth0.com/blog/forbidden-unauthorized-http-status-codes/
  2. https://enterprisecraftsmanship.com/posts/rest-api-response-codes-400-vs-500/
@mickvandijke
Copy link
Member

I think you're right, this should be returning a 401.

@josecelano
Copy link
Member Author

Relates to #144

@josecelano
Copy link
Member Author

I'm closing this issue as we should include this task in a comprehensive contract for the API v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants