-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Incorrect HTTP status code when macaroon is not provided over REST API #2332
Comments
Just adding some info here: I think a 401 would be the most appropriate:
Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#Client_error_responses More details: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 The specific difference to 403 is that a 401 means "try again with credentials", while 403 means "I got your credentials but they don't allow you to access the requested resource". So when no macaroons are sent, the server should respond with "try again with credentials" - i.e. 401. |
I was thinking about it but many browsers automatically assume basic authentication (but maybe only with some additional header?), so I'm unsure if it's actually suitable. |
I think that depends on the There's a link to a list of alternative standard authentication schemes (alternatives to It seems to be okay to define your own scheme, so maybe |
In that case, I agree for it to return 401. It should be made sure to return 403 in case of invalid macaroon. |
Ah this really got me today 😓 |
I might give this a shot on the weekend, but I might need some guidance for my first code contribution. |
Before I create a PR I'd love to get feedback from someone who knows the LND code base regarding if I'm on the right track:
Digging deeper:
So the solution seems to be to let I looked for tests that would need to be extended and found P.S.: I didn't debug into the code yet, I just went through the code in an editor. |
@philippgille Good detective work! From looking at how grpc intereptors are used, what you might need is for the error from macaroon validation to conform to the |
@halseth: Thanks for letting me know that I'm on the right track!
Yes, my proposal was to use gRPC's
And according to the GoDoc of
This should be exactly what we need. I'll work on a PR then :) |
Closing this issue, based on the last comment on the linked pr: #2863 |
@saubyk I ran the reproduction steps again on 0.17 and it's still broken. I might be able to look into making a PR soon. |
Hi @Kixunil thanks for volunteering a pr. Feel free to reopen once you have the pr up. Thanks. |
Background
The HTTP error code returned by lnd using REST API is not correct. It returns 500 Internal server error instead of 4xx. This is confusing when debugging.
Your environment
lnd
0.5.1uname -a
on *Nix)Linux <redacted> 3.16.0-4-amd64 #1 SMP Debian 3.16.51-3 (2017-12-13) x86_64 GNU/Linux
Steps to reproduce
restlisten=127.0.0.1:9737
wget --content-on-error --no-check-certificate -O - https://127.0.0.1:9737/v1/getinfo
Expected behaviour
Error 403 Forbidden or other reasonable 4xx error is returned.
Actual behaviour
500 Internal server error is returned
Ironically, since error 500 means there's something broken with the server, it's strictly true (server sending bad status code), but it doesn't help at all.
The text was updated successfully, but these errors were encountered: