Skip to content

feat: experimental CSP docs #11736

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
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: experimental CSP docs #11736

wants to merge 5 commits into from

Conversation

ematipico
Copy link
Member

Description (required)

This PR adds a new page under the experimental section that documents the upcoming CSP support.

For Astro version: 5.9.0. See astro PR #13802.

I leave here the link to RFC too: https://github.com/withastro/roadmap/blob/feat/rfc-csp/proposals/0055-csp.md

Copy link

netlify bot commented May 21, 2025

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit aaf949c
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/68384d6d9f38e600080cfe19
😎 Deploy Preview https://deploy-preview-11736--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@astrobot-houston
Copy link
Contributor

astrobot-houston commented May 21, 2025

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/reference/experimental-flags/csp.mdx Localization added, will be marked as complete.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@ematipico ematipico added the add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. label May 21, 2025
@ematipico ematipico added this to the 5.9.0 milestone May 21, 2025
@ematipico ematipico self-assigned this May 21, 2025
@sarah11918 sarah11918 added the merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) label May 21, 2025
@zaitovalisher
Copy link

zaitovalisher commented May 27, 2025

That's huge, cool and elegant solution that covers 90% of my needs. Great job @ematipico!

I will use your solution for google analytics, comments and styles. And Zaraz for the rest (which is ad placement, cause those are added on top of a built website and need nonces).

@sarah11918 sarah11918 added the minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah! label May 28, 2025

Enables support for [Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) to help minimize certain types of security threats by controlling which resources a document is allowed to load. This provides additional protection against [cross-site scripting (XSS)](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting) attacks.

Enabling this feature adds additional security to Astro's handling of processed and bundled scripts and styles by default, and is further configurable for more control over these, and additional, content types.
Copy link
Member Author

Choose a reason for hiding this comment

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

This feature doesn't support things like inline scripts, so I wonder if this phrase is clear enough to tell the user that this feature doesn't cover them

<Since v="5.9.0" />
</p>

A list of valid sources for the `script-src` and `style-src` directives.
Copy link
Member Author

Choose a reason for hiding this comment

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

If possible, I would like to keep the word "resources" because that's how MDN calls them

Copy link
Member

@sarah11918 sarah11918 May 29, 2025

Choose a reason for hiding this comment

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

Suggested change
A list of valid sources for the `script-src` and `style-src` directives.
A list of valid resources for the `script-src` and `style-src` directives.

We can do this! But I did check that MDN does define a resource as a "valid source" which is why I used it -- the only thing I was trying to avoid here was an "unhelpful" definition, like "Resources are resources" (Ideally, we don't define something with the EXACT same word.) But, it's true that our resources property is a list of resources, and we'll review all these docs again when they become stable, so we'll see if these have worked fine as is!

Are there any uses of the word "source" in the rest of this section that you think should be changed to "resource"?

Copy link
Member Author

@ematipico ematipico May 29, 2025

Choose a reason for hiding this comment

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

resource as a "valid source"

I must have missed that. No worries, it's just a nit. As long as users understand that, I'm fine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants