Skip to content

Commit 5d9b34b

Browse files
Copilothotlong
andcommitted
docs: Fix CSP security config and add missing meta.json files
- Remove unsafe-inline from CSP examples, use nonce/hash-based approach - Add meta.json for docs/guide/cli/ subdirectory - Add meta.json for docs/ecosystem/deployment/ subdirectory - Fixes Fumadocs build by ensuring all subdirectories have proper navigation Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent fa0e6b7 commit 5d9b34b

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"title": "Deployment",
3+
"pages": [
4+
"showcase-deployment"
5+
]
6+
}

docs/guide/cli/meta.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"title": "CLI",
3+
"pages": [
4+
"getting-started",
5+
"runtime-reference"
6+
]
7+
}

docs/security.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,26 +314,48 @@ Implement CSP headers:
314314

315315
```html
316316
<!-- In your HTML or via HTTP headers -->
317+
<!-- Use nonce-based CSP for inline scripts/styles -->
317318
<meta http-equiv="Content-Security-Policy"
318319
content="default-src 'self';
319-
script-src 'self' 'unsafe-inline';
320-
style-src 'self' 'unsafe-inline';
320+
script-src 'self' 'nonce-{random-nonce}';
321+
style-src 'self' 'nonce-{random-nonce}';
321322
img-src 'self' data: https:;
322323
font-src 'self' data:;">
323324
```
324325

325-
Or via HTTP header:
326+
Or via HTTP header with nonce:
326327
```javascript
327-
// Express
328+
// Express - Generate a unique nonce per request
328329
app.use((req, res, next) => {
330+
const nonce = crypto.randomBytes(16).toString('base64');
331+
res.locals.nonce = nonce;
329332
res.setHeader(
330333
'Content-Security-Policy',
331-
"default-src 'self'; script-src 'self' 'unsafe-inline'"
334+
`default-src 'self'; script-src 'self' 'nonce-${nonce}'; style-src 'self' 'nonce-${nonce}'`
332335
);
333336
next();
334337
});
338+
339+
// Then use the nonce in your inline scripts/styles:
340+
// <script nonce="${nonce}">...</script>
341+
// <style nonce="${nonce}">...</style>
335342
```
336343

344+
**Alternative: Hash-based CSP** (for static inline content):
345+
```javascript
346+
// Calculate hash of your inline script/style
347+
// Then include in CSP
348+
app.use((req, res, next) => {
349+
res.setHeader(
350+
'Content-Security-Policy',
351+
"default-src 'self'; script-src 'self' 'sha256-{hash-of-script}'; style-src 'self'"
352+
);
353+
next();
354+
});
355+
```
356+
357+
**Note**: Avoid using `'unsafe-inline'` as it significantly weakens XSS protection. Use nonces or hashes instead.
358+
337359
## Dependency Security
338360

339361
### Regular Updates

0 commit comments

Comments
 (0)