specdo 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +308 -0
  3. package/README.zh-CN.md +306 -0
  4. package/bin/specdo.js +3 -0
  5. package/dist/cli/index.d.ts +15 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +297 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/commands/_shared.d.ts +45 -0
  10. package/dist/commands/_shared.d.ts.map +1 -0
  11. package/dist/commands/_shared.js +124 -0
  12. package/dist/commands/_shared.js.map +1 -0
  13. package/dist/commands/apply.d.ts +30 -0
  14. package/dist/commands/apply.d.ts.map +1 -0
  15. package/dist/commands/apply.js +393 -0
  16. package/dist/commands/apply.js.map +1 -0
  17. package/dist/commands/archive.d.ts +25 -0
  18. package/dist/commands/archive.d.ts.map +1 -0
  19. package/dist/commands/archive.js +362 -0
  20. package/dist/commands/archive.js.map +1 -0
  21. package/dist/commands/doctor.d.ts +21 -0
  22. package/dist/commands/doctor.d.ts.map +1 -0
  23. package/dist/commands/doctor.js +180 -0
  24. package/dist/commands/doctor.js.map +1 -0
  25. package/dist/commands/domains.d.ts +14 -0
  26. package/dist/commands/domains.d.ts.map +1 -0
  27. package/dist/commands/domains.js +107 -0
  28. package/dist/commands/domains.js.map +1 -0
  29. package/dist/commands/explore.d.ts +48 -0
  30. package/dist/commands/explore.d.ts.map +1 -0
  31. package/dist/commands/explore.js +378 -0
  32. package/dist/commands/explore.js.map +1 -0
  33. package/dist/commands/init.d.ts +45 -0
  34. package/dist/commands/init.d.ts.map +1 -0
  35. package/dist/commands/init.js +243 -0
  36. package/dist/commands/init.js.map +1 -0
  37. package/dist/commands/list.d.ts +23 -0
  38. package/dist/commands/list.d.ts.map +1 -0
  39. package/dist/commands/list.js +135 -0
  40. package/dist/commands/list.js.map +1 -0
  41. package/dist/commands/propose.d.ts +22 -0
  42. package/dist/commands/propose.d.ts.map +1 -0
  43. package/dist/commands/propose.js +316 -0
  44. package/dist/commands/propose.js.map +1 -0
  45. package/dist/commands/show.d.ts +15 -0
  46. package/dist/commands/show.d.ts.map +1 -0
  47. package/dist/commands/show.js +214 -0
  48. package/dist/commands/show.js.map +1 -0
  49. package/dist/commands/status.d.ts +17 -0
  50. package/dist/commands/status.d.ts.map +1 -0
  51. package/dist/commands/status.js +146 -0
  52. package/dist/commands/status.js.map +1 -0
  53. package/dist/commands/sync.d.ts +21 -0
  54. package/dist/commands/sync.d.ts.map +1 -0
  55. package/dist/commands/sync.js +113 -0
  56. package/dist/commands/sync.js.map +1 -0
  57. package/dist/commands/validate.d.ts +117 -0
  58. package/dist/commands/validate.d.ts.map +1 -0
  59. package/dist/commands/validate.js +446 -0
  60. package/dist/commands/validate.js.map +1 -0
  61. package/dist/core/apply-brief-renderer.d.ts +35 -0
  62. package/dist/core/apply-brief-renderer.d.ts.map +1 -0
  63. package/dist/core/apply-brief-renderer.js +242 -0
  64. package/dist/core/apply-brief-renderer.js.map +1 -0
  65. package/dist/core/config-store.d.ts +190 -0
  66. package/dist/core/config-store.d.ts.map +1 -0
  67. package/dist/core/config-store.js +280 -0
  68. package/dist/core/config-store.js.map +1 -0
  69. package/dist/core/context-store.d.ts +96 -0
  70. package/dist/core/context-store.d.ts.map +1 -0
  71. package/dist/core/context-store.js +426 -0
  72. package/dist/core/context-store.js.map +1 -0
  73. package/dist/core/json-schemas.d.ts +349 -0
  74. package/dist/core/json-schemas.d.ts.map +1 -0
  75. package/dist/core/json-schemas.js +125 -0
  76. package/dist/core/json-schemas.js.map +1 -0
  77. package/dist/core/skill-content/cross-domain.d.ts +12 -0
  78. package/dist/core/skill-content/cross-domain.d.ts.map +1 -0
  79. package/dist/core/skill-content/cross-domain.js +291 -0
  80. package/dist/core/skill-content/cross-domain.js.map +1 -0
  81. package/dist/core/skill-content/protocol-examples.d.ts +13 -0
  82. package/dist/core/skill-content/protocol-examples.d.ts.map +1 -0
  83. package/dist/core/skill-content/protocol-examples.js +190 -0
  84. package/dist/core/skill-content/protocol-examples.js.map +1 -0
  85. package/dist/core/skill-content/workflow-content.d.ts +25 -0
  86. package/dist/core/skill-content/workflow-content.d.ts.map +1 -0
  87. package/dist/core/skill-content/workflow-content.js +1572 -0
  88. package/dist/core/skill-content/workflow-content.js.map +1 -0
  89. package/dist/core/skill-exporter.d.ts +186 -0
  90. package/dist/core/skill-exporter.d.ts.map +1 -0
  91. package/dist/core/skill-exporter.js +922 -0
  92. package/dist/core/skill-exporter.js.map +1 -0
  93. package/dist/core/spec-sync.d.ts +65 -0
  94. package/dist/core/spec-sync.d.ts.map +1 -0
  95. package/dist/core/spec-sync.js +226 -0
  96. package/dist/core/spec-sync.js.map +1 -0
  97. package/dist/core/task-parser.d.ts +58 -0
  98. package/dist/core/task-parser.d.ts.map +1 -0
  99. package/dist/core/task-parser.js +244 -0
  100. package/dist/core/task-parser.js.map +1 -0
  101. package/dist/core/template-renderer.d.ts +51 -0
  102. package/dist/core/template-renderer.d.ts.map +1 -0
  103. package/dist/core/template-renderer.js +362 -0
  104. package/dist/core/template-renderer.js.map +1 -0
  105. package/dist/domains/architecture.d.ts +34 -0
  106. package/dist/domains/architecture.d.ts.map +1 -0
  107. package/dist/domains/architecture.js +341 -0
  108. package/dist/domains/architecture.js.map +1 -0
  109. package/dist/domains/backend.d.ts +35 -0
  110. package/dist/domains/backend.d.ts.map +1 -0
  111. package/dist/domains/backend.js +367 -0
  112. package/dist/domains/backend.js.map +1 -0
  113. package/dist/domains/frontend.d.ts +36 -0
  114. package/dist/domains/frontend.d.ts.map +1 -0
  115. package/dist/domains/frontend.js +373 -0
  116. package/dist/domains/frontend.js.map +1 -0
  117. package/dist/domains/index.d.ts +49 -0
  118. package/dist/domains/index.d.ts.map +1 -0
  119. package/dist/domains/index.js +255 -0
  120. package/dist/domains/index.js.map +1 -0
  121. package/dist/domains/operations.d.ts +37 -0
  122. package/dist/domains/operations.d.ts.map +1 -0
  123. package/dist/domains/operations.js +344 -0
  124. package/dist/domains/operations.js.map +1 -0
  125. package/dist/domains/pool-ranking.d.ts +43 -0
  126. package/dist/domains/pool-ranking.d.ts.map +1 -0
  127. package/dist/domains/pool-ranking.js +153 -0
  128. package/dist/domains/pool-ranking.js.map +1 -0
  129. package/dist/domains/quality.d.ts +45 -0
  130. package/dist/domains/quality.d.ts.map +1 -0
  131. package/dist/domains/quality.js +368 -0
  132. package/dist/domains/quality.js.map +1 -0
  133. package/dist/domains/security.d.ts +19 -0
  134. package/dist/domains/security.d.ts.map +1 -0
  135. package/dist/domains/security.js +364 -0
  136. package/dist/domains/security.js.map +1 -0
  137. package/dist/domains/signal-match.d.ts +25 -0
  138. package/dist/domains/signal-match.d.ts.map +1 -0
  139. package/dist/domains/signal-match.js +67 -0
  140. package/dist/domains/signal-match.js.map +1 -0
  141. package/dist/domains/types.d.ts +354 -0
  142. package/dist/domains/types.d.ts.map +1 -0
  143. package/dist/domains/types.js +12 -0
  144. package/dist/domains/types.js.map +1 -0
  145. package/dist/index.d.ts +9 -0
  146. package/dist/index.d.ts.map +1 -0
  147. package/dist/index.js +9 -0
  148. package/dist/index.js.map +1 -0
  149. package/dist/protocols/index.d.ts +36 -0
  150. package/dist/protocols/index.d.ts.map +1 -0
  151. package/dist/protocols/index.js +85 -0
  152. package/dist/protocols/index.js.map +1 -0
  153. package/dist/protocols/review-to-solid.d.ts +32 -0
  154. package/dist/protocols/review-to-solid.d.ts.map +1 -0
  155. package/dist/protocols/review-to-solid.js +309 -0
  156. package/dist/protocols/review-to-solid.js.map +1 -0
  157. package/dist/utils/prompt.d.ts +37 -0
  158. package/dist/utils/prompt.d.ts.map +1 -0
  159. package/dist/utils/prompt.js +81 -0
  160. package/dist/utils/prompt.js.map +1 -0
  161. package/package.json +80 -0
