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

getStoredCookies can behave unexpectedly #98

Open
0xpr03 opened this issue Jan 7, 2024 · 0 comments
Open

getStoredCookies can behave unexpectedly #98

0xpr03 opened this issue Jan 7, 2024 · 0 comments

Comments

@0xpr03
Copy link

0xpr03 commented Jan 7, 2024

Describe the bug

Requests.getStoredCookies has no clear definition what to pass as URL if you want to retrieve the cookie returned from a request you just made.

To Reproduce
Steps to reproduce the behavior:

final url = "http://127.0.0.1:4563/api/login";
final loginResult = await Requests.post(url,
        body: {"email": _username, "password": _password},
        bodyEncoding: RequestBodyEncoding.JSON,
        persistCookies: true);
CookieJar cookies = await Requests.getStoredCookies(url);
// print!(cookies); inspect cookies somehow..

Will return nothing if the cookie returned from this request is defined as

"set-cookie" -> "API_SESSION=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX; HttpOnly; SameSite=Lax; Path=/api; Max-Age=25199"

What you have to do, after reading the code:

//..[post]
var uri = Uri.parse(url);
CookieJar cookies = await Requests.getStoredCookies(uri.host);

But this is brittle. The main branch already changed for that part, so the actual key I have to use for getStoredCookies is not actually stable.

Hostname makes sense at first, but if the cookie is restricted to a Path, like in this case, it gets confusing fast.
Additionally it might be nice to instead provide a way to retrieve cookies obtained by the request directly.

This whole procedure is required if you want to extract cookies for later use.

Expected behavior
Cookie is returned.

Desktop (please complete the following information):

  • OS: W10
  • requests 4.7.0
  • flutter 3.16.3
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

1 participant