-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
chore: upgrade to cookie 1.0.2 #13386
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: ef525b3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Ugh. There are type changes. I haven't looked yet whether we can deal with them internally or whether some of them will affect end-users. |
After an embarrassing number of commits, this is green now in CI, but I'm a bit worried about the effect this might have on end users. Any type changes here were something that users were already being exposed to by specifying an override of the I'm the most worried about |
I've pushed another change to remove I'm still not sure what to do about the |
Ben has opened jshttp/cookie#216 asking about this type change. It looks like a user-specified |
If we just want to filter out cookies with a decoded value of diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts
index 7f42a1318..c54ff9f98 100644
--- a/packages/kit/src/exports/public.d.ts
+++ b/packages/kit/src/exports/public.d.ts
@@ -221,9 +221,7 @@ export interface Cookies {
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
*/
- getAll: (
- opts?: import('cookie').ParseOptions
- ) => Array<{ name: string; value: string | undefined }>;
+ getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
/**
* Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
diff --git a/packages/kit/src/runtime/server/cookie.js b/packages/kit/src/runtime/server/cookie.js
index a5e4737f5..966a86046 100644
--- a/packages/kit/src/runtime/server/cookie.js
+++ b/packages/kit/src/runtime/server/cookie.js
@@ -105,7 +105,11 @@ export function get_cookies(request, url, trailing_slash) {
}
}
- return Object.entries(cookies).map(([name, value]) => ({ name, value }));
+ return /** @type {Array<{ name: string; value: string }>} */ (
+ Object.entries(cookies)
+ .filter(([, value]) => value != null)
+ .map(([name, value]) => ({ name, value }))
+ );
},
/**
diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts
index 7ab61a872..4dcdc32c5 100644
--- a/packages/kit/types/index.d.ts
+++ b/packages/kit/types/index.d.ts
@@ -203,9 +203,7 @@ declare module '@sveltejs/kit' {
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
*/
- getAll: (
- opts?: import('cookie').ParseOptions
- ) => Array<{ name: string; value: string | undefined }>;
+ getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
/**
* Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. If we go this way, I'd love suggestions about how to convince TS that this array really won't have any objects with |
If this is the blocker for 0.7 I'm happy to back port the validation change in 1.x to 0.x. 1.0 mostly contains performance improvements and cleanup of responsibilities in the code. It won't allow everything it used to, but should be much closer than today. |
Not sure if we need to do anything or can accept the risk of breaking, but I wanted to leave a comment for reference at least. I've been comparing the validation and it does appear to tighten it still compared to 0.6 If I've read the code correctly, things like the tab character, line feed, semi-colon, and equals are no longer allowed with this upgrade along with everything under "Latin-1 Supplement" on https://en.wikipedia.org/wiki/List_of_Unicode_characters. I don't know how many users might have used something like |
I've confirmed that @blakeembrey thanks for the offer to loosen the validation in 0.7. Do you think that we could change it to accept characters like |
Honestly, without a better expert opinion on this I wouldn't want to. That said, I'm 90% sure there's no support for sending non-ASCII characters in HTTP headers so it should be a non-issue. Related: RFC 2047 on encoding, RFC encoding the Link header, RFC on encoding in auth. TL;DR is they always convert into ASCII. Cookie doesn't encode names so relies on the application having done it. |
I'd expect |
Cookie names are not altered. Values are, and the validation occurs after encoding. I didn’t alter any behavior in the 1.0 release that may have unexpectedly changed how cookies are written or read to ensure a smoother upgrade. Update: Took a quick look into whether it’s worth adding cookie names encoding and saw dotnet/aspnetcore#23578, so it would need more thought. |
Can you confirm that this flows via the network from a server to the browser and back from a browser to a server correctly? As far as I can see, this is the entire concern with non-ASCII chars in cookie names. |
@benmccann Have you confirmed whether it's the dev tools URL-decoding the values for you when displaying them for convenience? If you 'copy as curl', what are the actual header values? |
https://stackoverflow.com/a/1969339 tells us that this is browser specific behaviour:
|
https://bugzilla.redhat.com/show_bug.cgi?id=2316549 This is the bug everyone seems to be complaining about which is exactly "Bug 2316549 (CVE-2024-47764) - CVE-2024-47764 cookie: cookie accepts cookie name, path, and domain with out of bounds characters:" |
We've regularly had comments/issues from people about a security vulnerability reported in [email protected], but we've been unable to upgrade because of later versions of the library having stricter validation. It sounds like these restrictions get loosened in 1.0.2 - jshttp/cookie#210 - and so I'm hopeful we can do this upgrade after all. If it turns out that there are still people who are affected by this, we can decide then whether we want to report this upstream to the cookie library or whether we want to deal with this in some other way.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits