Skip to content

Commit 4b747a2

Browse files
Your Nameclaude
andcommitted
chore: commit local changes for sync
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1d78c76 commit 4b747a2

30 files changed

+7780
-129
lines changed

COMPREHENSIVE-ROADMAP.md

Lines changed: 390 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,390 @@
1+
# Sanctify-PHP Comprehensive Implementation Roadmap
2+
**Target: 40% → 100% Completion**
3+
**Vision: Production-Ready PHP Security Analysis & Hardening Tool**
4+
5+
## Current Status Assessment (40%)
6+
7+
### ✅ Implemented (Strong Foundation)
8+
- **AST**: Comprehensive PHP 8.x AST with modern features (attributes, enums, match, etc.)
9+
- **Parser**: Megaparsec-based PHP parser (basic structures working)
10+
- **Security Analysis**: Extensive vulnerability detection
11+
- SQL injection, XSS, CSRF, command injection
12+
- Path traversal, unsafe deserialization
13+
- Weak crypto (with modern recommendations: SHAKE3-256/BLAKE3)
14+
- Hardcoded secrets detection
15+
- Dangerous function flagging
16+
- **Transform/Sanitize**: WordPress-specific security transformations
17+
- Output escaping (esc_html, esc_attr, etc.)
18+
- Input sanitization detection
19+
- SQL preparation wrapping
20+
- Superglobal sanitization
21+
- Exit after redirect
22+
- **WordPress**: WordPress-specific constraint checking
23+
- **Core Modules**: Config, Report, Ruleset (exist but need verification)
24+
25+
### ⚠️ Needs Completion/Enhancement (60% Gap)
26+
1. **Parser**: Needs full PHP 8.x expression/statement coverage
27+
2. **Emit**: PHP code generation from AST (critical for transformations)
28+
3. **Taint Analysis**: Data flow tracking needs completion
29+
4. **Type Inference**: PHP type system inference engine
30+
5. **Dead Code**: Unused code detection
31+
6. **CLI**: Production-ready command-line interface
32+
7. **Testing**: Comprehensive test suite
33+
8. **Documentation**: User guide, API docs, examples
34+
35+
---
36+
37+
## Phase 1: Core Completion (8-12h) - CRITICAL
38+
39+
### 1.1 Complete Parser (3-4h) ✅ COMPLETE
40+
**Priority: CRITICAL** - Nothing works without a complete parser
41+
42+
- [x] **Expression parsing completion**
43+
- Match expressions (PHP 8.0) ✓
44+
- Null coalescing assignment (??=) ✓
45+
- Spread operator in arrays ✓
46+
- Arrow functions with attributes ✓
47+
- Ternary and elvis operators ✓
48+
- Method calls and property access (including nullsafe) ✓
49+
50+
- [x] **Statement parsing completion**
51+
- Try/catch with multiple exception types ✓
52+
- Switch/match comprehensive coverage ✓
53+
- Declare directives (ticks, encoding) ✓
54+
- Global, static, unset statements ✓
55+
56+
- [x] **Modern PHP 8.x features**
57+
- Readonly classes (PHP 8.2) ✓
58+
- DNF types (PHP 8.2) - `(A&B)|(C&D)`
59+
- Constants in traits ✓
60+
- Attributes on all declarations ✓
61+
- Interface and enum parsing ✓
62+
- Constructor property promotion ✓
63+
64+
- [ ] **Robustness** (deferred to Phase 5)
65+
- Better error recovery (don't fail on single parse error)
66+
- Preserve whitespace/comments as metadata (for code generation)
67+
- Line/column tracking for all nodes (partially done)
68+
69+
### 1.2 Complete Emit - Code Generation (3-4h) ✅ COMPLETE
70+
**Priority: CRITICAL** - Required for all transformations
71+
72+
- [x] **Pretty printer from AST**
73+
- Generate readable PHP code ✓
74+
- All statements (match, try/catch, declare, global, static, unset) ✓
75+
- All expressions (closures, arrow functions, yield, throw) ✓
76+
- All declarations (interface, trait, enum, functions, classes) ✓
77+
- Attributes on all declarations ✓
78+
- DNF types with proper parenthesization ✓
79+
- Constructor property promotion ✓
80+
81+
- [ ] **Transformation output** (deferred to Phase 4)
82+
- Apply transform passes to AST
83+
- Emit modified code
84+
- Diff generation (show what changed)
85+
86+
- [ ] **Code style enforcement** (deferred to Phase 4)
87+
- PSR-12 compliance option
88+
- WordPress coding standards option
89+
- Configurable brace style, spacing
90+
91+
### 1.3 Type Inference Completion (2-3h)
92+
**Priority: HIGH** - Enables automatic type hint addition
93+
94+
- [ ] **Basic type inference**
95+
- Infer return types from function bodies
96+
- Infer parameter types from usage
97+
- Propagate types through assignments
98+
99+
- [ ] **WordPress type inference**
100+
- Recognize WordPress function signatures
101+
- Hook parameter type inference
102+
- WP_Query, WP_Post type awareness
103+
104+
- [ ] **Generics awareness**
105+
- array<T> inference
106+
- Collection type tracking
107+
108+
---
109+
110+
## Phase 2: Advanced Analysis (8-10h)
111+
112+
### 2.1 Complete Taint Tracking (3-4h)
113+
**Priority: HIGH** - Critical for security analysis accuracy
114+
115+
- [ ] **Data flow graph**
116+
- Build control flow graph
117+
- Track tainted data propagation
118+
- Source → Sink analysis
119+
120+
- [ ] **Taint sources**
121+
- Superglobals ($_GET, $_POST, $_COOKIE, etc.)
122+
- Database query results (trust context)
123+
- User input functions (file_get_contents, etc.)
124+
125+
- [ ] **Sanitizers recognition**
126+
- WordPress sanitization functions
127+
- PHP filter functions
128+
- Custom sanitizer patterns
129+
130+
- [ ] **Sinks**
131+
- SQL queries, shell commands
132+
- File operations, eval
133+
- Output (echo, print)
134+
135+
### 2.2 WordPress-Specific Deep Analysis (2-3h)
136+
**Priority: MEDIUM** - Differentiator for WP developers
137+
138+
- [ ] **Hook analysis**
139+
- Detect priority conflicts
140+
- Find missing/misplaced hooks
141+
- Identify wrong hook usage
142+
143+
- [ ] **Capability checking**
144+
- Find missing current_user_can() checks
145+
- Detect privilege escalation risks
146+
- Admin vs frontend context
147+
148+
- [ ] **Nonce verification**
149+
- Comprehensive CSRF detection
150+
- Find form submissions without nonces
151+
- AJAX handler nonce checking
152+
153+
- [ ] **Database query analysis**
154+
- $wpdb->prepare() compliance
155+
- Direct SQL detection
156+
- Table prefix usage
157+
158+
- [ ] **Internationalization**
159+
- Find untranslated strings
160+
- Detect missing text domains
161+
- Check escaping+translation combos
162+
163+
### 2.3 Advanced Security Checks (3-4h)
164+
**Priority: HIGH** - Beyond basic OWASP
165+
166+
- [ ] **Time-of-check-time-of-use (TOCTOU)**
167+
- File operation race conditions
168+
- Permission check bypasses
169+
170+
- [ ] **Regular expression DoS (ReDoS)**
171+
- Detect catastrophic backtracking patterns
172+
- Flag unsafe regex in preg_* functions
173+
174+
- [ ] **Server-Side Request Forgery (SSRF)**
175+
- wp_remote_get/post with user input
176+
- file_get_contents with URLs
177+
178+
- [ ] **XML External Entity (XXE)**
179+
- simplexml_load_* without disable_entity_loader
180+
- DOMDocument loadXML safety
181+
182+
- [ ] **Insecure direct object references**
183+
- Missing ownership checks on database queries
184+
- User ID manipulation detection
185+
186+
- [ ] **Mass assignment vulnerabilities**
187+
- Unvalidated array assignments to models
188+
189+
---
190+
191+
## Phase 3: Production CLI & Tooling (6-8h)
192+
193+
### 3.1 Enhanced CLI (3-4h) ✅ COMPLETE
194+
**Priority: HIGH** - User-facing interface
195+
196+
- [x] **Command improvements**
197+
- `sanctify analyze` - full analysis with report ✓
198+
- `sanctify fix --interactive` - interactive fixing with previews ✓
199+
- `sanctify fix --diff` - show unified diff of changes ✓
200+
- `sanctify --watch` - watch mode for development ✓
201+
202+
- [x] **Output formats**
203+
- JSON (machine-readable) ✓
204+
- SARIF (GitHub/GitLab integration) ✓
205+
- HTML (rich visualization) ✓
206+
- Terminal (text output) ✓
207+
208+
- [x] **Filtering & targeting**
209+
- `--severity=high,critical` - filter by severity ✓
210+
- `--type=sql,xss` - filter by vulnerability type ✓
211+
- `--in-place` - apply fixes to files ✓
212+
- `--verbose` - detailed output ✓
213+
214+
- [ ] **Performance** (deferred to Phase 6)
215+
- Parallel file processing
216+
- Incremental analysis (only changed files)
217+
- Result caching
218+
- `.sanctifyignore` support
219+
220+
### 3.2 Integration & Export (2-3h)
221+
**Priority: MEDIUM** - DevOps integration
222+
223+
- [ ] **CI/CD integration**
224+
- Exit codes for CI failure
225+
- GitHub Actions integration
226+
- GitLab CI templates
227+
- Pre-commit hooks
228+
229+
- [ ] **IDE integration preparation**
230+
- Language Server Protocol (LSP) foundations
231+
- JSON-RPC interface
232+
- Real-time analysis hooks
233+
234+
- [ ] **Configuration export**
235+
- php.ini hardening recommendations
236+
- nginx/Apache security headers
237+
- Guix/Nix package definitions
238+
- Docker security options
239+
240+
### 3.3 Reporting & Metrics (1-2h)
241+
**Priority: MEDIUM** - Visibility and tracking
242+
243+
- [ ] **Comprehensive reports**
244+
- Executive summary
245+
- Trend analysis (compare with previous scans)
246+
- Remediation guidance with code examples
247+
- Risk scoring
248+
249+
- [ ] **Metrics & dashboards**
250+
- Security score calculation
251+
- Issue distribution (by type, severity, file)
252+
- Fix effort estimation
253+
- Progress tracking
254+
255+
---
256+
257+
## Phase 4: Advanced Transformations (6-8h)
258+
259+
### 4.1 Automatic Fixes (4-5h)
260+
**Priority: HIGH** - Save developer time
261+
262+
- [ ] **Safe auto-fixes** (zero-risk, always apply)
263+
- Add `declare(strict_types=1)`
264+
- Add ABSPATH check to WP files
265+
- Convert `rand()``random_int()`
266+
- Add `exit` after `wp_redirect()`
267+
- Fix missing text domains in i18n functions
268+
269+
- [ ] **Semi-automatic fixes** (suggest with preview)
270+
- Wrap superglobals with sanitizers
271+
- Replace `$wpdb->query()` with `$wpdb->prepare()`
272+
- Add nonce verification scaffolding
273+
- Wrap `echo` with `esc_html()`
274+
275+
- [ ] **Type hint addition**
276+
- Infer and add parameter types
277+
- Infer and add return types
278+
- Add property types
279+
280+
- [ ] **Modernization**
281+
- Convert old array() → []
282+
- Convert isset() chains → null coalescing
283+
- Convert create_function() → closures
284+
285+
### 4.2 Code Quality Transformations (2-3h)
286+
**Priority: MEDIUM** - Beyond security
287+
288+
- [ ] **PSR compliance**
289+
- Naming conventions
290+
- File organization
291+
- Docblock generation
292+
293+
- [ ] **WordPress standards**
294+
- Yoda conditions
295+
- Brace style
296+
- Hook documentation
297+
298+
---
299+
300+
## Phase 5: Testing & Documentation (4-6h)
301+
302+
### 5.1 Test Suite (2-3h)
303+
**Priority: HIGH** - Ensure reliability
304+
305+
- [ ] **Unit tests**
306+
- Parser tests (golden files)
307+
- Analysis tests (vulnerability detection)
308+
- Transform tests (before/after)
309+
310+
- [ ] **Integration tests**
311+
- Full WordPress plugin analysis
312+
- Real-world vulnerability detection
313+
- Fix application verification
314+
315+
- [ ] **Property-based testing**
316+
- Parser round-trip (parse → emit → parse)
317+
- Transform idempotence
318+
319+
### 5.2 Documentation (2-3h)
320+
**Priority: MEDIUM** - User success
321+
322+
- [ ] **User guide**
323+
- Installation (Cabal, Stack, Nix, binaries)
324+
- Quick start tutorial
325+
- Configuration guide
326+
- Workflow examples
327+
328+
- [ ] **Rule documentation**
329+
- Security check reference
330+
- Transform catalog
331+
- WordPress-specific rules
332+
333+
- [ ] **API documentation**
334+
- Haddock coverage
335+
- Library usage examples
336+
- Extension guide
337+
338+
---
339+
340+
## Phase 6: Advanced Features (Optional, 4-6h)
341+
342+
### 6.1 Machine Learning Integration (2-3h)
343+
**Priority: LOW** - Cutting edge, experimental
344+
345+
- [ ] **Pattern learning**
346+
- Learn safe patterns from codebase
347+
- Reduce false positives
348+
- Suggest fixes based on codebase style
349+
350+
- [ ] **Anomaly detection**
351+
- Find unusual code patterns
352+
- Detect obfuscated malware
353+
354+
### 6.2 Plugin Ecosystem (2-3h)
355+
**Priority: LOW** - Extensibility
356+
357+
- [ ] **Custom rule engine**
358+
- DSL for defining custom checks
359+
- Custom transformation passes
360+
- Project-specific rules
361+
362+
- [ ] **Plugin architecture**
363+
- Load external analysis modules
364+
- Custom sanitizer definitions
365+
- Framework-specific analyzers (Laravel, Symfony, etc.)
366+
367+
---
368+
369+
## Summary: Path to 100%
370+
371+
| Phase | Hours | Completion Gain | Target % |
372+
|-------|-------|-----------------|----------|
373+
| Current | - | - | 40% |
374+
| Phase 1: Core Completion | 8-12 | +25% | 65% |
375+
| Phase 2: Advanced Analysis | 8-10 | +15% | 80% |
376+
| Phase 3: Production CLI | 6-8 | +10% | 90% |
377+
| Phase 4: Advanced Transforms | 6-8 | +5% | 95% |
378+
| Phase 5: Testing & Docs | 4-6 | +5% | 100% |
379+
| **TOTAL** | **32-44h** | **+60%** | **100%** |
380+
381+
**Critical Path (to 80%):**
382+
1. Complete Parser (4h)
383+
2. Complete Emit (4h)
384+
3. Complete Type Inference (3h)
385+
4. Complete Taint Tracking (4h)
386+
5. WordPress Deep Analysis (3h)
387+
6. Enhanced CLI (4h)
388+
7. Automatic Fixes (5h)
389+
390+
**Total Critical Path: 27h**

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SPDX-License-Identifier: PMPL-1.0
1+
SPDX-License-Identifier: PMPL-1.0-or-later
22
SPDX-FileCopyrightText: 2024-2025 Palimpsest Stewardship Council
33

44
================================================================================

0 commit comments

Comments
 (0)