diff --git a/docs/examples/index.md b/docs/examples/index.md index b560c7e5..5e78cd82 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -20,3 +20,4 @@ like to see here, please open - [Rendering markdown](./examples/rendering-markdown) - [Sharing state between islands](./examples/sharing-state-between-islands) - [Using Deno KV Oauth](./examples/using-deno-kv-oauth) +- [Using CSP](./examples/using-csp) diff --git a/docs/examples/using-csp.md b/docs/examples/using-csp.md new file mode 100644 index 00000000..07d2545e --- /dev/null +++ b/docs/examples/using-csp.md @@ -0,0 +1,383 @@ +--- +description: | + Change the source directory to effectively manage your project. +--- + +As per the +[MDN documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP): + +> Content Security Policy (CSP) is an added layer of security that helps to +> detect and mitigate certain types of attacks, including Cross-Site Scripting +> (XSS) and data injection attacks. These attacks are used for everything from +> data theft, to site defacement, to malware distribution. +> +> To enable CSP, you need to configure your web server to return the +> Content-Security-Policy HTTP header. (Sometimes you may see mentions of the +> X-Content-Security-Policy header, but that's an older version and you don't +> need to specify it anymore.) + +Fortunately Fresh has built in support for CSP. We don't need to worry about +setting headers ourselves. We just have to configure our routes correctly. Let's +dive into a few examples to see how this works. + +Fresh's CSP implementation supports the following + +
+directives + +```ts +export interface ContentSecurityPolicyDirectives { + // Fetch directives + /** + * Defines the valid sources for web workers and nested browsing contexts + * loaded using elements such as and