Skip to content

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
merged 5 commits into from
Apr 23, 2025

Conversation

ematipico
Copy link
Member

Changes

This PR updates Astro to use the information we already have of scripts and styles to create hashes and render them in the emitted HTML page.

This PR focus only SSG for now, I will follow up with another PR to implement the same logic for SSR.

  • SSRManifest has been extended to track new information, such as hashes coming from scripts and styles. I prefer to keep them separated because we handle them differently throughout the code base.
  • SSRResult has been extended to pass the hashes during the rendering phase. As for now, these hashes are always injected. I will change that later, and inject them only for static outputs. I need to find a way to test the static output with predictable hashes.
  • ASTRO_STYLES has been moved into a separate file, so I could add a better warning about its value. The script prebuild.js has been updated to track the hash of the styles of astro islands
  • The hashes of the astro island scripts are now compiled into a TS file, and it's imported when creating the manifest (they aren't used yet)

At the moment, the hashes of scripts and styles aren't grouped by page, but I believe we can achieve that.

Testing

I created a test for SSG, where we verify that the hashes we have in the manifest are the same of the one rendered in the final HTML file.

Docs

N/A

Copy link

changeset-bot bot commented Apr 23, 2025

⚠️ No Changeset found

Latest commit: 320d9b3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Apr 23, 2025
@ematipico ematipico force-pushed the feat/csp-render-head branch from bf9697a to a80ed77 Compare April 23, 2025 11:09
@ematipico ematipico merged commit b9320db into feat/csp Apr 23, 2025
15 checks passed
@ematipico ematipico deleted the feat/csp-render-head branch April 23, 2025 12:56
ematipico added a commit that referenced this pull request Apr 23, 2025
ematipico added a commit that referenced this pull request May 1, 2025
ematipico added a commit that referenced this pull request May 14, 2025
ematipico added a commit that referenced this pull request May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants