-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Added handling of httpOnly and secure flags of cookies when redirecting #1491
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
Conversation
Hi, Thanks for trying to contribute. Sadly, your fix is wrong. The wrong JSESSIONID cookie is being sent because AHC doesn't currently have a cookie jar implementing RFC6265. httpOnly attribute has nothing to do with this (makes a cookie not reachable with Javascript). CookieJar feature request was logged as #1235. I recently closed it due to lack of activity. |
thank you for quick response, @slandelle ! Could you please clarify what would be different in handling my example in case of implementation of |
@unoexperto Please take the time to read RFC6265, in particular the rules about domain and path matching. Also please properly read specification of |
@slandelle Perhaps I misinterpret the RFC. Consider following statement: In case of redirection handler AHC is the agent. Thus it should not use I can work on implementing cookie jar for AHC but do you agree that |
Indeed
You get it wrong. A redirect is an HTTP request. A "non-HTTP" API is for example Javascript's |
It doesn't matter that it's HTTP request. From server's prospective it's an agent whether it's your code or browser with JS interpreter. It wants certain cookie to be present which is curently lost. I'm ready to spend my personal time and implement cookie jar for this project but tell me exactly step-by-step what behavior for downloading http://www.thelancet.com/journals/lancet/article/PIIS1474-4422(17)30433-7 you consider correct handling. Here is dump of correct and incorrect communication Feel free to answer in French if it's more convenient for you. |
…, now handling cookies as a Set instead of List
Please, try reading the spec. HttpOnly is meant so to block cookie stealing with malicious Javascript. AHC doesn't support fetching your page because you set 2 different cookies, both named JSESSIONID, on 2 different domains. As AHC doesn't currently have a CookieJar that implements domain matching, it gets it wrong. If you want to contribute, there's everything you need in the Gatling implementation. You can also check the test. |
@slandelle Actually now I see that you're right. I'll ping you when I'm done with integrating |
Cool! As I said, the main difference is an implementation for AHC would need to be mutable and threadsafe, typically thanks to a ConcurrentHashMap, on contrary to the Gatling's one whose thread safety is guaranteed by Gatling's model. |
@slandelle Got it. Could you create https://gitter.im room for any of your projects for easier communication in future ? |
I don't plan to have chat rooms for my projects: AHC is my pet project, and I don't have time to provide free support, and Gatling is the means of making a living for my company, so we provide support for our customers. |
@slandelle Following is not final implementation but demonstration of approach I'd like to take. I looked at the AHC code and I think the least intrusive change would be to remove cookie manipulations from Here is the change Then in my client code I I added one
of course I'd need to add expiration of cookies here too. Other things I may do:
What do you think ? |
There's a chance those Filters (Request, Response, IOExceptionFilter) will go away or will be redesigned in a future major release:
Atm, I'd rather not have implementation rely on something that might go away.
Sorry, but that's not possible to break API now as I'm about to release 2.1.0 stable.
Yep, just please code in Java here, not in Scala, so other people might be more inclined to join the discussion. |
@slandelle I see. So would you prefer more then if I instead add |
Yep |
@slandelle All right. Here we go :) https://github.com/unoexperto/async-http-client/commit/746ff0d15cb092fa82486260d78f343e75709cda I decided not to invent the wheel so I took I also think I should implement Let me know what you think. |
I'm sorry, but I don't feel comfortable with this. |
FYI, I'll be releasing AHC 2.1.0 stable once this lands. |
@slandelle No worries. I can rewrite it tomorrow. How do you feel about rest of changes and |
Regarding CookieStore, I'd rather keep the interface minimal first, ie only Then, there's a problem with adding the cookies from the CookieStore into the request in So, except for trimming CookieStore interface down, LGTM |
Certain calls work incorrectly due to overridden cookies.
For example GET request of
http://www.thelancet.com/journals/lancet/article/PIIS1474-4422(17)30433-7
consists of eight redirects and all of them are HTTPS calls.
Response from 3rd redirect to
id.elsevier.com
returnsSet-Cookie
forJSESSION
withhttpOnly
flag. ButJSESSION
is already set. This response overrides it which breaks subsequent call tosecure.jbs.elsevierhealth.com
.As result client is being redirected to front page of the website.