diff --git a/README.md b/README.md index 75ecbc2..e47026d 100644 --- a/README.md +++ b/README.md @@ -1 +1,44 @@ -# webapp \ No newline at end of file +# Next.js with Strict Content Security Policy (CSP) + +This repository contains a Next.js application that demonstrates how to implement a strict Content Security Policy (CSP) with a nonce. This is a security feature that helps to prevent cross-site scripting (XSS) attacks by controlling which resources (scripts, styles, etc.) are allowed to be loaded by the browser. + +## How it works + +The implementation uses Next.js middleware to: + +1. **Generate a unique nonce** for each request using `crypto.randomUUID()`. +2. **Construct a strict CSP header**. This header specifies the allowed sources for various types of content. The generated nonce is included in the `script-src` and `style-src` directives. +3. **Apply the CSP header** to the response. +4. **Pass the nonce** to the frontend via a custom `x-nonce` header. + +The frontend code then retrieves the nonce from the headers and applies it to the `