-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: document experimental netlify support
Signed-off-by: Andres Correa Casablanca <andreu@kindspells.dev>
- Loading branch information
Showing
4 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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
68 changes: 68 additions & 0 deletions
68
docs/src/content/docs/guides/security-headers/netlify-static-content.mdx
This file contains 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,68 @@ | ||
--- | ||
# SPDX-FileCopyrightText: 2024 KindSpells Labs S.L. | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
title: Configuring CSP headers for static content on Netlify | ||
description: How to configure the Content-Security-Policy headers of your static pages on Netlify with Astro-Shield | ||
--- | ||
|
||
import { Aside, Code } from '@astrojs/starlight/components'; | ||
|
||
Ensuring that Netlify serves your static content with the correct | ||
`Content-Security-Policy` headers requires some additional configuration. | ||
Specifically, set `securityHeaders.enableOnStaticPages.provider` to the value | ||
`"netlify"`. | ||
|
||
See a more complete example: | ||
|
||
<Code | ||
lang="javascript" | ||
code={` | ||
import { resolve } from 'node:path' | ||
import { defineConfig } from 'astro/config' | ||
import { shield } from '@kindspells/astro-shield' | ||
const rootDir = new URL('.', import.meta.url).pathname | ||
const modulePath = resolve(rootDir, 'src', 'generated', 'sriHashes.mjs') | ||
export default defineConfig({ | ||
integrations: [ | ||
shield({ | ||
sri: { | ||
hashesModule: modulePath, // SHOULD be set! | ||
}, | ||
// - If set, it controls how the security headers will be generated in the | ||
// middleware. | ||
// - If not set, no security headers will be generated in the middleware. | ||
securityHeaders: { | ||
// This option is required to configure CSP headers for your static | ||
// content on Netlify. | ||
enableOnStaticPages: { provider: "netlify" }, | ||
// - If set, it controls how the CSP (Content Security Policy) header will | ||
// be generated in the middleware. | ||
// - If not set, no CSP header will be configured for your static content. | ||
// (there is no need to specify its inner options) | ||
contentSecurityPolicy: { | ||
// - If set, it controls the "default" CSP directives (they can be | ||
// overriden at runtime). | ||
// - If not set, the middleware will use a minimal set of default | ||
// directives. | ||
cspDirectives: { | ||
'default-src': "'none'", | ||
} | ||
} | ||
} | ||
}) | ||
] | ||
}) | ||
`} | ||
/> | ||
|
||
<Aside type='tip'> | ||
To see how to configure CSP headers for your dynamic content, check the page | ||
[Content-Security-Policy (CSP)](/guides/security-headers/content-security-policy/). | ||
</Aside> |