[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6D82C937XR4D078S7N045JQ":3,"skill-same:01M6D82C937XR4D078S7N045JQ":89},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":31,"linkOnly":32,"markdownContent":33,"markdownBody":34,"frontMatter":35,"refName":36,"commitSha":37,"skillDirectory":38,"forksCount":39,"repositoryHtmlUrl":40,"repositoryHomepageUrl":6,"ownerHtmlUrl":41,"ownerBlogUrl":42,"ownerDescription":43,"updatedAt":44,"install":45,"resources":58},"01M6D82C937XR4D078S7N045JQ","security-review",null,"Use this skill when adding authentication, handling user input, working with secrets, creating API endpoints, or implementing payment\u002Fsensitive features. Provides comprehensive security checklist and patterns.","oabdelmaksoud\u002FSuperClaw","oabdelmaksoud","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F50699149?v=4","01M6D5CVVN778ZCDP1WHS816SP","Omar Abdelmaksoud","01M6D5CW1RHNSKCJR85GJACBFT",2,"MIT","https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fsecurity-review\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30],"review","security","security review","authentication","api","secrets","user","use","endpoints","checklist","patterns","payment","2026-11-10 10:12:30",false,"---\nname: security-review\ndescription: Use this skill when adding authentication, handling user input, working with secrets, creating API endpoints, or implementing payment\u002Fsensitive features. Provides comprehensive security checklist and patterns.\n---\n\n# 安全性審查技能\n\n此技能確保所有程式碼遵循安全性最佳實務並識別潛在漏洞。\n\n## 何時啟用\n\n- 實作認證或授權\n- 處理使用者輸入或檔案上傳\n- 建立新的 API 端點\n- 處理密鑰或憑證\n- 實作支付功能\n- 儲存或傳輸敏感資料\n- 整合第三方 API\n\n## 安全性檢查清單\n\n### 1. 密鑰管理\n\n#### ❌ 絕不這樣做\n```typescript\nconst apiKey = \"sk-proj-xxxxx\"  \u002F\u002F 寫死的密鑰\nconst dbPassword = \"password123\" \u002F\u002F 在原始碼中\n```\n\n#### ✅ 總是這樣做\n```typescript\nconst apiKey = process.env.OPENAI_API_KEY\nconst dbUrl = process.env.DATABASE_URL\n\n\u002F\u002F 驗證密鑰存在\nif (!apiKey) {\n  throw new Error('OPENAI_API_KEY not configured')\n}\n```\n\n#### 驗證步驟\n- [ ] 無寫死的 API 金鑰、Token 或密碼\n- [ ] 所有密鑰在環境變數中\n- [ ] `.env.local` 在 .gitignore 中\n- [ ] git 歷史中無密鑰\n- [ ] 生產密鑰在託管平台（Vercel、Railway）中\n\n### 2. 輸入驗證\n\n#### 總是驗證使用者輸入\n```typescript\nimport { z } from 'zod'\n\n\u002F\u002F 定義驗證 schema\nconst CreateUserSchema = z.object({\n  email: z.string().email(),\n  name: z.string().min(1).max(100),\n  age: z.number().int().min(0).max(150)\n})\n\n\u002F\u002F 處理前驗證\nexport async function createUser(input: unknown) {\n  try {\n    const validated = CreateUserSchema.parse(input)\n    return await db.users.create(validated)\n  } catch (error) {\n    if (error instanceof z.ZodError) {\n      return { success: false, errors: error.errors }\n    }\n    throw error\n  }\n}\n```\n\n#### 檔案上傳驗證\n```typescript\nfunction validateFileUpload(file: File) {\n  \u002F\u002F 大小檢查（最大 5MB）\n  const maxSize = 5 * 1024 * 1024\n  if (file.size > maxSize) {\n    throw new Error('File too large (max 5MB)')\n  }\n\n  \u002F\u002F 類型檢查\n  const allowedTypes = ['image\u002Fjpeg', 'image\u002Fpng', 'image\u002Fgif']\n  if (!allowedTypes.includes(file.type)) {\n    throw new Error('Invalid file type')\n  }\n\n  \u002F\u002F 副檔名檢查\n  const allowedExtensions = ['.jpg', '.jpeg', '.png', '.gif']\n  const extension = file.name.toLowerCase().match(\u002F\\.[^.]+$\u002F)?.[0]\n  if (!extension || !allowedExtensions.includes(extension)) {\n    throw new Error('Invalid file extension')\n  }\n\n  return true\n}\n```\n\n#### 驗證步驟\n- [ ] 所有使用者輸入以 schema 驗證\n- [ ] 檔案上傳受限（大小、類型、副檔名）\n- [ ] 查詢中不直接使用使用者輸入\n- [ ] 白名單驗證（非黑名單）\n- [ ] 錯誤訊息不洩露敏感資訊\n\n### 3. SQL 注入預防\n\n#### ❌ 絕不串接 SQL\n```typescript\n\u002F\u002F 危險 - SQL 注入漏洞\nconst query = `SELECT * FROM users WHERE email = '${userEmail}'`\nawait db.query(query)\n```\n\n#### ✅ 總是使用參數化查詢\n```typescript\n\u002F\u002F 安全 - 參數化查詢\nconst { data } = await supabase\n  .from('users')\n  .select('*')\n  .eq('email', userEmail)\n\n\u002F\u002F 或使用原始 SQL\nawait db.query(\n  'SELECT * FROM users WHERE email = $1',\n  [userEmail]\n)\n```\n\n#### 驗證步驟\n- [ ] 所有資料庫查詢使用參數化查詢\n- [ ] SQL 中無字串串接\n- [ ] ORM\u002F查詢建構器正確使用\n- [ ] Supabase 查詢正確淨化\n\n### 4. 認證與授權\n\n#### JWT Token 處理\n```typescript\n\u002F\u002F ❌ 錯誤：localStorage（易受 XSS 攻擊）\nlocalStorage.setItem('token', token)\n\n\u002F\u002F ✅ 正確：httpOnly cookies\nres.setHeader('Set-Cookie',\n  `token=${token}; HttpOnly; Secure; SameSite=Strict; Max-Age=3600`)\n```\n\n#### 授權檢查\n```typescript\nexport async function deleteUser(userId: string, requesterId: string) {\n  \u002F\u002F 總是先驗證授權\n  const requester = await db.users.findUnique({\n    where: { id: requesterId }\n  })\n\n  if (requester.role !== 'admin') {\n    return NextResponse.json(\n      { error: 'Unauthorized' },\n      { status: 403 }\n    )\n  }\n\n  \u002F\u002F 繼續刪除\n  await db.users.delete({ where: { id: userId } })\n}\n```\n\n#### Row Level Security（Supabase）\n```sql\n-- 在所有表格上啟用 RLS\nALTER TABLE users ENABLE ROW LEVEL SECURITY;\n\n-- 使用者只能查看自己的資料\nCREATE POLICY \"Users view own data\"\n  ON users FOR SELECT\n  USING (auth.uid() = id);\n\n-- 使用者只能更新自己的資料\nCREATE POLICY \"Users update own data\"\n  ON users FOR UPDATE\n  USING (auth.uid() = id);\n```\n\n#### 驗證步驟\n- [ ] Token 儲存在 httpOnly cookies（非 localStorage）\n- [ ] 敏感操作前有授權檢查\n- [ ] Supabase 已啟用 Row Level Security\n- [ ] 已實作基於角色的存取控制\n- [ ] 工作階段管理安全\n\n### 5. XSS 預防\n\n#### 淨化 HTML\n```typescript\nimport DOMPurify from 'isomorphic-dompurify'\n\n\u002F\u002F 總是淨化使用者提供的 HTML\nfunction renderUserContent(html: string) {\n  const clean = DOMPurify.sanitize(html, {\n    ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'p'],\n    ALLOWED_ATTR: []\n  })\n  return \u003Cdiv dangerouslySetInnerHTML={{ __html: clean }} \u002F>\n}\n```\n\n#### Content Security Policy\n```typescript\n\u002F\u002F next.config.js\nconst securityHeaders = [\n  {\n    key: 'Content-Security-Policy',\n    value: `\n      default-src 'self';\n      script-src 'self' 'unsafe-eval' 'unsafe-inline';\n      style-src 'self' 'unsafe-inline';\n      img-src 'self' data: https:;\n      font-src 'self';\n      connect-src 'self' https:\u002F\u002Fapi.example.com;\n    `.replace(\u002F\\s{2,}\u002Fg, ' ').trim()\n  }\n]\n```\n\n#### 驗證步驟\n- [ ] 使用者提供的 HTML 已淨化\n- [ ] CSP headers 已設定\n- [ ] 無未驗證的動態內容渲染\n- [ ] 使用 React 內建 XSS 保護\n\n### 6. CSRF 保護\n\n#### CSRF Tokens\n```typescript\nimport { csrf } from '@\u002Flib\u002Fcsrf'\n\nexport async function POST(request: Request) {\n  const token = request.headers.get('X-CSRF-Token')\n\n  if (!csrf.verify(token)) {\n    return NextResponse.json(\n      { error: 'Invalid CSRF token' },\n      { status: 403 }\n    )\n  }\n\n  \u002F\u002F 處理請求\n}\n```\n\n#### SameSite Cookies\n```typescript\nres.setHeader('Set-Cookie',\n  `session=${sessionId}; HttpOnly; Secure; SameSite=Strict`)\n```\n\n#### 驗證步驟\n- [ ] 狀態變更操作有 CSRF tokens\n- [ ] 所有 cookies 設定 SameSite=Strict\n- [ ] 已實作 Double-submit cookie 模式\n\n### 7. 速率限制\n\n#### API 速率限制\n```typescript\nimport rateLimit from 'express-rate-limit'\n\nconst limiter = rateLimit({\n  windowMs: 15 * 60 * 1000, \u002F\u002F 15 分鐘\n  max: 100, \u002F\u002F 每視窗 100 個請求\n  message: 'Too many requests'\n})\n\n\u002F\u002F 套用到路由\napp.use('\u002Fapi\u002F', limiter)\n```\n\n#### 昂貴操作\n```typescript\n\u002F\u002F 搜尋的積極速率限制\nconst searchLimiter = rateLimit({\n  windowMs: 60 * 1000, \u002F\u002F 1 分鐘\n  max: 10, \u002F\u002F 每分鐘 10 個請求\n  message: 'Too many search requests'\n})\n\napp.use('\u002Fapi\u002Fsearch', searchLimiter)\n```\n\n#### 驗證步驟\n- [ ] 所有 API 端點有速率限制\n- [ ] 昂貴操作有更嚴格限制\n- [ ] 基於 IP 的速率限制\n- [ ] 基於使用者的速率限制（已認證）\n\n### 8. 敏感資料暴露\n\n#### 日誌記錄\n```typescript\n\u002F\u002F ❌ 錯誤：記錄敏感資料\nconsole.log('User login:', { email, password })\nconsole.log('Payment:', { cardNumber, cvv })\n\n\u002F\u002F ✅ 正確：遮蔽敏感資料\nconsole.log('User login:', { email, userId })\nconsole.log('Payment:', { last4: card.last4, userId })\n```\n\n#### 錯誤訊息\n```typescript\n\u002F\u002F ❌ 錯誤：暴露內部細節\ncatch (error) {\n  return NextResponse.json(\n    { error: error.message, stack: error.stack },\n    { status: 500 }\n  )\n}\n\n\u002F\u002F ✅ 正確：通用錯誤訊息\ncatch (error) {\n  console.error('Internal error:', error)\n  return NextResponse.json(\n    { error: 'An error occurred. Please try again.' },\n    { status: 500 }\n  )\n}\n```\n\n#### 驗證步驟\n- [ ] 日誌中無密碼、token 或密鑰\n- [ ] 使用者收到通用錯誤訊息\n- [ ] 詳細錯誤只在伺服器日誌\n- [ ] 不向使用者暴露堆疊追蹤\n\n### 9. 區塊鏈安全（Solana）\n\n#### 錢包驗證\n```typescript\nimport { verify } from '@solana\u002Fweb3.js'\n\nasync function verifyWalletOwnership(\n  publicKey: string,\n  signature: string,\n  message: string\n) {\n  try {\n    const isValid = verify(\n      Buffer.from(message),\n      Buffer.from(signature, 'base64'),\n      Buffer.from(publicKey, 'base64')\n    )\n    return isValid\n  } catch (error) {\n    return false\n  }\n}\n```\n\n#### 交易驗證\n```typescript\nasync function verifyTransaction(transaction: Transaction) {\n  \u002F\u002F 驗證收款人\n  if (transaction.to !== expectedRecipient) {\n    throw new Error('Invalid recipient')\n  }\n\n  \u002F\u002F 驗證金額\n  if (transaction.amount > maxAmount) {\n    throw new Error('Amount exceeds limit')\n  }\n\n  \u002F\u002F 驗證使用者有足夠餘額\n  const balance = await getBalance(transaction.from)\n  if (balance \u003C transaction.amount) {\n    throw new Error('Insufficient balance')\n  }\n\n  return true\n}\n```\n\n#### 驗證步驟\n- [ ] 錢包簽章已驗證\n- [ ] 交易詳情已驗證\n- [ ] 交易前有餘額檢查\n- [ ] 無盲目交易簽署\n\n### 10. 依賴安全\n\n#### 定期更新\n```bash\n# 檢查漏洞\nnpm audit\n\n# 自動修復可修復的問題\nnpm audit fix\n\n# 更新依賴\nnpm update\n\n# 檢查過時套件\nnpm outdated\n```\n\n#### Lock 檔案\n```bash\n# 總是 commit lock 檔案\ngit add package-lock.json\n\n# 在 CI\u002FCD 中使用以獲得可重現的建置\nnpm ci  # 而非 npm install\n```\n\n#### 驗證步驟\n- [ ] 依賴保持最新\n- [ ] 無已知漏洞（npm audit 乾淨）\n- [ ] Lock 檔案已 commit\n- [ ] GitHub 上已啟用 Dependabot\n- [ ] 定期安全更新\n\n## 安全測試\n\n### 自動化安全測試\n```typescript\n\u002F\u002F 測試認證\ntest('requires authentication', async () => {\n  const response = await fetch('\u002Fapi\u002Fprotected')\n  expect(response.status).toBe(401)\n})\n\n\u002F\u002F 測試授權\ntest('requires admin role', async () => {\n  const response = await fetch('\u002Fapi\u002Fadmin', {\n    headers: { Authorization: `Bearer ${userToken}` }\n  })\n  expect(response.status).toBe(403)\n})\n\n\u002F\u002F 測試輸入驗證\ntest('rejects invalid input', async () => {\n  const response = await fetch('\u002Fapi\u002Fusers', {\n    method: 'POST',\n    body: JSON.stringify({ email: 'not-an-email' })\n  })\n  expect(response.status).toBe(400)\n})\n\n\u002F\u002F 測試速率限制\ntest('enforces rate limits', async () => {\n  const requests = Array(101).fill(null).map(() =>\n    fetch('\u002Fapi\u002Fendpoint')\n  )\n\n  const responses = await Promise.all(requests)\n  const tooManyRequests = responses.filter(r => r.status === 429)\n\n  expect(tooManyRequests.length).toBeGreaterThan(0)\n})\n```\n\n## 部署前安全檢查清單\n\n任何生產部署前：\n\n- [ ] **密鑰**：無寫死密鑰，全在環境變數中\n- [ ] **輸入驗證**：所有使用者輸入已驗證\n- [ ] **SQL 注入**：所有查詢已參數化\n- [ ] **XSS**：使用者內容已淨化\n- [ ] **CSRF**：保護已啟用\n- [ ] **認證**：正確的 token 處理\n- [ ] **授權**：角色檢查已就位\n- [ ] **速率限制**：所有端點已啟用\n- [ ] **HTTPS**：生產環境強制使用\n- [ ] **安全標頭**：CSP、X-Frame-Options 已設定\n- [ ] **錯誤處理**：錯誤中無敏感資料\n- [ ] **日誌記錄**：無敏感資料被記錄\n- [ ] **依賴**：最新，無漏洞\n- [ ] **Row Level Security**：Supabase 已啟用\n- [ ] **CORS**：正確設定\n- [ ] **檔案上傳**：已驗證（大小、類型）\n- [ ] **錢包簽章**：已驗證（如果是區塊鏈）\n\n## 資源\n\n- [OWASP Top 10](https:\u002F\u002Fowasp.org\u002Fwww-project-top-ten\u002F)\n- [Next.js Security](https:\u002F\u002Fnextjs.org\u002Fdocs\u002Fsecurity)\n- [Supabase Security](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Fauth)\n- [Web Security Academy](https:\u002F\u002Fportswigger.net\u002Fweb-security)\n\n---\n\n**記住**：安全性不是可選的。一個漏洞可能危及整個平台。有疑慮時，選擇謹慎的做法。\n","# 安全性審查技能\n\n此技能確保所有程式碼遵循安全性最佳實務並識別潛在漏洞。\n\n## 何時啟用\n\n- 實作認證或授權\n- 處理使用者輸入或檔案上傳\n- 建立新的 API 端點\n- 處理密鑰或憑證\n- 實作支付功能\n- 儲存或傳輸敏感資料\n- 整合第三方 API\n\n## 安全性檢查清單\n\n### 1. 密鑰管理\n\n#### ❌ 絕不這樣做\n```typescript\nconst apiKey = \"sk-proj-xxxxx\"  \u002F\u002F 寫死的密鑰\nconst dbPassword = \"password123\" \u002F\u002F 在原始碼中\n```\n\n#### ✅ 總是這樣做\n```typescript\nconst apiKey = process.env.OPENAI_API_KEY\nconst dbUrl = process.env.DATABASE_URL\n\n\u002F\u002F 驗證密鑰存在\nif (!apiKey) {\n  throw new Error('OPENAI_API_KEY not configured')\n}\n```\n\n#### 驗證步驟\n- [ ] 無寫死的 API 金鑰、Token 或密碼\n- [ ] 所有密鑰在環境變數中\n- [ ] `.env.local` 在 .gitignore 中\n- [ ] git 歷史中無密鑰\n- [ ] 生產密鑰在託管平台（Vercel、Railway）中\n\n### 2. 輸入驗證\n\n#### 總是驗證使用者輸入\n```typescript\nimport { z } from 'zod'\n\n\u002F\u002F 定義驗證 schema\nconst CreateUserSchema = z.object({\n  email: z.string().email(),\n  name: z.string().min(1).max(100),\n  age: z.number().int().min(0).max(150)\n})\n\n\u002F\u002F 處理前驗證\nexport async function createUser(input: unknown) {\n  try {\n    const validated = CreateUserSchema.parse(input)\n    return await db.users.create(validated)\n  } catch (error) {\n    if (error instanceof z.ZodError) {\n      return { success: false, errors: error.errors }\n    }\n    throw error\n  }\n}\n```\n\n#### 檔案上傳驗證\n```typescript\nfunction validateFileUpload(file: File) {\n  \u002F\u002F 大小檢查（最大 5MB）\n  const maxSize = 5 * 1024 * 1024\n  if (file.size > maxSize) {\n    throw new Error('File too large (max 5MB)')\n  }\n\n  \u002F\u002F 類型檢查\n  const allowedTypes = ['image\u002Fjpeg', 'image\u002Fpng', 'image\u002Fgif']\n  if (!allowedTypes.includes(file.type)) {\n    throw new Error('Invalid file type')\n  }\n\n  \u002F\u002F 副檔名檢查\n  const allowedExtensions = ['.jpg', '.jpeg', '.png', '.gif']\n  const extension = file.name.toLowerCase().match(\u002F\\.[^.]+$\u002F)?.[0]\n  if (!extension || !allowedExtensions.includes(extension)) {\n    throw new Error('Invalid file extension')\n  }\n\n  return true\n}\n```\n\n#### 驗證步驟\n- [ ] 所有使用者輸入以 schema 驗證\n- [ ] 檔案上傳受限（大小、類型、副檔名）\n- [ ] 查詢中不直接使用使用者輸入\n- [ ] 白名單驗證（非黑名單）\n- [ ] 錯誤訊息不洩露敏感資訊\n\n### 3. SQL 注入預防\n\n#### ❌ 絕不串接 SQL\n```typescript\n\u002F\u002F 危險 - SQL 注入漏洞\nconst query = `SELECT * FROM users WHERE email = '${userEmail}'`\nawait db.query(query)\n```\n\n#### ✅ 總是使用參數化查詢\n```typescript\n\u002F\u002F 安全 - 參數化查詢\nconst { data } = await supabase\n  .from('users')\n  .select('*')\n  .eq('email', userEmail)\n\n\u002F\u002F 或使用原始 SQL\nawait db.query(\n  'SELECT * FROM users WHERE email = $1',\n  [userEmail]\n)\n```\n\n#### 驗證步驟\n- [ ] 所有資料庫查詢使用參數化查詢\n- [ ] SQL 中無字串串接\n- [ ] ORM\u002F查詢建構器正確使用\n- [ ] Supabase 查詢正確淨化\n\n### 4. 認證與授權\n\n#### JWT Token 處理\n```typescript\n\u002F\u002F ❌ 錯誤：localStorage（易受 XSS 攻擊）\nlocalStorage.setItem('token', token)\n\n\u002F\u002F ✅ 正確：httpOnly cookies\nres.setHeader('Set-Cookie',\n  `token=${token}; HttpOnly; Secure; SameSite=Strict; Max-Age=3600`)\n```\n\n#### 授權檢查\n```typescript\nexport async function deleteUser(userId: string, requesterId: string) {\n  \u002F\u002F 總是先驗證授權\n  const requester = await db.users.findUnique({\n    where: { id: requesterId }\n  })\n\n  if (requester.role !== 'admin') {\n    return NextResponse.json(\n      { error: 'Unauthorized' },\n      { status: 403 }\n    )\n  }\n\n  \u002F\u002F 繼續刪除\n  await db.users.delete({ where: { id: userId } })\n}\n```\n\n#### Row Level Security（Supabase）\n```sql\n-- 在所有表格上啟用 RLS\nALTER TABLE users ENABLE ROW LEVEL SECURITY;\n\n-- 使用者只能查看自己的資料\nCREATE POLICY \"Users view own data\"\n  ON users FOR SELECT\n  USING (auth.uid() = id);\n\n-- 使用者只能更新自己的資料\nCREATE POLICY \"Users update own data\"\n  ON users FOR UPDATE\n  USING (auth.uid() = id);\n```\n\n#### 驗證步驟\n- [ ] Token 儲存在 httpOnly cookies（非 localStorage）\n- [ ] 敏感操作前有授權檢查\n- [ ] Supabase 已啟用 Row Level Security\n- [ ] 已實作基於角色的存取控制\n- [ ] 工作階段管理安全\n\n### 5. XSS 預防\n\n#### 淨化 HTML\n```typescript\nimport DOMPurify from 'isomorphic-dompurify'\n\n\u002F\u002F 總是淨化使用者提供的 HTML\nfunction renderUserContent(html: string) {\n  const clean = DOMPurify.sanitize(html, {\n    ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'p'],\n    ALLOWED_ATTR: []\n  })\n  return \u003Cdiv dangerouslySetInnerHTML={{ __html: clean }} \u002F>\n}\n```\n\n#### Content Security Policy\n```typescript\n\u002F\u002F next.config.js\nconst securityHeaders = [\n  {\n    key: 'Content-Security-Policy',\n    value: `\n      default-src 'self';\n      script-src 'self' 'unsafe-eval' 'unsafe-inline';\n      style-src 'self' 'unsafe-inline';\n      img-src 'self' data: https:;\n      font-src 'self';\n      connect-src 'self' https:\u002F\u002Fapi.example.com;\n    `.replace(\u002F\\s{2,}\u002Fg, ' ').trim()\n  }\n]\n```\n\n#### 驗證步驟\n- [ ] 使用者提供的 HTML 已淨化\n- [ ] CSP headers 已設定\n- [ ] 無未驗證的動態內容渲染\n- [ ] 使用 React 內建 XSS 保護\n\n### 6. CSRF 保護\n\n#### CSRF Tokens\n```typescript\nimport { csrf } from '@\u002Flib\u002Fcsrf'\n\nexport async function POST(request: Request) {\n  const token = request.headers.get('X-CSRF-Token')\n\n  if (!csrf.verify(token)) {\n    return NextResponse.json(\n      { error: 'Invalid CSRF token' },\n      { status: 403 }\n    )\n  }\n\n  \u002F\u002F 處理請求\n}\n```\n\n#### SameSite Cookies\n```typescript\nres.setHeader('Set-Cookie',\n  `session=${sessionId}; HttpOnly; Secure; SameSite=Strict`)\n```\n\n#### 驗證步驟\n- [ ] 狀態變更操作有 CSRF tokens\n- [ ] 所有 cookies 設定 SameSite=Strict\n- [ ] 已實作 Double-submit cookie 模式\n\n### 7. 速率限制\n\n#### API 速率限制\n```typescript\nimport rateLimit from 'express-rate-limit'\n\nconst limiter = rateLimit({\n  windowMs: 15 * 60 * 1000, \u002F\u002F 15 分鐘\n  max: 100, \u002F\u002F 每視窗 100 個請求\n  message: 'Too many requests'\n})\n\n\u002F\u002F 套用到路由\napp.use('\u002Fapi\u002F', limiter)\n```\n\n#### 昂貴操作\n```typescript\n\u002F\u002F 搜尋的積極速率限制\nconst searchLimiter = rateLimit({\n  windowMs: 60 * 1000, \u002F\u002F 1 分鐘\n  max: 10, \u002F\u002F 每分鐘 10 個請求\n  message: 'Too many search requests'\n})\n\napp.use('\u002Fapi\u002Fsearch', searchLimiter)\n```\n\n#### 驗證步驟\n- [ ] 所有 API 端點有速率限制\n- [ ] 昂貴操作有更嚴格限制\n- [ ] 基於 IP 的速率限制\n- [ ] 基於使用者的速率限制（已認證）\n\n### 8. 敏感資料暴露\n\n#### 日誌記錄\n```typescript\n\u002F\u002F ❌ 錯誤：記錄敏感資料\nconsole.log('User login:', { email, password })\nconsole.log('Payment:', { cardNumber, cvv })\n\n\u002F\u002F ✅ 正確：遮蔽敏感資料\nconsole.log('User login:', { email, userId })\nconsole.log('Payment:', { last4: card.last4, userId })\n```\n\n#### 錯誤訊息\n```typescript\n\u002F\u002F ❌ 錯誤：暴露內部細節\ncatch (error) {\n  return NextResponse.json(\n    { error: error.message, stack: error.stack },\n    { status: 500 }\n  )\n}\n\n\u002F\u002F ✅ 正確：通用錯誤訊息\ncatch (error) {\n  console.error('Internal error:', error)\n  return NextResponse.json(\n    { error: 'An error occurred. Please try again.' },\n    { status: 500 }\n  )\n}\n```\n\n#### 驗證步驟\n- [ ] 日誌中無密碼、token 或密鑰\n- [ ] 使用者收到通用錯誤訊息\n- [ ] 詳細錯誤只在伺服器日誌\n- [ ] 不向使用者暴露堆疊追蹤\n\n### 9. 區塊鏈安全（Solana）\n\n#### 錢包驗證\n```typescript\nimport { verify } from '@solana\u002Fweb3.js'\n\nasync function verifyWalletOwnership(\n  publicKey: string,\n  signature: string,\n  message: string\n) {\n  try {\n    const isValid = verify(\n      Buffer.from(message),\n      Buffer.from(signature, 'base64'),\n      Buffer.from(publicKey, 'base64')\n    )\n    return isValid\n  } catch (error) {\n    return false\n  }\n}\n```\n\n#### 交易驗證\n```typescript\nasync function verifyTransaction(transaction: Transaction) {\n  \u002F\u002F 驗證收款人\n  if (transaction.to !== expectedRecipient) {\n    throw new Error('Invalid recipient')\n  }\n\n  \u002F\u002F 驗證金額\n  if (transaction.amount > maxAmount) {\n    throw new Error('Amount exceeds limit')\n  }\n\n  \u002F\u002F 驗證使用者有足夠餘額\n  const balance = await getBalance(transaction.from)\n  if (balance \u003C transaction.amount) {\n    throw new Error('Insufficient balance')\n  }\n\n  return true\n}\n```\n\n#### 驗證步驟\n- [ ] 錢包簽章已驗證\n- [ ] 交易詳情已驗證\n- [ ] 交易前有餘額檢查\n- [ ] 無盲目交易簽署\n\n### 10. 依賴安全\n\n#### 定期更新\n```bash\n# 檢查漏洞\nnpm audit\n\n# 自動修復可修復的問題\nnpm audit fix\n\n# 更新依賴\nnpm update\n\n# 檢查過時套件\nnpm outdated\n```\n\n#### Lock 檔案\n```bash\n# 總是 commit lock 檔案\ngit add package-lock.json\n\n# 在 CI\u002FCD 中使用以獲得可重現的建置\nnpm ci  # 而非 npm install\n```\n\n#### 驗證步驟\n- [ ] 依賴保持最新\n- [ ] 無已知漏洞（npm audit 乾淨）\n- [ ] Lock 檔案已 commit\n- [ ] GitHub 上已啟用 Dependabot\n- [ ] 定期安全更新\n\n## 安全測試\n\n### 自動化安全測試\n```typescript\n\u002F\u002F 測試認證\ntest('requires authentication', async () => {\n  const response = await fetch('\u002Fapi\u002Fprotected')\n  expect(response.status).toBe(401)\n})\n\n\u002F\u002F 測試授權\ntest('requires admin role', async () => {\n  const response = await fetch('\u002Fapi\u002Fadmin', {\n    headers: { Authorization: `Bearer ${userToken}` }\n  })\n  expect(response.status).toBe(403)\n})\n\n\u002F\u002F 測試輸入驗證\ntest('rejects invalid input', async () => {\n  const response = await fetch('\u002Fapi\u002Fusers', {\n    method: 'POST',\n    body: JSON.stringify({ email: 'not-an-email' })\n  })\n  expect(response.status).toBe(400)\n})\n\n\u002F\u002F 測試速率限制\ntest('enforces rate limits', async () => {\n  const requests = Array(101).fill(null).map(() =>\n    fetch('\u002Fapi\u002Fendpoint')\n  )\n\n  const responses = await Promise.all(requests)\n  const tooManyRequests = responses.filter(r => r.status === 429)\n\n  expect(tooManyRequests.length).toBeGreaterThan(0)\n})\n```\n\n## 部署前安全檢查清單\n\n任何生產部署前：\n\n- [ ] **密鑰**：無寫死密鑰，全在環境變數中\n- [ ] **輸入驗證**：所有使用者輸入已驗證\n- [ ] **SQL 注入**：所有查詢已參數化\n- [ ] **XSS**：使用者內容已淨化\n- [ ] **CSRF**：保護已啟用\n- [ ] **認證**：正確的 token 處理\n- [ ] **授權**：角色檢查已就位\n- [ ] **速率限制**：所有端點已啟用\n- [ ] **HTTPS**：生產環境強制使用\n- [ ] **安全標頭**：CSP、X-Frame-Options 已設定\n- [ ] **錯誤處理**：錯誤中無敏感資料\n- [ ] **日誌記錄**：無敏感資料被記錄\n- [ ] **依賴**：最新，無漏洞\n- [ ] **Row Level Security**：Supabase 已啟用\n- [ ] **CORS**：正確設定\n- [ ] **檔案上傳**：已驗證（大小、類型）\n- [ ] **錢包簽章**：已驗證（如果是區塊鏈）\n\n## 資源\n\n- [OWASP Top 10](https:\u002F\u002Fowasp.org\u002Fwww-project-top-ten\u002F)\n- [Next.js Security](https:\u002F\u002Fnextjs.org\u002Fdocs\u002Fsecurity)\n- [Supabase Security](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Fauth)\n- [Web Security Academy](https:\u002F\u002Fportswigger.net\u002Fweb-security)\n\n---\n\n**記住**：安全性不是可選的。一個漏洞可能危及整個平台。有疑慮時，選擇謹慎的做法。\n",{"name":5,"description":7},"main","7b610356e36623652299fa2acb477ff821b1d920","upstream-sync\u002Fwork\u002Fecc\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fsecurity-review",0,"https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw","https:\u002F\u002Fgithub.com\u002Foabdelmaksoud","https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fo-abdelmaksoud\u002F","Full-Stack Engineer | AI Systems Architect | Building autonomous multi-agent systems","2026-03-08 21:12:53",{"source":8,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add oabdelmaksoud\u002FSuperClaw --skill security-review",{"tool":51,"command":52},"bunx","bunx skills add oabdelmaksoud\u002FSuperClaw --skill security-review",{"tool":54,"command":55},"pnpm","pnpm dlx skills add oabdelmaksoud\u002FSuperClaw --skill security-review","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fsecurity-review\u002FSKILL.md",true,[59,65,69,73,77,81,85],{"path":60,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":63,"sourceHtmlUrl":64},"cloud-infrastructure-security.md","REFERENCE","参考文档",9420,"https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fsecurity-review\u002Fcloud-infrastructure-security.md",{"path":66,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":67,"sourceHtmlUrl":68},"reference\u002Fcalculation-assumptions.md",7133,"https:\u002F\u002Fgithub.com\u002Fanthropics\u002Fknowledge-work-plugins\u002Fblob\u002Fmain\u002Fsmall-business\u002Fskills\u002Ftax-season-organizer\u002Freference\u002Fcalculation-assumptions.md",{"path":70,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":71,"sourceHtmlUrl":72},"reference\u002Fconnector-queries.md",11978,"https:\u002F\u002Fgithub.com\u002Fanthropics\u002Fknowledge-work-plugins\u002Fblob\u002Fmain\u002Fsmall-business\u002Fskills\u002Ftax-season-organizer\u002Freference\u002Fconnector-queries.md",{"path":74,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":75,"sourceHtmlUrl":76},"reference\u002Fexamples\u002Fquarterly-estimate.md",2915,"https:\u002F\u002Fgithub.com\u002Fanthropics\u002Fknowledge-work-plugins\u002Fblob\u002Fmain\u002Fsmall-business\u002Fskills\u002Ftax-season-organizer\u002Freference\u002Fexamples\u002Fquarterly-estimate.md",{"path":78,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":79,"sourceHtmlUrl":80},"reference\u002Fexamples\u002Fyear-end-1099.md",4540,"https:\u002F\u002Fgithub.com\u002Fanthropics\u002Fknowledge-work-plugins\u002Fblob\u002Fmain\u002Fsmall-business\u002Fskills\u002Ftax-season-organizer\u002Freference\u002Fexamples\u002Fyear-end-1099.md",{"path":82,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":83,"sourceHtmlUrl":84},"reference\u002Fgotchas.md",3242,"https:\u002F\u002Fgithub.com\u002Fanthropics\u002Fknowledge-work-plugins\u002Fblob\u002Fmain\u002Fsmall-business\u002Fskills\u002Ftax-season-organizer\u002Freference\u002Fgotchas.md",{"path":86,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":87,"sourceHtmlUrl":88},"reference\u002Foutput-formats.md",3105,"https:\u002F\u002Fgithub.com\u002Fanthropics\u002Fknowledge-work-plugins\u002Fblob\u002Fmain\u002Fsmall-business\u002Fskills\u002Ftax-season-organizer\u002Freference\u002Foutput-formats.md",[90,106,120,139,164,182],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":31},"01M6D88QCPTBZVCRED0NZ1Y8K8","visa-doc-translate","Translate visa application documents (images) to English and create a bilingual PDF with original and translation","https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fskills\u002Fvisa-doc-translate\u002FSKILL.md",[],[97,98,99,100,101,102,103,104,105],"translate","doc","visa doc translate","translation","application","create","images","PDF","documents",{"skillNo":107,"name":108,"nameZh":6,"description":109,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":112,"publishedAt":31},"01M6D88NBM95T3TFM50CYYAP65","verification-loop","A comprehensive verification system for Claude Code sessions.","https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fskills\u002Fverification-loop\u002FSKILL.md",[],[113,114,115,116,117,118,119],"verification","loop","verification loop","sessions","code","claude code sessions","system",{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":31},"01M6D88JFZ2P996GVRHJNSZSTM","tdd-workflow","Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.","https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fskills\u002Ftdd-workflow\u002FSKILL.md",[],[127,128,129,130,131,132,117,133,26,134,135,136,137,138],"tdd","workflow","tdd workflow","e2e tests","e2e","integration","development","test","refactoring","coverage","tests","writing",{"skillNo":140,"name":141,"nameZh":6,"description":142,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":143,"categories":144,"keywords":145,"publishedAt":31},"01M6D88FTHRRSVJMXF2G7MQAK3","swiftui-patterns","SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS\u002FmacOS UI best practices.","https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fskills\u002Fswiftui-patterns\u002FSKILL.md",[],[29,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163],"swiftui","swiftui patterns","architecture","macos","performance","state management","best practices","state","ui","Optimization","ios","architecture patterns","Composition","performance optimization","view","management","swiftui architecture","navigation",{"skillNo":165,"name":166,"nameZh":6,"description":167,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":168,"categories":169,"keywords":170,"publishedAt":31},"01M6D88D527QTQT9DKHTRFN6EA","swift-protocol-di-testing","Protocol-based dependency injection for testable Swift code — mock file system, network, and external APIs using focused protocols and Swift Testing.","https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fskills\u002Fswift-protocol-di-testing\u002FSKILL.md",[],[171,172,173,174,117,175,176,177,178,119,179,180,181],"swift protocol di testing","protocol","swift","testing","protocols","file","network","injection","dependency","swift testing","dependency injection",{"skillNo":183,"name":184,"nameZh":6,"description":185,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":186,"categories":187,"keywords":188,"publishedAt":31},"01M6D88AJW8H2QNWSW5ZY82R43","swift-concurrency-6-2","Swift 6.2 Approachable Concurrency — single-threaded by default, @concurrent for explicit background offloading, isolated conformances for main actor types.","https:\u002F\u002Fgithub.com\u002Foabdelmaksoud\u002FSuperClaw\u002Fblob\u002Fmain\u002Fupstream-sync\u002Fwork\u002Fecc\u002Fskills\u002Fswift-concurrency-6-2\u002FSKILL.md",[],[189,190,173,191,192,36],"concurrency","swift concurrency","swift concurrency 6 2","default"]