-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make path
a required option when setting/deleting cookies
#9299
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
Comments
Still not sure this is the right move. None of the other metaframeworks do this AFAIK, and the "default path" logic works without bugs now. If we were to introduce this, it means that people need to stringify the path they're currently on, and when it's not |
What about defaulting the path to |
It probably is, but changing it now feels too risky - people could rely on the current behavior (more scoped cookies) and upgrade, not reading the changelog carefully, introducing a security hole. |
We decided to do this with a convenience shortcut for the current default behavior, something like |
Trying to figure out how to indicate 'use the default kit/packages/kit/src/runtime/server/cookie.js Lines 27 to 28 in 6818dd4
...matches RFC 6265, but neither normalized_url = '/foo/bar';
normalized_url.split('/').slice(0, -1).join('/') || '/'; // "/foo"
new URL('', 'https://example.com/foo/bar').pathname; // "/foo/bar"
new URL('.', 'https://example.com/foo/bar').pathname; // "/foo/"
new URL('..', 'https://example.com/foo/bar').pathname; // "/" Having said that, I'm not sure the default behaviour is particularly useful. I think it's probably fine to just say 'you have to specify |
What would it mean specifying a relative path? Relative to the current location, so that |
I would agree. I don't really understand the discussion around default
I think it's probably fine to say you have to specify the path. I think that the user can specify
That could be okay, but I'd be careful to think through, test, and maybe document edge cases with trailing slashes. I know people have gotten tripped up on the browser when relative paths behave differently for things like |
Re "discussion about default path behavior": the idea was to provide a shortcut so that people get the same cookie path they would get today when omitting the path, like "pass in |
Yeah, I just don't get why today's behavior ever existed |
We're not talking about a browser API at all, we're talking about whether — in a world where we require you to provide a My vote is 'no', because the default browser behaviour seems dumb.
Specifying Trailing slashes work exactly as you'd expect: new URL('', 'https://example.com/foo/').pathname; // '/foo/'
new URL('.', 'https://example.com/foo/').pathname; // '/foo/'
new URL('..', 'https://example.com/foo/').pathname; // '/'
new URL('', 'https://example.com/foo/bar').pathname; // '/foo/bar'
new URL('.', 'https://example.com/foo/bar').pathname; // '/foo/'
new URL('..', 'https://example.com/foo/bar').pathname; // '/' |
Because it's what the browser does if you don't set a path |
(One thing to note: our |
One thing that speaks for having some string reserved for the current "omit path" behavior is that we can automigrate the user's code |
Feels a bit tail-wagging-the-dog |
Yeah, I'd not make an effort to keep the current behavior. It's better to make the user do some work to migrate so that we all have nicer APIs |
But what if you do want the current default behavior? Sounds weird to not have an ergonomic option for that. Absolute paths are prone to get out of sync |
You can just use If we really want to support the old behavior I suppose we could introduce an additional shortcut such as |
The default behaviour isn't hard to implement yourself if you really need it. The question is, why would you ever need it? What's a scenario in which it's helpful? |
Ok asked differently: If I'm on |
I just saw #11237 was merged. One suggestion on that - I think we should add the relative path support in 1.x. Otherwise it's weird to deprecate the old behavior, but not yet have available the new functionality that we want users to migrate to |
If we're worried about things getting out of date (or handling use cases like translated routes) then we should probably just build tools to accommodate those scenarios (like
It's already supported, except for |
I suppose the other way to tackle this is to make |
Oh actually there is one caveat here — it's support insofar as the cookie path will be correct in the browser, but |
I agree making |
I just checked this again and setting the path to |
IMO, this is the wrong move. Also, this breaks compatibility with every other meta-framework (including Astro, Next.js, and Unjs/Nuxt), as well as the popular |
I'll be honest, I'm very surprised at the number of 👍 reactions here. It would be useful to know how many of those are because of the compatibility-with-other-frameworks thing, and how many are because people genuinely want the confusing default behaviour. (Sound off if you're one of the 21 — so far — people who reacted!) Doing the default-HTTP-spec thing is good in the absence of an alternative, but when relying on the default behaviour is a frequent source of confusion and bugs, it's the framework's job to push people towards more reliable outcomes. I'm sympathetic to the cross-framework issue! But I'm not sure it should be decisive — if anything, I'd love to see other frameworks (and libraries that support them) adopt the same constraint. I do think it's better for users in the long run. |
I just don't think it's the right place to put it. From the API/types, I'd expect it to work exactly like how HTTP cookies would. |
Which perfectly encapsulates why we made this change — omitting And we already deviated from those defaults — we default I strongly encourage you to consider this question from the opposite angle — rather than asking SvelteKit to undo a necessary change to facilitate compatibility with cross-framework libraries, what if cross-framework libraries made |
Sorry I meant to say path directory there. Anyway, I guess it's just different design philosophy. I value standardized API that's consistent with the spec over potentially safer API, and I don't want/expect the framework to do everything for me. Even if other frameworks change their API, we still have a fractured ecosystem right now - and IMO for very little reason. |
it was linked from pilcrow's twitter, which has thousands of followers: https://twitter.com/pilcrowonpaper/status/1735468834843418738. |
Describe the problem
See discussion in #9130. I'm not sure there's ever a good reason not to specify a
path
— it's almost always an annoying mistake, that we may or may not catch in time.Describe the proposed solution
Make
path
required.Alternatives considered
No response
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: