You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Digest authentication requires Cookie header for auth to succeed #124
Everything works as expected from a web browser. As it should.
But I can't get my Java client code to work. I'm 99% sure I'm generating the correct MD5s, but could somebody please walk me through the steps? Must be something I don't understand there. Here's what I'm doing now
Create the response, put it into "Authorizaton" header
connect(), try to read the response
This always fails with another 401.
p.s. If it helps I'd be happy to try this at some planned time, to a planned user/password, and let one of you view the log files on the httpbin side to try to see what is happening.
I ran into this myself, and looked into this with @christopherhesse's help. It appears this was introduced in commit 4870f70, which added the requirement that the request include a Cookie: header line, with any value. I have no idea why this is done, I'm pretty sure the standard doesn't require that a client handle cookies in order to perform digest authentication.
ping @sigmavirus24, what was the reason behind requiring a cookie header for digest auth in 4870f70? The RFC doesn't seem to mention anything about requiring a cookie. Is there a corresponding test in requests that expects this behavior?
@kevin1024 yes. There's nothing requiring it in the RFC but there are servers that expect this behaviour and we needed this behaviour for requests. The RFC allows this behaviour and as such every user-agent should be prepared to handle it.
The RFC allows this behaviour and as such every user-agent should be prepared to handle it.
Agreed. However, there is no way to use httpbin to test a a basic auth endpoint that doesn't require a cookie. Also, I don't think that the behavior of requiring a cookie to be set in order for the digest auth to succeed is actually tested or required by requests.
How about this:
Remove the requirement for a cookie to be set in order for the auth to succeed
Add a way to make httpbin return extra headers from the auth request with a querystring parameter.
This would work in the same way as the /response-headers endpoint.
Now you can rewrite the 2 requests tests like this:
What do you think @sigmavirus24? I would like to come up with a solution that will still work for requests, but be general enough that httpbin can be used for testing other libraries too.
but be general enough that httpbin can be used for testing other libraries too
What other libraries use HTTPBin for testing? Specifically what other libraries use HTTPBin to test this and would not consider a failure (on their part to properly catch the cookies) useful information?
Specifically what other libraries use HTTPBin to test this and would not consider a failure (on their part to properly catch the cookies) useful information?
Well, perhaps it would be good to have a test that tests digest auth separately from digest auth + cookie handling. It's generally good practice to keep your tests isolated.
I would agree with you except that this is not atypical behaviour for a server using digest authentication. Really, for parity, this should be implemented for basic auth, but most clients send that pre-emptively. I for one am also beginning work on a new user-agent in a different language and will be using this endpoint to ensure that user-agent works correctly.
I think it is worth stating protocol here, as I found it hard to follow without refreshing my memory (more details on Wikipedia):
Client opens with a request without any headers (or cookies)
Server responds with a 401 code including a 'WWW-Authenticate' header.
Client re-requests with an "Authorization" header formatted using information from the 'WWW-Authenticate' header it got.
Server validates this information, and returns the page as normal.
The problem we are talking about in this bug is that if during step 2 the server also sends back a cookie that in step 3 the client sends that cookie back to the server. The current code is being a bit crude in that it only checks if there is any cookie at all in step 3, rather than checking for the cookie it sends specifically.
While this might not be in the RFC for digest authentication specifically, it is part of the underlying http protocol, and any property functioning client should respect it. I will be sending in a pull request that both sharpens this requirement (checking the cookie explicitly) and allows a specific bypass cookie so that clients that don't want to support collecting cookies during authentication can bypass this.
@larkost that sounds like a good way forward. I think the arguments here and on other issues are leading me to think that @johnsheehan and @Runscope/httpbin need to sit down on IRC or a G+ hangout and discuss the scope/purpose of HTTPBin and put together a clearly written document for users and contributors alike. Perhaps, I should start another issue to plan this (or we can just do an email thread to schedule it).
For those who want to see this in more clarity, you can run httpbin locally with the following command: python -m httpbin.core
Then use curl to demonstrate that it fails without cookies: curl --digest 'http://localhost:5000/digest-auth/auth/a/b' --user a:b
and that it succeeds with cookies: curl --digest 'http://localhost:5000/digest-auth/auth/a/b' --user a:b --cookie-jar /tmp/cookietemp
If you want to see more details, add the 'i flag to get both headers from the server.
I have (re) posted my pull request that should handle most of the points raised in this issue. I did take a slight turn from what I posted before as the opt-out for cookie checking is no longer a cookie, but rather a new route (/digest-auth-nocookie) that uses the same method as /digest-auth but skips the cookie part. The PR also fixes a few minor issues with /digest-auth.
On @sigmavirus24's call for a pow-wow: I don't see much of a call for it, but if you need a data point, we at RethinkDB are using it to check the correctness of our r.http term against a http server. Having lots of endpoints to deal with all of the cases we need (and erring when we make a mistake) is invaluable.
IMO the main issue is that the fact that the endpoint requires cookie support is kind of suprising and undocumented. Someone might spend a lot of time digging into their digest auth code trying to debug it, when in fact the issue lies elsewhere (the cookie). Their digest auth code is fine, but the missing cookie is breaking the response.
So maybe more of a documentation problem than anything?
The version in my pull request separates out the error for the cookie problem, marking it as a 403 error (vs. a 401 for digest auth issues) and returns a message explaining this in the response body. So in this it is a bit better at self-documenting.
I agree with Kevin, it's more of a documentation thing. I was one of those
"someones" who spent a lot of time trying to debug perfectly fine digest
code. I think the change to a 403 with a useful message will help a lot.
On Tue, Dec 23, 2014 at 7:31 PM, Kevin McCarthy [email protected]
wrote:
IMO the main issue is that the fact that the endpoint requires cookie
support is kind of suprising and undocumented. Someone might spend a lot of
time digging into their digest auth code trying to debug it, when in fact
the issue lies elsewhere (the cookie). Their digest auth code is fine, but
the missing cookie is breaking the response.
So maybe more of a documentation problem than anything?
—
Reply to this email directly or view it on GitHub #124 (comment).
Activity
Tryneus commentedon May 7, 2014
I ran into this myself, and looked into this with @christopherhesse's help. It appears this was introduced in commit 4870f70, which added the requirement that the request include a
Cookie:header line, with any value. I have no idea why this is done, I'm pretty sure the standard doesn't require that a client handle cookies in order to perform digest authentication.MorganConrad commentedon May 27, 2014
@Tryneus Thanks - that did the trick! IMO, should be fixed or at least noted in the docs.
kevin1024 commentedon Jun 21, 2014
ping @sigmavirus24, what was the reason behind requiring a cookie header for digest auth in 4870f70? The RFC doesn't seem to mention anything about requiring a cookie. Is there a corresponding test in requests that expects this behavior?
sigmavirus24 commentedon Jun 22, 2014
@kevin1024 yes. There's nothing requiring it in the RFC but there are servers that expect this behaviour and we needed this behaviour for requests. The RFC allows this behaviour and as such every user-agent should be prepared to handle it.
kevin1024 commentedon Jun 22, 2014
OK I found the corresponding tests in requests. It appears that Requests used to have a bug with processing set-cookie headers on 401 responses.
Agreed. However, there is no way to use httpbin to test a a basic auth endpoint that doesn't require a cookie. Also, I don't think that the behavior of requiring a cookie to be set in order for the digest auth to succeed is actually tested or required by requests.
How about this:
This would work in the same way as the /response-headers endpoint.
Now you can rewrite the 2 requests tests like this:
What do you think @sigmavirus24? I would like to come up with a solution that will still work for requests, but be general enough that httpbin can be used for testing other libraries too.
[-]Can't get Digest Authorization to work[/-][+]Digest authentication requires Cookie header for auth to succeed [/+]sigmavirus24 commentedon Jun 23, 2014
What other libraries use HTTPBin for testing? Specifically what other libraries use HTTPBin to test this and would not consider a failure (on their part to properly catch the cookies) useful information?
kevin1024 commentedon Jun 23, 2014
Well, perhaps it would be good to have a test that tests digest auth separately from digest auth + cookie handling. It's generally good practice to keep your tests isolated.
sigmavirus24 commentedon Jun 23, 2014
I would agree with you except that this is not atypical behaviour for a server using digest authentication. Really, for parity, this should be implemented for basic auth, but most clients send that pre-emptively. I for one am also beginning work on a new user-agent in a different language and will be using this endpoint to ensure that user-agent works correctly.
larkost commentedon Dec 23, 2014
I think it is worth stating protocol here, as I found it hard to follow without refreshing my memory (more details on Wikipedia):
The problem we are talking about in this bug is that if during step 2 the server also sends back a cookie that in step 3 the client sends that cookie back to the server. The current code is being a bit crude in that it only checks if there is any cookie at all in step 3, rather than checking for the cookie it sends specifically.
While this might not be in the RFC for digest authentication specifically, it is part of the underlying http protocol, and any property functioning client should respect it. I will be sending in a pull request that both sharpens this requirement (checking the cookie explicitly) and allows a specific bypass cookie so that clients that don't want to support collecting cookies during authentication can bypass this.
sigmavirus24 commentedon Dec 23, 2014
@larkost that sounds like a good way forward. I think the arguments here and on other issues are leading me to think that @johnsheehan and @Runscope/httpbin need to sit down on IRC or a G+ hangout and discuss the scope/purpose of HTTPBin and put together a clearly written document for users and contributors alike. Perhaps, I should start another issue to plan this (or we can just do an email thread to schedule it).
larkost commentedon Dec 23, 2014
For those who want to see this in more clarity, you can run
httpbinlocally with the following command:python -m httpbin.coreThen use
curlto demonstrate that it fails without cookies:curl --digest 'http://localhost:5000/digest-auth/auth/a/b' --user a:band that it succeeds with cookies:
curl --digest 'http://localhost:5000/digest-auth/auth/a/b' --user a:b --cookie-jar /tmp/cookietempIf you want to see more details, add the
'iflag to get both headers from the server.larkost commentedon Dec 23, 2014
I have (re) posted my pull request that should handle most of the points raised in this issue. I did take a slight turn from what I posted before as the opt-out for cookie checking is no longer a cookie, but rather a new route (
/digest-auth-nocookie) that uses the same method as/digest-authbut skips the cookie part. The PR also fixes a few minor issues with/digest-auth.On @sigmavirus24's call for a pow-wow: I don't see much of a call for it, but if you need a data point, we at RethinkDB are using it to check the correctness of our
r.httpterm against a http server. Having lots of endpoints to deal with all of the cases we need (and erring when we make a mistake) is invaluable.sigmavirus24 commentedon Dec 24, 2014
@larkost the meeting is more of a high-level discussion than anything else.
kevin1024 commentedon Dec 24, 2014
IMO the main issue is that the fact that the endpoint requires cookie support is kind of suprising and undocumented. Someone might spend a lot of time digging into their digest auth code trying to debug it, when in fact the issue lies elsewhere (the cookie). Their digest auth code is fine, but the missing cookie is breaking the response.
So maybe more of a documentation problem than anything?
larkost commentedon Dec 26, 2014
The version in my pull request separates out the error for the cookie problem, marking it as a 403 error (vs. a 401 for digest auth issues) and returns a message explaining this in the response body. So in this it is a bit better at self-documenting.
MorganConrad commentedon Dec 28, 2014
I agree with Kevin, it's more of a documentation thing. I was one of those
"someones" who spent a lot of time trying to debug perfectly fine digest
code. I think the change to a 403 with a useful message will help a lot.
On Tue, Dec 23, 2014 at 7:31 PM, Kevin McCarthy [email protected]
wrote: