-
-
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
feat: validate values for cache-control
and content-type
headers in dev mode
#13114
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 4f7c4b9 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 |
preview: https://svelte-dev-git-preview-kit-13114-svelte.vercel.app/ this is an automated message |
72f42fd
to
e651a53
Compare
cache-control
and content-type
headers in dev mode
e651a53
to
adc6077
Compare
'cache-control': (value) => { | ||
const directives = value | ||
.split(',') | ||
.map((directive) => directive.trim().split('=')[0].toLowerCase()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map((directive) => directive.trim().split('=')[0].toLowerCase()); | |
.map((directive) => directive.trim().split('=').at(0)?.toLowerCase()); |
Is it possible for the string to end up with an empty entry after splitting on ','
? Like cache-control: stale-while-revalidate,,no-transform
or something? Obviously that's still wrong, but hopefully we'd catch that and show an error, not throw a hard-to-debug runtime error 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a good point! I've introduced an additional check to catch the empty directives.
|
||
beforeAll(() => { | ||
console_warn = console.warn; | ||
// @ts-expect-error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here, I think you can add a global declaration to the top and avoid using globalThis
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found success in the other declarations, but I didn't have much luck silencing it here, despite trying a couple of things 🤔.
adc6077
to
838fd8b
Compare
]); | ||
|
||
const CONTENT_TYPE_PATTERN = | ||
/^(application|audio|font|image|model|text|video|x-[a-z]+)\/[-+.\w]+$/i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/^(application|audio|font|image|model|text|video|x-[a-z]+)\/[-+.\w]+$/i; | |
/^(application|audio|font|image|model|text|video|x-[a-z]+)\/[-+.\w]+$/i; |
The IANA spec defines the following top-level types, some of which are not included here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Updated to reflect this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move this to the test-dev-only
package -- that package only runs dev tests, which means you don't need to fake the globalThis.__SVELTEKIT_DEV__
thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shifted!
838fd8b
to
4f7c4b9
Compare
Fix for #12784
Adds validation for common HTTP headers in dev mode to help catch invalid values early:
run
pnpm dev
fromtest/apps/basics
and navigate to http://localhost:5173/headers/invalid. In your console you'll see: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