-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add support for Integrity-Policy & SRI #15435
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
Open
willfarrell
wants to merge
9
commits into
sveltejs:main
Choose a base branch
from
willfarrell:feature/integrity-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
abd2471
feat: add support for Integrity-Policy & sri
willfarrell 28d2e2f
test: add in proper test and types
willfarrell 50c815f
Merge branch 'main' into feature/integrity-policy
willfarrell 4839b7b
test: integrate tests into shared app test
willfarrell a7c4256
Merge branch 'main' into feature/integrity-policy
willfarrell 1be59eb
Merge branch 'main' into feature/integrity-policy
willfarrell 811ac3f
revert: integrity-policy support
willfarrell 163df1a
chore: fix lint
willfarrell 2c46656
test: add in test to validate hash
willfarrell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| title: $app/integrity | ||
| --- | ||
|
|
||
| > MODULE: $app/integrity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { BROWSER } from 'esm-env'; | ||
| import { manifest } from '__sveltekit/server'; | ||
| import { initial_base } from '$app/paths/internal/server'; | ||
|
|
||
| /** | ||
| * @param {string} url | ||
| * @returns {string | undefined} | ||
| */ | ||
| function server_integrity(url) { | ||
| const integrity_map = manifest?._.client.integrity; | ||
| if (!integrity_map) return undefined; | ||
|
|
||
| // Integrity map keys are like "_app/immutable/assets/foo.abc123.js" | ||
| // URLs from ?url imports are absolute: "/_app/immutable/assets/foo.abc123.js" | ||
| // or with base: "/my-base/_app/immutable/assets/foo.abc123.js" | ||
| // | ||
| // We use initial_base (not base) because base can be overridden to a relative | ||
| // path during rendering when paths.relative is true, while ?url imports are | ||
| // always absolute. | ||
| const prefix = (initial_base || '') + '/'; | ||
| if (url.startsWith(prefix)) { | ||
| return integrity_map[url.slice(prefix.length)]; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Look up the SRI integrity hash for a Vite-processed asset URL. | ||
| * Returns the integrity string (e.g. `"sha384-..."`) during SSR, or `undefined` on the client / in dev. | ||
| * @param {string} url | ||
| * @returns {string | undefined} | ||
| */ | ||
| export function integrity(url) { | ||
| if (BROWSER) return undefined; | ||
| return server_integrity(url); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Look up the SRI integrity hash for a Vite-processed asset URL. | ||
| * Returns the integrity string (e.g. `"sha384-..."`) during SSR when | ||
| * [`subresourceIntegrity`](https://svelte.dev/docs/kit/configuration#subresourceIntegrity) is enabled, | ||
| * or `undefined` on the client and in dev. | ||
| * | ||
| * ```svelte | ||
| * <script> | ||
| * import scriptUrl from "./my-script.js?url"; | ||
| * import { integrity } from '$app/integrity'; | ||
| * </script> | ||
| * | ||
| * <svelte:head> | ||
| * <script src="{scriptUrl}" type="module" integrity={integrity(scriptUrl)} crossorigin="anonymous"></script> | ||
| * </svelte:head> | ||
| * ``` | ||
| * @param url The asset URL (e.g. from a `?url` import) | ||
| * @since 2.54.0 | ||
| */ | ||
| export function integrity(url: string): string | undefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "test-options-4", | ||
| "private": true, | ||
| "version": "0.0.1", | ||
| "scripts": { | ||
| "dev": "vite dev", | ||
| "build": "vite build", | ||
| "preview": "vite preview", | ||
| "prepare": "svelte-kit sync", | ||
| "check": "svelte-kit sync && tsc && svelte-check", | ||
| "test": "playwright test" | ||
| }, | ||
| "devDependencies": { | ||
| "@sveltejs/kit": "workspace:^", | ||
| "@sveltejs/vite-plugin-svelte": "catalog:", | ||
| "svelte": "catalog:", | ||
| "svelte-check": "catalog:", | ||
| "typescript": "^5.5.4", | ||
| "vite": "catalog:" | ||
| }, | ||
| "type": "module" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { config as default } from '../../utils.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| %sveltekit.head% | ||
| </head> | ||
| <body> | ||
| <div style="display: contents">%sveltekit.body%</div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <script> | ||
| import { setup } from '../../../../setup.js'; | ||
|
|
||
| setup(); | ||
| </script> | ||
|
|
||
| <slot /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <h1>SRI test</h1> |
7 changes: 7 additions & 0 deletions
7
packages/kit/test/apps/options-4/src/routes/styled/+page.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <h1 class="styled">Styled page</h1> | ||
|
|
||
| <style> | ||
| .styled { | ||
| color: red; | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** @type {import('@sveltejs/kit').Config} */ | ||
| const config = { | ||
| kit: { | ||
| subresourceIntegrity: 'sha384', | ||
| integrityPolicy: { | ||
| endpoints: ['default'] | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| export default config; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.