@@ -0,0 +1,364 @@
1
+ /**
2
+ * Security Domain Module
3
+ *
4
+ * 来源:
5
+ * - content/skills/security-hardening/SKILL.md (51 行)
6
+ * OWASP Top 10 审计、安全标头、CVE 扫描、密钥管理
7
+ * - content/roles/04-quality-security/security-auditor.toml (42 行)
8
+ * 安全审计方法、攻击面分析、风险排序
9
+ *
10
+ * 压缩方法:
11
+ * 1. OWASP Top 10 表格 → design.checklist + implement.antiPatterns
12
+ * 2. 安全标头模板 → design.patterns["Security Headers"]
13
+ * 3. 审计工作流 → verify.checklist
14
+ * 4. security-auditor focus areas → implement.focusAreas
15
+ * 5. 原始代码示例/Python脚本 → 丢弃(用户有自己的代码库)
16
+ */
17
+ export const securityDomain = {
18
+ name: 'security',
19
+ description: 'Security audit, OWASP Top 10, vulnerability hardening, secrets management, auth flow validation',
20
+ // ── Explore: 需求澄清 ─────────────────────────────────────
21
+ explore: {
22
+ signals: [
23
+ // 认证/授权
24
+ 'auth', 'authentication', 'oauth', 'jwt', 'sso', 'mfa', 'rbac',
25
+ 'login', 'logout', 'session', 'token', 'credential', 'password',
26
+ 'permission', 'role', 'access control', 'authorization',
27
+ // 数据安全
28
+ 'pii', 'personal data', 'privacy', 'gdpr', 'hipaa', 'pci', 'compliance',
29
+ 'encryption', 'encrypt', 'hash', 'salt', 'secret', 'key management',
30
+ // 攻击面
31
+ 'security', 'vulnerability', 'cve', 'injection', 'xss', 'csrf',
32
+ 'attack', 'threat', 'penetration', 'audit', 'harden',
33
+ // 业务场景
34
+ 'payment', 'billing', 'transaction', 'financial', 'user data',
35
+ 'admin', 'sensitive',
36
+ ],
37
+ questions: {
38
+ defaultCount: 8,
39
+ items: [
40
+ // ── Tier 1: 认证基础 (priority 9-10) ──────────────────
41
+ {
42
+ text: 'What authentication method will be used? (OAuth 2.0, JWT, SAML, session-based, API key, mTLS)',
43
+ id: 'auth-method',
44
+ signals: ['auth', 'authentication', 'oauth', 'jwt', 'sso', 'login', 'token', 'saml', 'api key', 'mtls', 'session'],
45
+ priority: 10,
46
+ },
47
+ {
48
+ text: 'Is multi-factor authentication (MFA) needed? For all users or only admins? What MFA method (TOTP, WebAuthn, SMS)?',
49
+ signals: ['auth', 'authentication', 'mfa', 'login', 'admin', 'sensitive', 'webauthn', 'totp'],
50
+ priority: 9,
51
+ requiresAnswer: ['security:auth-method'],
52
+ },
53
+ {
54
+ text: 'What is the session/token lifecycle? (access token TTL, refresh token TTL, revocation strategy, token rotation policy)',
55
+ id: 'session-lifecycle',
56
+ signals: ['session', 'token', 'jwt', 'expiry', 'refresh', 'revocation', 'credential', 'ttl'],
57
+ priority: 9,
58
+ requiresAnswer: ['security:auth-method'],
59
+ },
60
+ {
61
+ text: 'Should refresh tokens use single-use rotation? How is token reuse detected and revoked?',
62
+ signals: ['jwt', 'token', 'refresh', 'rotation', 'reuse', 'revocation'],
63
+ priority: 7,
64
+ requiresAnswer: ['security:session-lifecycle'],
65
+ conditional: { 'security:auth-method': 'jwt' },
66
+ },
67
+ {
68
+ text: 'What user roles and permission levels exist? (admin, user, viewer, editor, superadmin) — is RBAC or ABAC more appropriate?',
69
+ signals: ['rbac', 'abac', 'permission', 'role', 'access control', 'authorization', 'admin', 'role-based'],
70
+ priority: 9,
71
+ },
72
+ // ── Tier 2: 数据安全与合规 (priority 8-9) ──────────────
73
+ {
74
+ text: 'Does this handle PII, financial data, or health data? If yes, what compliance applies (GDPR, HIPAA, PCI-DSS, SOC2, CCPA)?',
75
+ id: 'compliance-data',
76
+ signals: ['pii', 'personal data', 'privacy', 'gdpr', 'hipaa', 'pci', 'compliance', 'user data', 'sensitive', 'financial', 'soc2', 'ccpa'],
77
+ priority: 9,
78
+ },
79
+ {
80
+ text: 'What encryption standards are required? (at rest: AES-256-GCM; in transit: TLS 1.3; key rotation frequency)',
81
+ signals: ['encryption', 'encrypt', 'tls', 'aes', 'key management', 'at rest', 'in transit'],
82
+ priority: 8,
83
+ requiresAnswer: ['security:compliance-data'],
84
+ },
85
+ {
86
+ text: 'What is the data retention and deletion policy? (regulatory minimum retention, user right-to-delete, archival/backup considerations)',
87
+ signals: ['gdpr', 'pii', 'privacy', 'compliance', 'data', 'retention', 'deletion', 'archive', 'backup', 'right-to-delete'],
88
+ priority: 7,
89
+ requiresAnswer: ['security:compliance-data'],
90
+ conditional: { 'security:compliance-data': 'gdpr' },
91
+ },
92
+ {
93
+ text: 'Is data minimization enforced by design? Are collected fields strictly necessary for the feature to function?',
94
+ signals: ['pii', 'privacy', 'gdpr', 'data', 'minimization', 'compliance'],
95
+ priority: 7,
96
+ requiresAnswer: ['security:compliance-data'],
97
+ },
98
+ // ── Tier 3: 威胁建模与攻击面 (priority 8) ──────────────
99
+ {
100
+ text: 'What is the threat model? Who are the likely attackers (script kiddies, organized crime, nation-state) and what do they want?',
101
+ id: 'threat-model',
102
+ signals: ['threat', 'attack', 'security', 'vulnerability', 'penetration', 'audit', 'threat model'],
103
+ priority: 8,
104
+ },
105
+ {
106
+ text: 'What is the attack surface of this change? Which user inputs, API endpoints, and third-party interfaces are exposed?',
107
+ signals: ['attack', 'threat', 'security', 'vulnerability', 'api', 'endpoint', 'surface', 'input'],
108
+ priority: 8,
109
+ requiresAnswer: ['security:threat-model'],
110
+ },
111
+ // ── Tier 4: 第三方集成安全 (priority 7-8) ──────────────
112
+ {
113
+ text: 'Are there third-party integrations that receive or process sensitive data? What is the data-sharing agreement and scope?',
114
+ id: 'third-party',
115
+ signals: ['integration', 'third-party', 'api', 'payment', 'billing', 'sensitive', 'vendor', 'saas'],
116
+ priority: 8,
117
+ },
118
+ {
119
+ text: 'Does the integration surface handle webhooks, callbacks, or redirect URIs from untrusted sources? How are they validated?',
120
+ signals: ['integration', 'webhook', 'callback', 'redirect', 'oauth', 'sso', 'uri', 'untrusted'],
121
+ priority: 7,
122
+ requiresAnswer: ['security:third-party'],
123
+ },
124
+ {
125
+ text: 'What is the vendor/third-party security review process? Are SOC2 reports or penetration test results available?',
126
+ signals: ['third-party', 'vendor', 'integration', 'security', 'soc2', 'audit', 'review'],
127
+ priority: 6,
128
+ requiresAnswer: ['security:third-party'],
129
+ },
130
+ // ── Tier 5: 密钥管理 (priority 8) ──────────────────────
131
+ {
132
+ text: 'How will secrets (API keys, DB passwords, signing keys, certificates) be managed, stored, and rotated?',
133
+ id: 'secrets-mgmt',
134
+ signals: ['secret', 'key management', 'api key', 'password', 'credential', 'encryption', 'rotation', 'certificate', 'signing'],
135
+ priority: 8,
136
+ },
137
+ {
138
+ text: 'Is there a secret rotation plan with defined frequency? Is rotation tested in staging before production?',
139
+ signals: ['secret', 'rotation', 'key management', 'credential', 'staging', 'production'],
140
+ priority: 7,
141
+ requiresAnswer: ['security:secrets-mgmt'],
142
+ },
143
+ {
144
+ text: 'Where do secrets live at runtime? (env vars, vault, KMS, secrets manager) — are they ever logged or included in error messages?',
145
+ signals: ['secret', 'key management', 'env', 'vault', 'kms', 'log', 'error', 'runtime'],
146
+ priority: 7,
147
+ requiresAnswer: ['security:secrets-mgmt'],
148
+ },
149
+ // ── Tier 6: 注入防护 (priority 8) ──────────────────────
150
+ {
151
+ text: 'What SQL/NoSQL injection prevention is in place? Are all queries parameterized with no string concatenation?',
152
+ signals: ['sql', 'injection', 'nosql', 'database', 'query', 'parameterized', 'orm', 'prepared statement'],
153
+ priority: 8,
154
+ },
155
+ {
156
+ text: 'How is XSS prevented? Is output encoding context-specific (HTML, JS, URL, CSS)? Is CSP configured with nonce-based script-src?',
157
+ signals: ['xss', 'injection', 'output encoding', 'csp', 'sanitize', 'dompurify', 'nonce', 'script'],
158
+ priority: 8,
159
+ },
160
+ {
161
+ text: 'How are file uploads validated? (MIME type inspection, size limits, file extension allowlist, store outside web root)',
162
+ signals: ['file upload', 'injection', 'validation', 'mime', 'size limit', 'extension'],
163
+ priority: 7,
164
+ },
165
+ // ── Tier 7: CSRF / CORS / 安全标头 (priority 7) ────────
166
+ {
167
+ text: 'Is CSRF protection needed? (SameSite=Strict cookies, CSRF tokens on state-changing requests, custom header requirement)',
168
+ signals: ['csrf', 'cookie', 'samesite', 'token', 'state', 'form', 'cross-site'],
169
+ priority: 7,
170
+ },
171
+ {
172
+ text: 'What is the CORS policy? Are origins explicitly allowlisted (no * with credentials)? Are preflight requests handled?',
173
+ signals: ['cors', 'cross-origin', 'origin', 'allowlist', 'preflight', 'credentials', 'api'],
174
+ priority: 7,
175
+ },
176
+ {
177
+ text: 'Which security headers will be enforced? (HSTS, CSP, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy)',
178
+ signals: ['security headers', 'hsts', 'csp', 'x-content-type-options', 'x-frame-options', 'referrer-policy', 'permissions-policy'],
179
+ priority: 7,
180
+ },
181
+ // ── Tier 8: 日志与监控 (priority 7) ────────────────────
182
+ {
183
+ text: 'What is the audit logging strategy for auth events, data mutations, and admin actions? Are logs immutable and tamper-proof?',
184
+ id: 'audit-logging',
185
+ signals: ['audit', 'logging', 'log', 'monitoring', 'auth', 'admin', 'mutation', 'immutable', 'tamper'],
186
+ priority: 7,
187
+ },
188
+ {
189
+ text: 'Are sensitive fields (passwords, tokens, full PII) redacted or excluded from logs? Is structured logging with sensitivity tags used?',
190
+ signals: ['logging', 'log', 'pii', 'sensitive', 'redact', 'token', 'password', 'structured'],
191
+ priority: 7,
192
+ requiresAnswer: ['security:audit-logging'],
193
+ },
194
+ {
195
+ text: 'How are security incidents detected and alerted? Is there an anomaly detection or rate-limit alerting pipeline?',
196
+ signals: ['monitoring', 'alert', 'incident', 'anomaly', 'rate limit', 'detection', 'siem'],
197
+ priority: 6,
198
+ },
199
+ // ── Tier 9: 依赖安全 (priority 6-7) ────────────────────
200
+ {
201
+ text: 'How are dependencies scanned for known vulnerabilities? (npm audit, Snyk, Dependabot, OWASP Dependency-Check) — is CI gating on CRITICAL?',
202
+ id: 'dep-scan',
203
+ signals: ['dependency', 'cve', 'npm audit', 'snyk', 'dependabot', 'vulnerability', 'scan', 'ci', 'supply chain'],
204
+ priority: 7,
205
+ },
206
+ {
207
+ text: 'Are third-party libraries pinned to exact versions? Is there a process for reviewing new dependencies before adoption?',
208
+ signals: ['dependency', 'version', 'pin', 'lock', 'library', 'third-party', 'supply chain'],
209
+ priority: 6,
210
+ requiresAnswer: ['security:dep-scan'],
211
+ },
212
+ // ── Tier 10: 安全配置与开发实践 (priority 5-6) ──────────
213
+ {
214
+ text: 'Are default credentials and unnecessary features disabled in production configuration? Is there a production hardening checklist?',
215
+ signals: ['configuration', 'default', 'production', 'harden', 'disable', 'misconfiguration'],
216
+ priority: 6,
217
+ },
218
+ {
219
+ text: 'How is the admin panel or privileged interface protected? (IP allowlisting, separate auth, access logging, session timeout)',
220
+ signals: ['admin', 'privilege', 'panel', 'ip', 'allowlist', 'auth', 'session'],
221
+ priority: 6,
222
+ },
223
+ {
224
+ text: 'Is there a security review gate in the development workflow? When is a full penetration test or external audit required?',
225
+ signals: ['security', 'review', 'audit', 'penetration', 'gate', 'workflow', 'sdlc'],
226
+ priority: 5,
227
+ },
228
+ {
229
+ text: 'What is the error handling strategy for security failures? (no stack traces in responses, generic messages, server-side logging)',
230
+ signals: ['error', 'security', 'stack trace', 'response', 'logging', 'failure', 'exception'],
231
+ priority: 6,
232
+ },
233
+ {
234
+ text: 'How are rate limits configured for auth endpoints and public APIs? (per-IP, per-user, burst vs sustained; 429 response format)',
235
+ signals: ['rate limit', 'throttle', 'brute force', 'auth', 'api', '429', 'ddos', 'dos'],
236
+ priority: 6,
237
+ },
238
+ ],
239
+ },
240
+ },
241
+ // ── Design: 设计阶段 ─────────────────────────────────────
242
+ design: {
243
+ checklist: [
244
+ // OWASP Top 10 — 从 security-hardening 表格提取
245
+ 'Injection: All database queries use parameterized statements; no string concatenation',
246
+ 'Broken Authentication: Session timeout defined; MFA for sensitive operations; password policy enforced',
247
+ 'Sensitive Data Exposure: Encryption at rest (AES-256-GCM) and in transit (TLS 1.3); PII minimized',
248
+ 'XXE: XML parsers configured with DTD/entity expansion disabled; prefer JSON where possible',
249
+ 'Broken Access Control: Server-side authorization check on every endpoint; IDOR prevention via ownership validation',
250
+ 'Security Misconfiguration: No default credentials; unnecessary features disabled; verbose errors suppressed in production',
251
+ 'XSS: Output encoding for all user-generated content; CSP header with nonce-based script-src',
252
+ 'Insecure Deserialization: Type constraints and integrity checks on deserialized data; allowlist for accepted types',
253
+ 'Components with Known Vulnerabilities: Dependency scanning in CI; automated update policy for CVEs',
254
+ 'Insufficient Logging & Monitoring: Audit trail for auth events, data mutations, admin actions; no sensitive data in logs',
255
+ // 安全标头 — 从 security-hardening 示例提取
256
+ 'HSTS header set: max-age=31536000; includeSubDomains',
257
+ 'CSP header: default-src self; script-src with nonce; no unsafe-inline',
258
+ 'X-Content-Type-Options: nosniff',
259
+ 'X-Frame-Options: DENY (or SAMEORIGIN if iframes needed)',
260
+ 'Referrer-Policy: strict-origin-when-cross-origin',
261
+ 'Permissions-Policy: restrict camera, microphone, geolocation to minimum',
262
+ // 基础架构安全
263
+ 'CORS configured with explicit allowed origins (no * with credentials)',
264
+ 'Rate limiting on all auth endpoints (login, signup, password reset)',
265
+ 'API has request size limits and timeout configurations',
266
+ 'CSRF tokens on all state-changing requests (or SameSite=Strict cookies)',
267
+ // 审计关注 — 从 security-auditor 提取
268
+ 'Authentication/authorization boundaries clearly drawn and documented',
269
+ 'Privilege escalation paths analyzed and blocked',
270
+ 'Secret handling surfaces mapped (code, config, CI, logs, runtime env)',
271
+ 'Supply-chain trust boundaries identified (npm/pip dependencies, build tools, base images)',
272
+ ],
273
+ patterns: {
274
+ 'Defense in Depth': 'Layer multiple controls: network (firewall, WAF) → application (auth, input validation) → data (encryption, backups). No single control failure should compromise the system.',
275
+ 'Principle of Least Privilege': 'Every component, service account, and user should have the minimum permissions needed. Use short-lived credentials where possible.',
276
+ 'Secure by Default': 'Default-deny for all access; explicitly grant permissions per role. Default configurations should be the most secure option.',
277
+ 'JWT with Refresh Token Rotation': 'Short-lived access tokens (15 min) + longer refresh tokens. Rotate refresh token on each use; detect and revoke stolen refresh tokens via reuse detection.',
278
+ 'Security Headers Middleware': 'Apply HSTS, CSP, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy globally via middleware — not per-route. One audit point.',
279
+ 'OWASP ASVS Level 2': 'For applications handling sensitive data, align with OWASP Application Security Verification Standard Level 2 as a design baseline.',
280
+ },
281
+ antiPatterns: [
282
+ 'Rolling your own cryptographic algorithm or protocol — use well-audited libraries (libsodium, WebCrypto API, bcrypt for passwords)',
283
+ 'Client-side only authorization checks — the server must independently verify permissions on every request',
284
+ 'Storing secrets in source code, config files, or environment variables committed to git — use a secret manager (Vault, AWS Secrets Manager, Doppler)',
285
+ 'Logging sensitive data (passwords, tokens, full PII) in application logs — redact or hash before logging; use structured logging with sensitivity tags',
286
+ 'Overly permissive CORS (Access-Control-Allow-Origin: * with credentials) — restrict to explicit, validated origins',
287
+ 'Trusting user-supplied URLs for redirects without validation — validate against an allowlist of safe destinations',
288
+ 'Using deprecated hash algorithms (MD5, SHA-1) for security purposes — use bcrypt/scrypt/argon2 for passwords, SHA-256+ for integrity',
289
+ ],
290
+ },
291
+ // ── Implement: 实施阶段 ──────────────────────────────────
292
+ implement: {
293
+ focusAreas: [
294
+ // 从 security-hardening audit workflow + security-auditor focus areas 提取
295
+ 'Input validation: every API endpoint validates type, format, length, and business rules before processing',
296
+ 'Output encoding: all user-generated content encoded before rendering (context-specific: HTML, JS, URL, CSS)',
297
+ 'SQL injection prevention: parameterized queries 100% of the time; ORM raw queries audited',
298
+ 'Authentication flow: token generation, storage (secure+httpOnly+SameSite), refresh, revocation all tested',
299
+ 'Authorization: role checks at every endpoint, not just UI hiding; test with different role accounts',
300
+ 'Secrets handling: no secrets in code; env vars validated at startup; secret rotation tested',
301
+ 'Error handling: user-facing errors reveal nothing about internals; stack traces logged server-side only',
302
+ 'File upload: validate MIME type (not just extension), size limits enforced server-side, store outside web root',
303
+ 'Dependency audit: run npm audit / pip audit; block builds on HIGH or CRITICAL CVEs',
304
+ 'Cryptographic usage: verify algorithm choice, key length, IV/nonce handling, and padding for every crypto call',
305
+ // 从 security-auditor working mode + quality checks 提取
306
+ 'Map failure surface before implementing: which user inputs reach this code? what can go wrong?',
307
+ 'Separate confirmed vulnerability from hypothesis: test each suspected issue before reporting',
308
+ 'Verify one normal path, one failure path, and one privilege escalation attempt per auth change',
309
+ 'For each finding, state: attack path → impact → exploitation prerequisites → remediation',
310
+ ],
311
+ patterns: {
312
+ 'Input Validation Chain': 'Validation middleware: check type → validate format → enforce business rules → sanitize. Reject early at the boundary; never pass raw input to business logic.',
313
+ 'Parametrized Query Audit': 'Grep for string concatenation near SQL keywords (SELECT, INSERT, UPDATE, DELETE, WHERE) before every commit. Add to pre-commit hook.',
314
+ 'Secret Rotation Script': 'Every secret should have a documented rotation procedure. Implement a /health endpoint that reports secret age; alert if approaching expiry.',
315
+ 'OWASP Dependency Check in CI': 'Run dependency scanning in CI pipeline. Fail build on CRITICAL. File ticket automatically on HIGH. Update within SLA per severity.',
316
+ },
317
+ antiPatterns: [
318
+ 'Using innerHTML, dangerouslySetInnerHTML, or document.write with user-controlled data — use textContent or a sanitizer (DOMPurify)',
319
+ 'Building SQL queries with string concatenation or template literals — use query builders or parameterized queries',
320
+ 'Trusting client-side validation — always re-validate on the server',
321
+ 'Hardcoding API keys, tokens, or database passwords — use environment variables validated at startup',
322
+ 'Disabling security features for development ("temporarily") and forgetting to re-enable — security config should be environment-aware, not environment-specific',
323
+ 'Catching all errors with a generic try/catch and returning 200 OK — use proper HTTP status codes (401, 403, 404, 422, 500)',
324
+ 'Using default or weak secrets in production (admin/admin, default JWT secret) — generate unique secrets per environment',
325
+ ],
326
+ },
327
+ // ── Verify: 验证阶段 ─────────────────────────────────────
328
+ verify: {
329
+ checklist: [
330
+ // 认证/授权验证
331
+ 'All auth endpoints have rate limiting (login, signup, password reset, MFA, token refresh)',
332
+ 'Session tokens use secure + httpOnly + SameSite=Strict flags',
333
+ 'JWT tokens use RS256 or HS256 with key length ≥ 256 bits; no "none" algorithm allowed',
334
+ 'Password reset flow: time-limited tokens, email verification, no user enumeration in responses',
335
+ 'MFA enrollment and recovery flows tested end-to-end',
336
+ // 注入防护验证
337
+ 'All SQL queries use parameterized statements (grep for string concatenation near SQL keywords)',
338
+ 'No user input rendered without encoding (grep for innerHTML, dangerouslySetInnerHTML, document.write)',
339
+ 'File upload endpoints validate MIME type by content inspection, not just extension',
340
+ // 配置验证
341
+ 'CSP header present and not using unsafe-inline or unsafe-eval',
342
+ 'HSTS header set with max-age ≥ 1 year (31536000)',
343
+ 'No hardcoded secrets in codebase (grep for common patterns: api_key, secret, password, token =)',
344
+ 'CORS configuration restricts to explicit origins (no * with credentials)',
345
+ // 依赖验证
346
+ 'Dependencies pass npm audit / pip audit with zero HIGH or CRITICAL',
347
+ 'All production dependencies pinned to exact versions (no ^ or ~ ranges)',
348
+ // 运行时验证
349
+ 'Error responses contain no stack traces, internal paths, or debug information',
350
+ 'Security headers present on all responses (verify with curl -I or browser devtools)',
351
+ 'TLS 1.2+ enforced; HTTP redirected to HTTPS; HSTS preload considered',
352
+ // 审计验证 — 从 security-auditor quality checks 提取
353
+ 'For each security finding: attack path, impact, and exploitation prerequisites are documented',
354
+ 'Mitigation guidance for each finding is specific and operationally feasible',
355
+ 'High-severity items include immediate containment steps (WAF rule, feature flag, config change)',
356
+ 'Verification steps that require runtime or environment access are explicitly called out',
357
+ 'Residual risk after remediation is assessed and documented',
358
+ // 变更安全
359
+ 'No new secrets introduced without rotation plan',
360
+ 'Authorization rules tested with at least 2 role accounts (admin + regular user)',
361
+ ],
362
+ },
363
+ };
364
+ //# sourceMappingURL=security.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.js","sourceRoot":"","sources":["../../src/domains/security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,CAAC,MAAM,cAAc,GAAiB;IAC1C,IAAI,EAAE,UAAU;IAChB,WAAW,EACT,iGAAiG;IAEnG,yDAAyD;IAEzD,OAAO,EAAE;QACP,OAAO,EAAE;YACP,QAAQ;YACR,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM;YAC9D,OAAO,EAAE,QAAQ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G;YAC3G,6GAA6G;YAC7G,2FAA2F;YAC3F,2GAA2G;YAC3G,qGAAqG;YACrG,6FAA6F;YAC7F,yGAAyG;YACzG,gHAAgH;YAChH,oFAAoF;YACpF,gHAAgH;YAEhH,sDAAsD;YACtD,gGAAgG;YAChG,8FAA8F;YAC9F,gGAAgG;YAChG,0FAA0F;SAC3F;QAED,QAAQ,EAAE;YACR,wBAAwB,EACtB,gKAAgK;YAClK,0BAA0B,EACxB,sIAAsI;YACxI,wBAAwB,EACtB,8IAA8I;YAChJ,8BAA8B,EAC5B,oIAAoI;SACvI;QAED,YAAY,EAAE;YACZ,oIAAoI;YACpI,mHAAmH;YACnH,oEAAoE;YACpE,qGAAqG;YACrG,iKAAiK;YACjK,4HAA4H;YAC5H,yHAAyH;SAC1H;KACF;IAED,wDAAwD;IAExD,MAAM,EAAE;QACN,SAAS,EAAE;YACT,UAAU;YACV,2FAA2F;YAC3F,8DAA8D;YAC9D,uFAAuF;YACvF,gGAAgG;YAChG,qDAAqD;YAErD,SAAS;YACT,gGAAgG;YAChG,uGAAuG;YACvG,oFAAoF;YAEpF,OAAO;YACP,+DAA+D;YAC/D,kDAAkD;YAClD,iGAAiG;YACjG,0EAA0E;YAE1E,OAAO;YACP,oEAAoE;YACpE,yEAAyE;YAEzE,QAAQ;YACR,+EAA+E;YAC/E,qFAAqF;YACrF,sEAAsE;YAEtE,8CAA8C;YAC9C,+FAA+F;YAC/F,6EAA6E;YAC7E,iGAAiG;YACjG,yFAAyF;YACzF,4DAA4D;YAE5D,OAAO;YACP,iDAAiD;YACjD,iFAAiF;SAClF;KACF;CACF,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Signal Match Utility
3
+ *
4
+ * 提取自 domains/index.ts 的纯函数分词和信号匹配逻辑。
5
+ * 供 domains/index.ts 和 domains/pool-ranking.ts 共同引用,避免循环依赖。
6
+ */
7
+ /** 分词的分割字符集 */
8
+ export declare const TOKENIZE_SPLIT_CHARS: RegExp;
9
+ /** 短信号最小长度:低于此值的信号仅做精确 token 匹配,不做子串匹配 */
10
+ export declare const MIN_SIGNAL_LENGTH_FOR_SUBSTRING = 4;
11
+ /**
12
+ * 分词:小写 → 按非字母数字边界拆分 → 过滤停用词和短词 → 去重
13
+ */
14
+ export declare function tokenize(text: string): string[];
15
+ /**
16
+ * 判断单个 signal 是否匹配当前输入。
17
+ *
18
+ * 匹配规则(按优先级):
19
+ * 1. 含空格的信号 → 直接在原始输入中做子串匹配
20
+ * 2. 含 tokenize 分割符但不含空格的信号 (e.g. "n+1") → 原始输入子串匹配
21
+ * 3. 短信号 (< MIN_SIGNAL_LENGTH_FOR_SUBSTRING 字符) → 仅精确 token 匹配
22
+ * 4. 普通信号 → token 包含 signal,或较长 token 作为 signal 前缀
23
+ */
24
+ export declare function signalMatchesToken(signal: string, lowerInput: string, tokens: string[]): boolean;
25
+ //# sourceMappingURL=signal-match.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-match.d.ts","sourceRoot":"","sources":["../../src/domains/signal-match.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAe;AACf,eAAO,MAAM,oBAAoB,QAA4C,CAAC;AAE9E,0CAA0C;AAC1C,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAajD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAmB/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EAAE,GACf,OAAO,CAwBT"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Signal Match Utility
3
+ *
4
+ * 提取自 domains/index.ts 的纯函数分词和信号匹配逻辑。
5
+ * 供 domains/index.ts 和 domains/pool-ranking.ts 共同引用,避免循环依赖。
6
+ */
7
+ /** 分词的分割字符集 */
8
+ export const TOKENIZE_SPLIT_CHARS = /[\s,.;:!?()\[\]{}<>/\\|`'"@#$%^&*+=~_-]/;
9
+ /** 短信号最小长度:低于此值的信号仅做精确 token 匹配,不做子串匹配 */
10
+ export const MIN_SIGNAL_LENGTH_FOR_SUBSTRING = 4;
11
+ /** 英文停用词 — 不参与匹配的常见功能词 */
12
+ const STOP_WORDS = new Set([
13
+ 'a', 'an', 'the', 'is', 'are', 'be', 'to', 'of', 'in', 'for',
14
+ 'on', 'with', 'and', 'or', 'but', 'not', 'this', 'that', 'it',
15
+ 'we', 'you', 'i', 'my', 'our', 'your', 'me', 'us',
16
+ 'need', 'want', 'should', 'would', 'could', 'can', 'will',
17
+ 'add', 'create', 'make', 'build', 'implement', 'fix', 'change',
18
+ 'do', 'does', 'get', 'set', 'use', 'using', 'have', 'has',
19
+ 'new', 'like', 'just', 'also', 'now', 'then', 'than',
20
+ ]);
21
+ /**
22
+ * 分词:小写 → 按非字母数字边界拆分 → 过滤停用词和短词 → 去重
23
+ */
24
+ export function tokenize(text) {
25
+ const seen = new Set();
26
+ const tokens = [];
27
+ for (const raw of text.split(TOKENIZE_SPLIT_CHARS)) {
28
+ const token = raw.toLowerCase();
29
+ if (token.length < 2 ||
30
+ STOP_WORDS.has(token) ||
31
+ /^\d+$/.test(token) || // 纯数字
32
+ seen.has(token)) {
33
+ continue;
34
+ }
35
+ seen.add(token);
36
+ tokens.push(token);
37
+ }
38
+ return tokens;
39
+ }
40
+ /**
41
+ * 判断单个 signal 是否匹配当前输入。
42
+ *
43
+ * 匹配规则(按优先级):
44
+ * 1. 含空格的信号 → 直接在原始输入中做子串匹配
45
+ * 2. 含 tokenize 分割符但不含空格的信号 (e.g. "n+1") → 原始输入子串匹配
46
+ * 3. 短信号 (< MIN_SIGNAL_LENGTH_FOR_SUBSTRING 字符) → 仅精确 token 匹配
47
+ * 4. 普通信号 → token 包含 signal,或较长 token 作为 signal 前缀
48
+ */
49
+ export function signalMatchesToken(signal, lowerInput, tokens) {
50
+ const s = signal.toLowerCase();
51
+ // 含空格的多词信号: 直接在原始输入中做子串匹配
52
+ if (s.includes(' ')) {
53
+ return lowerInput.includes(s);
54
+ }
55
+ // 含 tokenize 分割符的信号: 直接在原始输入中做子串匹配
56
+ if (TOKENIZE_SPLIT_CHARS.test(s)) {
57
+ return lowerInput.includes(s);
58
+ }
59
+ // 短信号: 仅精确 token 匹配,防止缩写误匹配
60
+ if (s.length < MIN_SIGNAL_LENGTH_FOR_SUBSTRING) {
61
+ return tokens.some((token) => token === s);
62
+ }
63
+ // 单词信号
64
+ return tokens.some((token) => token.includes(s) ||
65
+ (token.length >= 4 && s.startsWith(token)));
66
+ }
67
+ //# sourceMappingURL=signal-match.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-match.js","sourceRoot":"","sources":["../../src/domains/signal-match.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAe;AACf,MAAM,CAAC,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;AAE9E,0CAA0C;AAC1C,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC;AAEjD,0BAA0B;AAC1B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK;IAC5D,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI;IAC7D,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;IACjD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM;IACzD,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ;IAC9D,IAAI,EAAE,MAAM,EAAE,KAAK,E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