Skip to content

feat: implement skew protection - #11987

Merged
Rich-Harris merged 14 commits into
mainfrom
skew-protection
Mar 19, 2024
Merged

Rich-Harris merged 14 commits into
mainfrom
skew-protection

Conversation

@Rich-Harris

@Rich-Harris Rich-Harris commented Mar 15, 2024 •

Copy link
Copy Markdown
Member

closes #10947

This implements Vercel Skew Protection. Tested manually


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot

changeset-bot Bot commented Mar 15, 2024 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d9bb954

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-vercel Minor

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

Comment thread packages/adapter-vercel/index.js Resolved
@leerob

leerob commented Mar 15, 2024

Copy link
Copy Markdown
Contributor

Woohoo! Thank you for implementing this 🥳

Comment thread .changeset/slow-drinks-burn.md Resolved
Comment thread packages/adapter-vercel/files/edge.js Resolved
Comment thread packages/adapter-vercel/index.js Outdated
value: 'document'
},
headers: {
'Set-Cookie': `__vdpl=${process.env.VERCEL_DEPLOYMENT_ID}; Path=/${builder.config.kit.paths.base}; SameSite=Strict; Secure; HttpOnly`

@dummdidumm dummdidumm Mar 15, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously you deleted the cookie for the version.json route - is that not necessary after all? Not necessary because it's not a document request?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct — we only care about non-document requests for this file. AFAICT there's no way to set multiple cookies (you can't do set-cookie: [...], and if you add a header in multiple continue routes the last one wins), so we had to get rid of it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, no, hang on... this is a problem — the version.json will be requested with the old deployment ID. gah

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this seemed to work in my testing, because the cookie was still in my browser from the earlier iteration 🤦 )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've 'fixed' this by setting the second set-cookie header on the response for the entry point, since we know it will happen before the client hydrates. Since adapters don't have access to the build manifest, this involves some hackery, but hopefully we can remove it in future once the Build Output API supports setting multiple set-cookie headers in a single response.

@Rich-Harris
Rich-Harris marked this pull request as ready for review March 19, 2024 13:33
@Rich-Harris
Rich-Harris merged commit af5a257 into main Mar 19, 2024
@Rich-Harris
Rich-Harris deleted the skew-protection branch March 19, 2024 13:52
@github-actions github-actions Bot mentioned this pull request Mar 18, 2024
@danielroe danielroe mentioned this pull request Mar 25, 2024
1 task done
teemingc pushed a commit that referenced this pull request Nov 12, 2026
Fixes #17730

Skew Protection currently scans `immutable/entry` for `start.*` to
attach the cookie that exempts `version.json` from deployment pinning.
Single bundles have no such directory, so adaptation fails after the
client/server builds succeed. Inline bundles likewise have no external
entry request.

The separate-response workaround introduced in
#11987 was necessary because the
legacy route headers map could not express multiple cookies. Vercel's
current [Build Output
API](https://vercel.com/docs/build-output-api/configuration#routes)
supports appending response headers with multiple values, and the
adapter already uses routing transforms.

This removes the obsolete entry scan and appends both independent
`Set-Cookie` values on the existing document route. The deployment
cookie and the more-specific empty version cookie retain their scopes
and security attributes; the exemption is now installed on the HTML
response rather than a later JavaScript response. Branching the scan for
each bundle strategy would retain unnecessary dependence on output
filenames and entry requests, especially since inline output files are
removed by #16025.

This covers split, single, and inline output, SSR and prerendered
documents, and custom `paths.base`/`appDir`, without changing ISR
dispatch, immutable caching, filesystem routing, or missing-asset
handling.

- [Ported reproduction using the reported
versions](https://www.sveltelab.dev/#code=N4IgdA5glgLlEDsD2AnApiAXKAZlANhtiAMZIIxoUDOWIyAJmgPoC2SDArodQDoL8AxAAIA8pxgAHCfzBIJ0mLIBuaFCTT5ZCNDHxQcAT1kB3FAEMEEQin4B6MNVX5KAWgDWsewCNOBBvxCYgDKsgAiwczBMKho-AAqABacrN7UYAzegQgiAKIIyrJUhQhgxWAAVPwAhGUFZQAe5qyShDV1ymCU1EoCOcIAarBxBcNgZAh4EGAAVulwrGg9zZKuVaOU4%2BRTXfNQi8sta-wgAL6nADQg1OpYoAxQ6CQxKIZ3IOaSkmCJMKz47zwhHeE0oNDoAB5qgwkM9DJI0MJfv8AHz8CHI-DCfCWCAAXl4ICohLRAhgGLQ5gYpN4SnJixg5mEJES5hQ1F0BJAEhwrgAHIThHYaXSIQymQhmmgucooGgTJJUEoQMzyGCYFyTFAGDBEnimLKNK4tTrEhdhFAELAoOZ8K5qCRbdKAIyC4WBUXi4SSxZcygNGD2x1tFWgqgawkOp1ukW0gCkTk0lE8MB%2BlIYcY9ELsiXTIoh3g4hmEDHMjPtzmTsFcknQ%2BCQVNcpcZXMSSFUthAsfJD2Uwh6hkIXIe1Fa5kMmFVFHDfC7CcraBTYELDEMcezvfzdhXhlJ2cxpLOlxAKHk3XeDyeLzexAA1JJzBA0I4F4CCERQGHwZgQBjnSiAHVNDIRZhBiYRggXABpWB93-dFJBRIZqFgYQISZRJ0BwVsYCkahMDsOxExcZ8DTsGESGoOwUxJYjNjIiiqJTbNzBRMCkGEdAqTA3MS1hFJwzLKByGzRCTnOK5bxxQwzxfJMPxAIEFK-GBaB-CEHRQKBJBgbFcT9WcRUIXTgGZRJ-HQBBhFOYQ8WEAASWskEkagAAoAEoAG50SIkgtJ0mkEGAAABSymBQMyLKoDzTnE854quMAEEkVhbmIJSQTVGc6CoaAdHtGAtOePFCs4EYjyuB8SHcR9nzmcg32BYgVLUkBgA9QkfTiLBhEJFNXGdAB2QaAGYAAZCQuDqQA7FDyEJSdCTGsBltdEAprJQlaygZQy26ydSrQDbaUJGB4X23qQHYLgQ2O5VNO01SFuEdrNuVA1nsJWVKBLNBCnWjrlV8fxPpAAZcgAJQAYVyAAZKIoNyADmAABQh0R4lyKH4gASVEAA5ZhcnxgBBAAhWHcjCPFnUGSGYfhsJchR2HRAATQAWWJ%2BJmBx6mGFaZh0Cc4RvsRYH8ACAG3q29BZXlUGxeEWs-rlExJsB2W0AfdBQbotAPFQ6hDAQEhCQ9S5poNMJtaoJhTblWdJ1ek7lWC-W5jsKlPkoFBXA7DQtB6wkAFYwAATjANa7pOkB3YXT2aODkAACYwBG50o41mW449qixZrfBODyit5NBsPM%2BjzXrgXcv075Fbs9d07zoenS68jlOm7pL7hlBgA2dOwBD82yVihBx4qmaxgmHZVMa5Ssu-EB9kVFATP7BcU2s4QcFPVhhAAcnj%2BTE9gOwxcP7yrRaJUXt%2BvAdCh7Z4B3vekAPw-L%2Bv-g0AaNfdJMBwOYbggC0CPzQM-SY8BXKmVaMXS0%2BFhAAG19Ypg8gAXWsl5OKVx9ZbGgdMOYC9MrTmXqvO%2B3sdJqF3vvI%2BJ8SKeyob7f2ahA5X2yH-ABD8QEuBeh6FMztAbMLUJOERKAPIxxiAoCQzthC%2BAQAwQg0QLCUAgBOI%2BKErCEEPtZC2-BTjXynqpWe8BZjUAauld8pD1StRdsqP%2BYIGBO0umABw%2BtDYwDsCYl%2BRCLECGlrHECkh3woFEDpYSCAXGmUjIVKAzxnqHT0RPOKpwgA)

<!--
svelte-triage-bot:feedback-baseline:1b737b13847ffb736fce6d2d743115473b9b1dfe
-->

---------

Co-authored-by: svelte-triage-bot <[email protected]>

This branch was successfully deployed

2 active deployments
Preview – kit-svelte-dev — d9bb9544 Deployed Mar 19, 2024 by vercel[bot]
Preview – kit-default-template — d9bb9544 Deployed Mar 19, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:adapter-vercel Pertaining to the Vercel adapter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Vercel's skew protection

7 participants