-
Notifications
You must be signed in to change notification settings - Fork 22
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
Remove cookie doesn't seem to work in sub-sub paths like '/foo/bar' #34
Comments
Hi :) Sorry for the late response. Let me know if you've solved this already. I remember there was already an issue when someone tried to remove the cookie using the extracted one. I guess it's about the path, notice it's
If I just create a new cookie the code works: private_cookies.remove(create_cookie()); But I personally always call Cookie::make_removal just in case. I don't have time right now to investigate the issue. But if you'd like to dig into it, I'd start with trying to reproduce the bug using just underlying cookie::CookieJar to be sure the bug is belong to this crate. |
No worries!:) Haven't solved it, but great discovery about the extracted one being the issue here. I did a small test with fn test() {
use cookie::{Cookie, CookieJar};
let mut jar = CookieJar::new();
let ck = Cookie::build(("name", "gnu")).path("/").build();
jar.add(ck.clone());
let gck = jar.get("name").unwrap();
println!("{:?}\n", ck);
println!("{:?}", gck);
} this will print out this:
Which compared to the |
I may be wrong here, but I think the issue is the round trip of the cookies. When the browser sends the cookies back, it does not indicate the metadata used to set the cookie, in particular, it does not return the path. It just looks like So the extractor, which only gets to read the cookie headers, does not contain information about the path, and sets the path information to Note that path and domain default to the endpoint that sets these cookies. So, lets say you set a cookie To resolve this, the backend might need to store a copy of the cookies by name, and use these to delete, but that seems cumbersome to abstract out. Another solution could be to store the path right inside the cookie itself. For instance if the cookies are typed via serde, and can we add a field which contains the I realize that |
Seems so, thank you for the insight 🙏
Yeah, I'd like it to work with cookies set from other sources, e.g. frontend js. The realistic solution could be saving paths in separate cookies. I.e. for We could hide this solution behind a (certainly not default) feature, if you really need it. But I'd rather suggest adding a warning on deletion pitfalls and solutions to the docs. |
I noticed that removing cookies didn't work for me, and after troubleshooting I think I have identified it as being related to the paths.
When you remove cookies, the remove part just sets the
max_age
andexpired
, but ignores thepath
.This seems to work if it's just
/
or/foo
, but not if there's any more paths for some reason.Here's an example that doesn't work, based on the private/signed example,
it should create and remove the cookie every other turn, but it doesn't work.
Change the path to just
/
or/foo
and it works.I am aware i specify the path when building the cookie, but that should not break it, as that makes the
remove
"unstable".The text was updated successfully, but these errors were encountered: