invar-tools 1.8.0__py3-none-any.whl → 1.11.0__py3-none-any.whl

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 (117) hide show
  1. invar/__init__.py +8 -0
  2. invar/core/doc_edit.py +187 -0
  3. invar/core/doc_parser.py +563 -0
  4. invar/core/language.py +88 -0
  5. invar/core/models.py +106 -0
  6. invar/core/patterns/detector.py +6 -1
  7. invar/core/patterns/p0_exhaustive.py +15 -3
  8. invar/core/patterns/p0_literal.py +15 -3
  9. invar/core/patterns/p0_newtype.py +15 -3
  10. invar/core/patterns/p0_nonempty.py +15 -3
  11. invar/core/patterns/p0_validation.py +15 -3
  12. invar/core/patterns/registry.py +5 -1
  13. invar/core/patterns/types.py +5 -1
  14. invar/core/property_gen.py +4 -0
  15. invar/core/rules.py +84 -18
  16. invar/core/sync_helpers.py +27 -1
  17. invar/core/ts_parsers.py +286 -0
  18. invar/core/ts_sig_parser.py +310 -0
  19. invar/mcp/handlers.py +408 -0
  20. invar/mcp/server.py +288 -143
  21. invar/node_tools/MANIFEST +7 -0
  22. invar/node_tools/__init__.py +51 -0
  23. invar/node_tools/fc-runner/cli.js +77 -0
  24. invar/node_tools/quick-check/cli.js +28 -0
  25. invar/node_tools/ts-analyzer/cli.js +480 -0
  26. invar/shell/claude_hooks.py +35 -12
  27. invar/shell/commands/doc.py +409 -0
  28. invar/shell/commands/guard.py +41 -1
  29. invar/shell/commands/init.py +154 -16
  30. invar/shell/commands/perception.py +157 -33
  31. invar/shell/commands/skill.py +187 -0
  32. invar/shell/commands/template_sync.py +65 -13
  33. invar/shell/commands/uninstall.py +60 -12
  34. invar/shell/commands/update.py +6 -14
  35. invar/shell/contract_coverage.py +1 -0
  36. invar/shell/doc_tools.py +459 -0
  37. invar/shell/fs.py +67 -13
  38. invar/shell/pi_hooks.py +6 -0
  39. invar/shell/prove/crosshair.py +3 -0
  40. invar/shell/prove/guard_ts.py +902 -0
  41. invar/shell/skill_manager.py +355 -0
  42. invar/shell/template_engine.py +28 -4
  43. invar/shell/templates.py +4 -4
  44. invar/templates/claude-md/python/critical-rules.md +33 -0
  45. invar/templates/claude-md/python/quick-reference.md +24 -0
  46. invar/templates/claude-md/typescript/critical-rules.md +40 -0
  47. invar/templates/claude-md/typescript/quick-reference.md +24 -0
  48. invar/templates/claude-md/universal/check-in.md +25 -0
  49. invar/templates/claude-md/universal/skills.md +73 -0
  50. invar/templates/claude-md/universal/workflow.md +55 -0
  51. invar/templates/commands/{audit.md → audit.md.jinja} +18 -1
  52. invar/templates/config/AGENT.md.jinja +58 -0
  53. invar/templates/config/CLAUDE.md.jinja +16 -209
  54. invar/templates/config/context.md.jinja +19 -0
  55. invar/templates/examples/{README.md → python/README.md} +2 -0
  56. invar/templates/examples/{conftest.py → python/conftest.py} +1 -1
  57. invar/templates/examples/{contracts.py → python/contracts.py} +81 -4
  58. invar/templates/examples/python/core_shell.py +227 -0
  59. invar/templates/examples/python/functional.py +613 -0
  60. invar/templates/examples/typescript/README.md +31 -0
  61. invar/templates/examples/typescript/contracts.ts +163 -0
  62. invar/templates/examples/typescript/core_shell.ts +374 -0
  63. invar/templates/examples/typescript/functional.ts +601 -0
  64. invar/templates/examples/typescript/workflow.md +95 -0
  65. invar/templates/hooks/PostToolUse.sh.jinja +10 -1
  66. invar/templates/hooks/PreToolUse.sh.jinja +38 -0
  67. invar/templates/hooks/Stop.sh.jinja +1 -1
  68. invar/templates/hooks/UserPromptSubmit.sh.jinja +7 -0
  69. invar/templates/hooks/pi/invar.ts.jinja +9 -0
  70. invar/templates/manifest.toml +7 -6
  71. invar/templates/onboard/assessment.md.jinja +214 -0
  72. invar/templates/onboard/patterns/python.md +347 -0
  73. invar/templates/onboard/patterns/typescript.md +452 -0
  74. invar/templates/onboard/roadmap.md.jinja +168 -0
  75. invar/templates/protocol/INVAR.md.jinja +51 -0
  76. invar/templates/protocol/python/architecture-examples.md +41 -0
  77. invar/templates/protocol/python/contracts-syntax.md +56 -0
  78. invar/templates/protocol/python/markers.md +44 -0
  79. invar/templates/protocol/python/tools.md +24 -0
  80. invar/templates/protocol/python/troubleshooting.md +38 -0
  81. invar/templates/protocol/typescript/architecture-examples.md +52 -0
  82. invar/templates/protocol/typescript/contracts-syntax.md +73 -0
  83. invar/templates/protocol/typescript/markers.md +48 -0
  84. invar/templates/protocol/typescript/tools.md +65 -0
  85. invar/templates/protocol/typescript/troubleshooting.md +104 -0
  86. invar/templates/protocol/universal/architecture.md +36 -0
  87. invar/templates/protocol/universal/completion.md +14 -0
  88. invar/templates/protocol/universal/contracts-concept.md +37 -0
  89. invar/templates/protocol/universal/header.md +17 -0
  90. invar/templates/protocol/universal/session.md +17 -0
  91. invar/templates/protocol/universal/six-laws.md +10 -0
  92. invar/templates/protocol/universal/usbv.md +14 -0
  93. invar/templates/protocol/universal/visible-workflow.md +25 -0
  94. invar/templates/skills/develop/SKILL.md.jinja +85 -3
  95. invar/templates/skills/extensions/_registry.yaml +93 -0
  96. invar/templates/skills/extensions/acceptance/SKILL.md +383 -0
  97. invar/templates/skills/extensions/invar-onboard/SKILL.md +448 -0
  98. invar/templates/skills/extensions/invar-onboard/patterns/python.md +347 -0
  99. invar/templates/skills/extensions/invar-onboard/patterns/typescript.md +452 -0
  100. invar/templates/skills/extensions/invar-onboard/templates/assessment.md.jinja +214 -0
  101. invar/templates/skills/extensions/invar-onboard/templates/roadmap.md.jinja +168 -0
  102. invar/templates/skills/extensions/security/SKILL.md +382 -0
  103. invar/templates/skills/extensions/security/patterns/_common.yaml +126 -0
  104. invar/templates/skills/extensions/security/patterns/python.yaml +155 -0
  105. invar/templates/skills/extensions/security/patterns/typescript.yaml +194 -0
  106. invar/templates/skills/review/SKILL.md.jinja +220 -248
  107. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/METADATA +336 -12
  108. invar_tools-1.11.0.dist-info/RECORD +178 -0
  109. invar/templates/examples/core_shell.py +0 -127
  110. invar/templates/protocol/INVAR.md +0 -310
  111. invar_tools-1.8.0.dist-info/RECORD +0 -116
  112. /invar/templates/examples/{workflow.md → python/workflow.md} +0 -0
  113. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/WHEEL +0 -0
  114. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/entry_points.txt +0 -0
  115. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/licenses/LICENSE +0 -0
  116. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/licenses/LICENSE-GPL +0 -0
  117. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,168 @@
1
+ {#
2
+ Expected variables:
3
+ - project_name: str
4
+ - timestamp: str
5
+ - total_days: int
6
+ - session_count: int
7
+ - phases: list of {id: str, name: str, days: int, objective: str,
8
+ tasks: [{day: int, files: [str], scope: str}],
9
+ sessions: [{files: [str], estimate: str}],
10
+ gates: [str], verification_command?: str, rollback_action?: str}
11
+ - result_library: str
12
+ - install_command: str
13
+ - additional_deps?: [{name: str, purpose: str, install: str}]
14
+ - target_coverage?: int (default 80)
15
+ - dependency_graph?: str
16
+ - notes?: str
17
+ #}
18
+ # Invar Onboarding Roadmap
19
+
20
+ > Project: {{ project_name }}
21
+ > Generated: {{ timestamp }}
22
+ > Based on: docs/invar-onboard-assessment.md
23
+
24
+ ## Overview
25
+
26
+ | Metric | Value |
27
+ |--------|-------|
28
+ | Total Phases | {{ phases | length }} |
29
+ | Total Days | {{ total_days }} |
30
+ | Agent Sessions | {{ session_count }} |
31
+
32
+ ---
33
+
34
+ {% for phase in phases %}
35
+ ## Phase {{ loop.index }}: {{ phase.name }} ({{ phase.days }} days)
36
+
37
+ ### Objective
38
+
39
+ {{ phase.objective }}
40
+
41
+ ### Tasks
42
+
43
+ | Day | Files | Scope |
44
+ |-----|-------|-------|
45
+ {% for task in phase.tasks %}
46
+ | {{ task.day }} | {{ task.files | join(", ") }} | {{ task.scope }} |
47
+ {% endfor %}
48
+
49
+ ### Sessions
50
+
51
+ | Session | Files | Estimated |
52
+ |---------|-------|-----------|
53
+ {% for session in phase.sessions %}
54
+ | {{ phase.id }}.{{ loop.index }} | {{ session.files | join(", ") }} | {{ session.estimate }} |
55
+ {% endfor %}
56
+
57
+ ### Gate Checklist
58
+
59
+ {% for gate in phase.gates %}
60
+ - [ ] {{ gate }}
61
+ {% endfor %}
62
+
63
+ ### Verification
64
+
65
+ ```bash
66
+ {{ phase.verification_command | default("invar guard") }}
67
+ ```
68
+
69
+ ---
70
+
71
+ {% endfor %}
72
+
73
+ ## Rollback Strategy
74
+
75
+ | Phase | Rollback Point | Recovery Action |
76
+ |-------|----------------|-----------------|
77
+ {% for phase in phases %}
78
+ | {{ loop.index }} | Pre-{{ phase.name }} | {{ phase.rollback_action | default("Revert " + phase.name + " changes") }} |
79
+ {% endfor %}
80
+
81
+ ## Session Guidelines
82
+
83
+ ### Context Limits
84
+
85
+ Each agent session should:
86
+ - Focus on 2-3 files maximum
87
+ - Complete within 1 context window
88
+ - End with successful `invar guard`
89
+
90
+ ### Handoff Protocol
91
+
92
+ 1. **Before session end:**
93
+ - Commit all changes
94
+ - Update this roadmap (mark completed)
95
+ - Document any deviations
96
+
97
+ 2. **Session start:**
98
+ - Read assessment and this roadmap
99
+ - Review previous session's changes
100
+ - Verify Guard passes before proceeding
101
+
102
+ ### Emergency Procedures
103
+
104
+ | Situation | Action |
105
+ |-----------|--------|
106
+ | Guard fails after changes | Revert to last passing commit |
107
+ | Unexpected dependency | Add to blockers, pause phase |
108
+ | Scope creep detected | Stop, update assessment |
109
+
110
+ ## Progress Tracking
111
+
112
+ ### Phase Status
113
+
114
+ | Phase | Status | Started | Completed | Notes |
115
+ |-------|--------|---------|-----------|-------|
116
+ {% for phase in phases %}
117
+ | {{ loop.index }}. {{ phase.name }} | ⬜ Pending | - | - | |
118
+ {% endfor %}
119
+
120
+ ### Session Log
121
+
122
+ | Session | Date | Duration | Files Changed | Guard | Notes |
123
+ |---------|------|----------|---------------|-------|-------|
124
+ | - | - | - | - | - | - |
125
+
126
+ ## Dependencies
127
+
128
+ ### External Libraries
129
+
130
+ | Library | Purpose | Install Command |
131
+ |---------|---------|-----------------|
132
+ | {{ result_library }} | Result types | {{ install_command }} |
133
+ {% for dep in additional_deps %}
134
+ | {{ dep.name }} | {{ dep.purpose }} | {{ dep.install }} |
135
+ {% endfor %}
136
+
137
+ ### Internal Dependencies
138
+
139
+ ```
140
+ {{ dependency_graph | default("No complex internal dependencies.") }}
141
+ ```
142
+
143
+ ## Success Criteria
144
+
145
+ ### Phase Completion
146
+
147
+ Each phase is complete when:
148
+ 1. All tasks checked off
149
+ 2. Gate checklist passed
150
+ 3. `invar guard` passes
151
+ 4. E2E tests still pass (if applicable)
152
+
153
+ ### Project Completion
154
+
155
+ Project migration complete when:
156
+ - [ ] All phases completed
157
+ - [ ] Full `invar guard` passes
158
+ - [ ] Contract coverage > {{ target_coverage | default(80) }}%
159
+ - [ ] All Core functions have doctests
160
+ - [ ] Shell functions return Result types
161
+
162
+ ## Notes
163
+
164
+ {{ notes | default("No additional notes.") }}
165
+
166
+ ---
167
+
168
+ *Generated by /invar-onboard*
@@ -0,0 +1,382 @@
1
+ <!--invar:skill-->
2
+ # /security — Security Audit
3
+
4
+ > Extension Skill | Tier: T0 | Isolation: Default
5
+
6
+ ## Purpose
7
+
8
+ Identify security vulnerabilities using OWASP Top 10 as baseline. This skill performs systematic security audits with evidence-based reporting.
9
+
10
+ ## Triggers
11
+
12
+ Use this skill when user says: "security", "audit", "vulnerabilities", "OWASP"
13
+
14
+ ## Relationship to Core Skills
15
+
16
+ - `/review` includes security as one checklist item
17
+ - `/security` is deep-dive security-focused audit
18
+
19
+ ---
20
+
21
+ ## Core Principles
22
+
23
+ | Principle | Description |
24
+ |-----------|-------------|
25
+ | **Assume vulnerable** | Every input is malicious until proven safe |
26
+ | **Defense in depth** | Check all layers, not just obvious entry points |
27
+ | **Evidence-based** | Report with file:line and exploitation scenario |
28
+ | **Context isolated** | Fresh perspective prevents "I know this is safe" bias |
29
+
30
+ ---
31
+
32
+ ## Depth Levels
33
+
34
+ | Level | Scope | Use Case |
35
+ |-------|-------|----------|
36
+ | `--quick` | A03 (Injection) only | Fast CI gate |
37
+ | `--standard` | A01-A05 (most common) | Regular development |
38
+ | `--deep` (default) | Full OWASP A01-A10 + isolated agent | Release audit |
39
+
40
+ **Default is `--deep`** — thorough security review is critical.
41
+
42
+ ---
43
+
44
+ ## Workflow
45
+
46
+ ### Step 0: Isolation Check
47
+
48
+ ```
49
+ Parse depth: --quick / --standard / --deep (default)
50
+
51
+ If --deep (default):
52
+ ┌─────────────────────────────────────────────────────────┐
53
+ │ SPAWN ISOLATED AGENT │
54
+ │ │
55
+ │ Collect inputs: │
56
+ │ • Code scope (files/directories to audit) │
57
+ │ • Dependency manifest (package.json, requirements.txt) │
58
+ │ • Config files (if any) │
59
+ │ │
60
+ │ Spawn Task agent with: │
61
+ │ • Security Auditor persona (see below) │
62
+ │ • NO conversation history │
63
+ │ • Only the collected inputs │
64
+ │ │
65
+ │ → Isolated agent executes steps 1-4 below │
66
+ │ → Returns structured security report │
67
+ └─────────────────────────────────────────────────────────┘
68
+
69
+ If --quick or --standard:
70
+ └─ Continue in same context with attacker mindset
71
+ ```
72
+
73
+ ### Step 1: Entry + External Tools
74
+
75
+ - Detect Invar (Enhanced/Standalone mode)
76
+ - Identify scope (full project or specific files)
77
+ - Run external security tools (if available)
78
+
79
+ **External Tool Detection:**
80
+ ```
81
+ package.json exists? → npm audit --json
82
+ requirements.txt exists? → pip-audit --format=json
83
+ go.mod exists? → govulncheck -json ./...
84
+ .git exists? → trufflehog git file://. --json (secrets)
85
+ ```
86
+
87
+ | Tool | OWASP Category | Command |
88
+ |------|----------------|---------|
89
+ | `npm audit` | A06 | `npm audit --json` |
90
+ | `pip-audit` | A06 | `pip-audit --format=json` |
91
+ | `govulncheck` | A06 | `govulncheck -json ./...` |
92
+ | `trufflehog` | A02 | `trufflehog git file://. --json` |
93
+ | `semgrep` | A01-A10 | `semgrep --config=auto --json` |
94
+
95
+ If tool not available → note in report, continue with manual analysis.
96
+
97
+ ### Step 2: Reconnaissance — Understand Attack Surface
98
+
99
+ Identify:
100
+ - **Entry points:** APIs, forms, file uploads
101
+ - **Data flows:** user input → storage → output
102
+ - **Auth points:** authentication/authorization checkpoints
103
+ - **Dependencies:** external libraries and services
104
+
105
+ **Enhanced Mode:** Use `invar_map` to find entry points
106
+ **Standalone:** Grep for route definitions, handlers
107
+
108
+ ### Step 3: OWASP Check — Systematic Vulnerability Scan
109
+
110
+ Check against OWASP Top 10 (2021):
111
+
112
+ #### A01: Broken Access Control
113
+ - [ ] Authorization checked on all endpoints?
114
+ - [ ] IDOR vulnerabilities?
115
+ - [ ] Missing function-level access control?
116
+
117
+ #### A02: Cryptographic Failures
118
+ - [ ] Sensitive data encrypted at rest?
119
+ - [ ] Weak algorithms (MD5, SHA1)?
120
+ - [ ] Hardcoded secrets?
121
+
122
+ #### A03: Injection
123
+ - [ ] SQL injection (raw queries)?
124
+ - [ ] Command injection (shell exec)?
125
+ - [ ] XSS (unescaped output)?
126
+
127
+ #### A04: Insecure Design
128
+ - [ ] Missing rate limiting?
129
+ - [ ] No account lockout?
130
+ - [ ] Predictable tokens?
131
+
132
+ #### A05: Security Misconfiguration
133
+ - [ ] Debug mode in production?
134
+ - [ ] Default credentials?
135
+ - [ ] Verbose error messages?
136
+
137
+ #### A06: Vulnerable Components
138
+ - [ ] Known CVEs in dependencies?
139
+ - [ ] Outdated packages?
140
+
141
+ #### A07: Authentication Failures
142
+ - [ ] Weak password policy?
143
+ - [ ] Missing MFA?
144
+ - [ ] Session fixation?
145
+
146
+ #### A08: Data Integrity Failures
147
+ - [ ] Unsigned data trusted?
148
+ - [ ] Deserialization of untrusted data?
149
+
150
+ #### A09: Logging Failures
151
+ - [ ] Security events logged?
152
+ - [ ] Sensitive data in logs?
153
+
154
+ #### A10: SSRF
155
+ - [ ] User-controlled URLs fetched?
156
+ - [ ] Internal network accessible?
157
+
158
+ **Use language-specific patterns from `patterns/` directory.**
159
+
160
+ ### Step 4: Evidence — Document Findings
161
+
162
+ For each finding, document:
163
+ - **Location:** file:line
164
+ - **Severity:** Critical/High/Medium/Low
165
+ - **Evidence:** Code snippet
166
+ - **Exploitation scenario:** How to exploit
167
+ - **Remediation:** How to fix
168
+
169
+ ### Step 5: Report — Security Audit Report
170
+
171
+ ```markdown
172
+ ## Security Audit Report
173
+
174
+ **Scope:** src/api/, src/auth/
175
+ **Date:** [date]
176
+ **Mode:** Enhanced / Standalone
177
+ **Depth:** --deep
178
+
179
+ ### External Tool Results
180
+ - npm audit: 2 vulnerabilities (1 high, 1 moderate)
181
+ - trufflehog: 0 secrets found
182
+
183
+ ### Summary
184
+ | Severity | Count |
185
+ |----------|-------|
186
+ | Critical | 1 |
187
+ | High | 2 |
188
+ | Medium | 3 |
189
+ | Low | 1 |
190
+
191
+ ### Critical Findings
192
+
193
+ **[CRITICAL] SQL Injection in user search**
194
+ - Location: api/users.py:45
195
+ - Evidence: `query = f"SELECT * FROM users WHERE name='{n}'"`
196
+ - Exploit: Input `' OR 1=1 --` returns all users
197
+ - Risk: Full database compromise
198
+ - Fix: Use parameterized queries
199
+
200
+ ### New Findings (not baselined)
201
+ | ID | Severity | Category | Location | Description |
202
+ |----|----------|----------|----------|-------------|
203
+ | SEC-001 | Critical | A03 | api/users.py:45 | SQL injection |
204
+
205
+ ### Baselined (suppressed)
206
+ | ID | Status | Reason |
207
+ |----|--------|--------|
208
+ | SEC-000 | false_positive | ORM handles escaping |
209
+
210
+ ### Recommendations
211
+ 1. [URGENT] Fix SQL injection
212
+ 2. Add rate limiting to login endpoint
213
+ 3. Implement account lockout
214
+
215
+ ### Statistics
216
+ - New findings: 7
217
+ - Baselined: 2
218
+ - Total tracked: 9
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Severity Classification
224
+
225
+ **Decision Tree:**
226
+ ```
227
+ Can attacker execute arbitrary code?
228
+
229
+ YES ─┴─ NO
230
+ │ │
231
+ ▼ ▼
232
+ CRITICAL Can read/write sensitive data?
233
+
234
+ YES ─┴─ NO
235
+ │ │
236
+ ▼ ▼
237
+ HIGH Can access limited data / disrupt service?
238
+
239
+ YES ─┴─ NO
240
+ │ │
241
+ ▼ ▼
242
+ MEDIUM LOW
243
+ ```
244
+
245
+ | Severity | Impact | Examples |
246
+ |----------|--------|----------|
247
+ | **Critical** | Complete system compromise | RCE, SQL injection (write), command injection |
248
+ | **High** | Significant data breach | SQL injection (read), stored XSS, session hijacking |
249
+ | **Medium** | Limited exposure | Reflected XSS, user enumeration, missing rate limiting |
250
+ | **Low** | Minimal direct impact | Missing security headers, debug info |
251
+
252
+ ---
253
+
254
+ ## False Positive Handling
255
+
256
+ Baseline file: `.invar/security-baseline.yaml`
257
+
258
+ ```yaml
259
+ version: 1
260
+ findings:
261
+ SEC-2024-001:
262
+ pattern: sql_injection
263
+ file: src/db/queries.py
264
+ line: 45
265
+ content_hash: "a1b2c3d4" # Re-evaluate if code changes
266
+ status: false_positive
267
+ reason: "ORM handles parameterization"
268
+ marked_by: "dev@example.com"
269
+ marked_at: "2026-01-01T10:30:00Z"
270
+ ```
271
+
272
+ | Status | Meaning | Behavior |
273
+ |--------|---------|----------|
274
+ | `false_positive` | Not a real vulnerability | Suppress permanently (unless code changes) |
275
+ | `accepted_risk` | Real but accepted | Suppress, can set expiry date |
276
+ | `wont_fix` | Won't be fixed | Suppress, still counted in stats |
277
+ | `in_progress` | Being fixed | Show but don't block |
278
+
279
+ **To mark a finding:**
280
+ ```
281
+ "Mark SEC-001 as false-positive: ORM handles escaping"
282
+ ```
283
+
284
+ ---
285
+
286
+ ## Language-Specific Patterns
287
+
288
+ Patterns are loaded from `patterns/` directory based on project type.
289
+
290
+ **Pattern file structure:**
291
+ ```yaml
292
+ # patterns/python.yaml
293
+ extends: _common
294
+ patterns:
295
+ sql_injection:
296
+ category: A03
297
+ severity: Critical
298
+ description: "SQL injection via string formatting"
299
+ regex:
300
+ - 'f"[^"]*SELECT[^"]*\{[^}]+\}'
301
+ - '\.format\([^)]*\)[^"]*SELECT'
302
+ ```
303
+
304
+ **Loading logic:**
305
+ 1. Detect language(s) from manifest files
306
+ 2. Load `_common.yaml` always
307
+ 3. Load language-specific YAML(s)
308
+ 4. Merge patterns (language-specific overrides common)
309
+
310
+ ---
311
+
312
+ ## Security Auditor Persona
313
+
314
+ Used in `--deep` mode (isolated agent):
315
+
316
+ ```
317
+ You are an independent Security Auditor.
318
+
319
+ CRITICAL RULES:
320
+ 1. Assume all code is vulnerable until proven secure
321
+ 2. Think like an attacker — how would I exploit this?
322
+ 3. Check all layers, not just obvious entry points
323
+ 4. Provide exploitation scenarios, not just "vulnerable to X"
324
+ 5. Prioritize by impact, not likelihood
325
+
326
+ OWASP TOP 10 CHECKLIST:
327
+ You MUST check every item in A01-A10.
328
+
329
+ INPUT YOU WILL RECEIVE:
330
+ - Code files to audit
331
+ - Dependency manifests
332
+ - Configuration files
333
+
334
+ INPUT YOU WILL NOT RECEIVE:
335
+ - Developer assurances ("this is only internal")
336
+ - Prior security review results
337
+ - Context about "trusted" inputs
338
+
339
+ OUTPUT: Structured Security Report (see Step 5)
340
+ ```
341
+
342
+ ---
343
+
344
+ ## CLI Override
345
+
346
+ Override isolation level per-invocation:
347
+
348
+ ```
349
+ /security → Uses --deep (default, spawns isolated agent)
350
+ /security --quick → Same context, A03 only
351
+ /security --standard → Same context, A01-A05
352
+ /security --deep → Spawns isolated agent (explicit)
353
+ ```
354
+
355
+ **No external configuration required.** Defaults are in this SKILL.md.
356
+
357
+ ---
358
+
359
+ ## Installation
360
+
361
+ ```bash
362
+ # Via CLI
363
+ invar skill add security
364
+
365
+ # Manual copy
366
+ cp -r /path/to/extensions/security .claude/skills/
367
+ ```
368
+
369
+ ---
370
+
371
+ *Extension Skill v1.0 — LX-07*
372
+ <!--/invar:skill--><!--invar:extensions-->
373
+ <!-- ========================================================================
374
+ EXTENSIONS REGION - USER EDITABLE
375
+ Add project-specific extensions here. This section is preserved on update.
376
+
377
+ Examples of what to add:
378
+ - Custom security patterns for your tech stack
379
+ - Project-specific baseline rules
380
+ - Additional OWASP categories relevant to your domain
381
+ ======================================================================== -->
382
+ <!--/invar:extensions-->
@@ -0,0 +1,126 @@
1
+ # Common Security Patterns (Cross-Language)
2
+ # These patterns apply to all languages
3
+
4
+ version: "1.0"
5
+
6
+ patterns:
7
+ # A02: Cryptographic Failures
8
+ hardcoded_secrets:
9
+ category: A02
10
+ severity: High
11
+ description: "Hardcoded credentials in source code"
12
+ regex:
13
+ - "password\\s*=\\s*[\"'][^\"']{4,}[\"']"
14
+ - "passwd\\s*=\\s*[\"'][^\"']{4,}[\"']"
15
+ - "api_key\\s*=\\s*[\"'][^\"']{8,}[\"']"
16
+ - "apikey\\s*=\\s*[\"'][^\"']{8,}[\"']"
17
+ - "secret\\s*=\\s*[\"'][^\"']{8,}[\"']"
18
+ - "token\\s*=\\s*[\"'][^\"']{8,}[\"']"
19
+ - "private_key\\s*=\\s*[\"']"
20
+ - "AWS_SECRET_ACCESS_KEY\\s*=\\s*[\"']"
21
+ - "GITHUB_TOKEN\\s*=\\s*[\"']"
22
+ exclude:
23
+ - '*_test.*'
24
+ - '*.test.*'
25
+ - '*.spec.*'
26
+ - '*.example.*'
27
+ - '.env.example'
28
+ false_positive_hints:
29
+ - "Check if value is a placeholder or environment variable reference"
30
+ - "Verify if file is meant for testing only"
31
+
32
+ weak_crypto_algorithms:
33
+ category: A02
34
+ severity: Medium
35
+ description: "Weak cryptographic algorithm usage"
36
+ regex:
37
+ - '\bmd5\b'
38
+ - '\bMD5\b'
39
+ - '\bsha1\b'
40
+ - '\bSHA1\b'
41
+ - '\bDES\b'
42
+ - '\bRC4\b'
43
+ - '\bRC2\b'
44
+ false_positive_hints:
45
+ - "MD5/SHA1 acceptable for non-security checksums"
46
+ - "Check if used for password hashing (bad) vs file integrity (ok)"
47
+
48
+ weak_random:
49
+ category: A02
50
+ severity: Medium
51
+ description: "Weak random number generation for security purposes"
52
+ regex:
53
+ - 'Math\.random\s*\('
54
+ - 'random\.random\s*\('
55
+ - 'rand\s*\('
56
+ false_positive_hints:
57
+ - "Check if used for security-sensitive purposes (tokens, keys)"
58
+ - "Non-security randomness (UI, tests) is acceptable"
59
+
60
+ # A03: Injection (generic patterns)
61
+ dangerous_regex:
62
+ category: A03
63
+ severity: Medium
64
+ description: "Potentially dangerous regular expression (ReDoS)"
65
+ regex:
66
+ - '\(\.\*\)\+'
67
+ - '\(\.\+\)\+'
68
+ - '\(\[.*\]\+\)\+'
69
+ false_positive_hints:
70
+ - "Check if regex is applied to untrusted input"
71
+ - "Consider regex timeout or input length limits"
72
+
73
+ # A05: Security Misconfiguration
74
+ debug_enabled:
75
+ category: A05
76
+ severity: Medium
77
+ description: "Debug mode potentially enabled in production"
78
+ regex:
79
+ - "DEBUG\\s*=\\s*[Tt]rue"
80
+ - "debug\\s*:\\s*true"
81
+ - "NODE_ENV\\s*=\\s*[\"']development[\"']"
82
+ false_positive_hints:
83
+ - "Check if this is production configuration"
84
+ - "Development-only files are acceptable"
85
+
86
+ verbose_errors:
87
+ category: A05
88
+ severity: Low
89
+ description: "Verbose error messages may leak information"
90
+ regex:
91
+ - 'stack\s*:\s*true'
92
+ - 'showStackTrace'
93
+ - 'print_exc\s*\('
94
+ - 'traceback\.print'
95
+ false_positive_hints:
96
+ - "Check if exposed to end users in production"
97
+
98
+ # A09: Logging Failures
99
+ sensitive_logging:
100
+ category: A09
101
+ severity: Medium
102
+ description: "Potentially logging sensitive data"
103
+ regex:
104
+ - 'log.*password'
105
+ - 'log.*token'
106
+ - 'log.*secret'
107
+ - 'log.*credit.?card'
108
+ - 'console\.log.*password'
109
+ - 'print.*password'
110
+ false_positive_hints:
111
+ - "Check if actual values are logged vs field names"
112
+ - "Verify log level and production exposure"
113
+
114
+ # A10: SSRF
115
+ ssrf_risk:
116
+ category: A10
117
+ severity: High
118
+ description: "User-controlled URL being fetched"
119
+ regex:
120
+ - 'fetch\s*\(\s*\w+\s*\)'
121
+ - 'requests\.get\s*\(\s*\w+\s*\)'
122
+ - 'http\.get\s*\(\s*\w+\s*\)'
123
+ - 'urllib\.request\.urlopen\s*\(\s*\w+\s*\)'
124
+ false_positive_hints:
125
+ - "Check if URL is user-controlled or hardcoded"
126
+ - "Verify URL validation/allowlisting exists"