-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(csp): create hashes of tracked scripts and hashes #13675
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
Merged
Parent:
feat: experimental CSP
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
5 changes: 3 additions & 2 deletions
5
packages/astro/src/core/csp-hashes.js → ...es/astro/src/core/astro-islands-hashes.ts
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 |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| // This file is code-generated, please don't change it manually | ||
| export default [ | ||
| export const ASTRO_ISLAND_HASHES = [ | ||
| "GI/D8grziRZwfj/Mqmn+dcgU/i8sylHSR/IfobqcUT4=", | ||
| "HDWxd14AUw8OvjrhhRRyyZFHCGnzxXGDrg59Qi8ayhc=", | ||
| "XN6a2Vn8uvpBr/WhdYPdK0jVeCzlcOD2XYaP10veV4Y=", | ||
| "ZR0ZAU8UNTzLmo/ApeWH0y1mVLT+XtFkvZ5nw32W8jI=", | ||
| "cSNmhdbFlyTDRozeu9HPjo+B2S4QAeMp0RO41PqgAcA=", | ||
| "mH3H4wSoDVWMXJKrmeBKYJQMdAZQ3dArB2N66JomkzI=", | ||
| "mH3H4wSoDVWMXJKrmeBKYJQMdAZQ3dArB2N66JomkzI=" | ||
| "mH3H4wSoDVWMXJKrmeBKYJQMdAZQ3dArB2N66JomkzI=", | ||
| "s81ZcLcyAa7P/Jh5M5hUxYthTGwW+iZY3e6aHrQ8H9E=" | ||
| ]; |
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,40 @@ | ||
| import type { AstroConfig } from '../../types/public/index.js'; | ||
| import type { BuildInternals } from '../build/internal.js'; | ||
| import crypto from 'node:crypto'; | ||
| import type { AstroSettings } from '../../types/astro.js'; | ||
|
|
||
| export function shouldTrackCspHashes(config: AstroConfig): boolean { | ||
| return config.experimental?.csp === true; | ||
| } | ||
|
|
||
| export function trackStyleHashes(internals: BuildInternals): string[] { | ||
| const clientStyleHashes: string[] = []; | ||
| for (const [_, page] of internals.pagesByViteID.entries()) { | ||
| for (const style of page.styles) { | ||
| if (style.sheet.type === 'inline') { | ||
| clientStyleHashes.push( | ||
| crypto.createHash('sha256').update(style.sheet.content).digest('base64'), | ||
ematipico marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return clientStyleHashes; | ||
| } | ||
|
|
||
| export function trackScriptHashes(internals: BuildInternals, settings: AstroSettings): string[] { | ||
| const clientScriptHashes: string[] = []; | ||
|
|
||
| for (const script of internals.inlinedScripts.values()) { | ||
| clientScriptHashes.push(crypto.createHash('sha256').update(script).digest('base64')); | ||
| } | ||
|
|
||
| for (const script of settings.scripts) { | ||
| const { content, stage } = script; | ||
| if (stage === 'head-inline' || stage === 'before-hydration') { | ||
| clientScriptHashes.push(crypto.createHash('sha256').update(content).digest('base64')); | ||
| } | ||
| } | ||
|
|
||
| return clientScriptHashes; | ||
| } | ||
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,2 @@ | ||
| // NOTE: if you change the value inside the style tag, you must update `prebuild.js` too | ||
ematipico marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export const ISLAND_STYLES = `<style>astro-island,astro-slot,astro-static-slot{display:contents}</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
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
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.