From 60404a5004077dcef2e73bc5ae3f0c5b03744175 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sat, 29 Nov 2025 18:46:11 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 12 + README.md | 3 + plugin.lock.json | 45 +++ skills/csp-config-generator/SKILL.md | 563 +++++++++++++++++++++++++++ 4 files changed, 623 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 plugin.lock.json create mode 100644 skills/csp-config-generator/SKILL.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..b503b4f --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,12 @@ +{ + "name": "csp-config-generator", + "description": "This skill should be used when the user requests to generate, create, or configure Content Security Policy (CSP) headers for Next.js applications to prevent XSS attacks and control resource loading. It analyzes the application to determine appropriate CSP directives and generates configuration via next.config or middleware. Trigger terms include CSP, Content Security Policy, security headers, XSS protection, generate CSP, configure CSP, strict CSP, nonce-based CSP, CSP directives.", + "version": "1.0.0", + "author": { + "name": "Hope Overture", + "email": "support@worldbuilding-app-skills.dev" + }, + "skills": [ + "./skills" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..58dc042 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# csp-config-generator + +This skill should be used when the user requests to generate, create, or configure Content Security Policy (CSP) headers for Next.js applications to prevent XSS attacks and control resource loading. It analyzes the application to determine appropriate CSP directives and generates configuration via next.config or middleware. Trigger terms include CSP, Content Security Policy, security headers, XSS protection, generate CSP, configure CSP, strict CSP, nonce-based CSP, CSP directives. diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..6fe1880 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,45 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:hopeoverture/worldbuilding-app-skills:plugins/csp-config-generator", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "7d65a094e04b39d25ef527f7a32f28a30999e4dd", + "treeHash": "d541a24428de978c0c4de7b2c2fde5491b74547c1d7a84e6451ac03b66e1a95b", + "generatedAt": "2025-11-28T10:17:31.644155Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "csp-config-generator", + "description": "This skill should be used when the user requests to generate, create, or configure Content Security Policy (CSP) headers for Next.js applications to prevent XSS attacks and control resource loading. It analyzes the application to determine appropriate CSP directives and generates configuration via next.config or middleware. Trigger terms include CSP, Content Security Policy, security headers, XSS protection, generate CSP, configure CSP, strict CSP, nonce-based CSP, CSP directives.", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "ad51c443d5c834dcf482f025263d61095892a9b6d29a9c6ba2e79e7106b56e8f" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "a67ff981a04979a34c05534b5d2d9d431436e88f09df114f6b00a72774b0741a" + }, + { + "path": "skills/csp-config-generator/SKILL.md", + "sha256": "797e3d03030eef2a1a75bc32c8c0fd15df6098f2835950fba434a4049b0a8456" + } + ], + "dirSha256": "d541a24428de978c0c4de7b2c2fde5491b74547c1d7a84e6451ac03b66e1a95b" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/csp-config-generator/SKILL.md b/skills/csp-config-generator/SKILL.md new file mode 100644 index 0000000..0415c72 --- /dev/null +++ b/skills/csp-config-generator/SKILL.md @@ -0,0 +1,563 @@ +--- +name: csp-config-generator +description: This skill should be used when the user requests to generate, create, or configure Content Security Policy (CSP) headers for Next.js applications to prevent XSS attacks and control resource loading. It analyzes the application to determine appropriate CSP directives and generates configuration via next.config or middleware. Trigger terms include CSP, Content Security Policy, security headers, XSS protection, generate CSP, configure CSP, strict CSP, nonce-based CSP, CSP directives. +--- + +# CSP Config Generator + +To generate a strict Content Security Policy configuration for Next.js applications, follow these steps systematically. + +## Step 1: Analyze Application Resources + +Identify all resource types used in the application. + +### Discover External Resources + +Use Grep to find external resource references: + +**Scripts**: +``` +- " `${name} ${values.join(' ')}`) + .join('; ') +} + +export const config = { + matcher: [ + { + source: '/((?!api|_next/static|_next/image|favicon.ico).*)', + missing: [ + { type: 'header', key: 'next-router-prefetch' }, + { type: 'header', key: 'purpose', value: 'prefetch' }, + ], + }, + ], +} +``` + +### Update Root Layout with Nonce + +```typescript +// app/layout.tsx +import { getNonce } from '@/lib/csp/nonce' + +export default function RootLayout({ + children, +}: { + children: React.ReactNode +}) { + const nonce = getNonce() + + return ( + + + {/* Head content will use nonce */} + + {children} + + ) +} +``` + +### Update Script Tags + +```typescript +// Use Next.js Script component with nonce +import Script from 'next/script' +import { getNonce } from '@/lib/csp/nonce' + +export function AnalyticsScript() { + const nonce = getNonce() + + return ( +