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

Cookies don't seem to get picked up within a chain or redirect requests #113

Closed
mdirkse opened this issue Jul 7, 2020 · 5 comments
Closed

Comments

@mdirkse
Copy link

mdirkse commented Jul 7, 2020

Hi,

I'm using ureq in a project to do ADFS authentication for AWS. The login mechanics basically work like this:

  1. GET the login page, which will set an auth-request cookie
  2. POST post credentials (along with the auth-request cookie)
  3. If the credentials are valid the server responds with a 302 to the same login page and an auth-response cookie
  4. The client then GETs the redirect URL with the auth request and response cookie, to which the server replies with an HTML page that includes a form with SAML assertion that can be used to login to AWS.

(If this sounds somewhat circuitous, it is, but that's how ADFS works.)

I was having trouble getting this to work with ureq. I'm using an Agent (for automatic cookie persistence) but the login procedure kept failing at step 4. On a hunch I used redirect(0) on the POST in step 2, extracted the cookies from the response and did the redirect request "manually" and things suddenly worked. This seems to indicate that cookies set during a request in a chain of redirects are not used in subsequent requests.

@jsha
Copy link
Collaborator

jsha commented Jul 8, 2020

Thanks for the report! It looks like cookies are only saved for the first request in a redirect chain:

save_cookies(&unit, &resp);

Will fix.

@jsha
Copy link
Collaborator

jsha commented Aug 5, 2020

An update on the above: I misread the code, and cookies are in fact saved on redirects after the first. I wrote a unittest (#127) to verify. Probably something else is going on. Are you able to share a sample of your code that triggered this problem so I can further debug?

@jsha
Copy link
Collaborator

jsha commented Aug 9, 2020

By the way, we had a bug until recently: #130. When multiple cookies were present, we would send multiple Cookie headers instead of just one. That could also explain this behavior, depending on whether multiple cookies were in use.

@nico-abram
Copy link
Contributor

Can this be closed? AIUI this is fixed, and has had no response from @mdirkse in a long time

@mdirkse
Copy link
Author

mdirkse commented Feb 15, 2021

Hi, yeah, sorry for the radio silence, the code that showed this behavior hasn't been exercised in quite some time, so I'll close it for now and if I hit it again I'll post a more thorough reproducer.

@mdirkse mdirkse closed this as completed Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants